From b773497f6c6463165a4a15d91cb0ea06265bb91d Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Fri, 26 Jul 2024 11:44:07 +0200 Subject: [PATCH] combine trust options into struct + use in e2e test --- contracts/fixtures/update_client_fixture.json | 4 +- contracts/script/genesis.json | 4 +- e2e/interchaintestv8/sp1_ics07_test.go | 14 ++-- e2e/interchaintestv8/testvalues/values.go | 3 + operator/src/cli/command.rs | 79 ++++++++----------- operator/src/runners/fixtures/membership.rs | 7 +- operator/src/runners/fixtures/uc_and_mem.rs | 7 +- .../src/runners/fixtures/update_client.rs | 7 +- operator/src/runners/genesis.rs | 7 +- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/contracts/fixtures/update_client_fixture.json b/contracts/fixtures/update_client_fixture.json index 71fab3d..defce54 100644 --- a/contracts/fixtures/update_client_fixture.json +++ b/contracts/fixtures/update_client_fixture.json @@ -6,6 +6,6 @@ "updateClientVkey": "0x00b8a6a2873e2eb2b0456023e69672caf877239e7c1f1b77cb84e7eb748af3eb", "membershipVkey": "0x005dee562962534ba45f120968c2e0eaa59ace5404e49252264f9f3699edad82", "ucAndMembershipVkey": "0x00dc223d082fda575a3950f0cf145ac567f7e479a44513e79a76f5f5529233a0", - "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000066a03c102bab132312afa95add5dec8f90e2fdc48085e7494ca6d39ee9431ff434e22775e0373a8b805881ecdbb47fce30b66956aa13e9a573107ba9ac495b9cef3365d30000000000000000000000000000000000000000000000000000000066a03c8ace271cd333ff2f0cd166fe30bcd67431aca0d94c5c8ed0079a30761311bbd3a2e0373a8b805881ecdbb47fce30b66956aa13e9a573107ba9ac495b9cef3365d3000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000238d9000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000238d9a00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000001275000000000000000000000000000000000000000000000000000000000066a23f9400000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000", - "proof": "0xfedc1fcc08e627cb26787c4cc66f4ff4a6b9978610d25f21252e2214f866a5ed941702552305139486082fd9a506c75a484977d3beaadf254f897a621cf1683003410378110d29c338a09e75256ecb4bb1c692e549ae30eb897fe51e2f5beed251233084225ed412137a935c50ac12e08b3569427167f2978912a2a57305d6e19c72108403f172ad0503983ee3d1fa24c55eb08280ac945926624d997767b68b8f3ed4520320d171a0c4f2a5fad1890b634574b4f80ca7977d9614d80d18da2836a59c151a30e5c21b5671b2777b84274b846f5a9dad12907cd8b3a63c83b081d0a27b4b00a1a05c6d63e458eea919baca496ed5e4bd232413b2307edd9fab408a6ac1b217e0cdcfa79e660789ce86fc33e11d82326ff2c2763a73da23a708c6dedcac85133988839d960f0b9528772005335778565e07e5fb4d278a6d146ae9ac0570d50501f491fcd75f7b103b751a44fa389ec7f30d648112aadef0ed2e638575329b0eaa3bb121c90e6991a3acdc1527ba2f2df48de0730189f571444d72d083f1df2d8b5838d73998f4dc1b16c2c3f51985c89e82f5ceb7f92c9ecd8903eaf3504e12e107687321eff5b25eb797a40c7588cf8834e8230c5ff002d99374e87a457304bb34df7abed35da0a8e77bac124699c53c0c14b5778b4a4765276bd3f82949052029cb854f9a64020e832789d3d31e8de3df36cc25156b84b16c82aef317e3238bd7c93dcbc572b9238dfec781218cd1dcb84ca22aff749027747d503840410298c88ca7f6035e854bd6fb74e0dd0a519b6a2f352f7224f279fd15c8e3d0c5205493cd0fee440827e689005389b868ffca2134af551734c499dfa52edb4adf0bf8cae03bfdfa4796fa835e1ef63ea2ad948b2f74eea863e949a7b3ec918cb11a11d96dfdc7a5038e716e4a9dee23e98ec587bad0a3c008fc743547f5e97c8d011a2e2207a056ffad0e5975a293abed1249cd1f70347f7eeb6b6fb6038f218613b0f0701780ce9ad3a585d2ed96e59b6fc7a2bdb7204545013a8964debfb9a9294ac6ad60e9942f8824f69c737f2550f71a3cdc60332c981d2540be47585bdb0f5518f69d74bc4db89e640c64248f5c8ffea02a58420f2d5f71df28350e806820012f152fa4985a77d409298e5ed06a65e3163f62df3dc764166d933eacec9209016c76a8701a5b5ac34dcdc31f515026d7ee9d0f85edd7da5a04fc375588c0" + "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000066a03c102bab132312afa95add5dec8f90e2fdc48085e7494ca6d39ee9431ff434e22775e0373a8b805881ecdbb47fce30b66956aa13e9a573107ba9ac495b9cef3365d30000000000000000000000000000000000000000000000000000000066a03c8ace271cd333ff2f0cd166fe30bcd67431aca0d94c5c8ed0079a30761311bbd3a2e0373a8b805881ecdbb47fce30b66956aa13e9a573107ba9ac495b9cef3365d3000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000238d9000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000238d9a00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000001275000000000000000000000000000000000000000000000000000000000066a365de00000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000", + "proof": "0xfedc1fcc24c655481805f42c8b8f22e968ab2f97506f902740ecdb6b94edd518477991481158eb6fbd85f8b7c6b56795e0a4e82de6f1afa30f7d720f688abf7feba9d4ed0b708984613e55e9e7a3b93d79c3267e556e924d585eb7e503b25878afd7a3b426cb1ce0ee343d3c2d2f9e58182dc12d19677a37fbb19a2533e846527d4296c52c4bf6de2a6812bef3aaae1471cf1ba8a24da64d7b173838180924698d0519a52389408e9c71b92a8aa97e3440504793e3ea4f454049b1878b0191797261d8ff2f13aa0a89d2f1499bb2504c6f225d4ebe5f90125cd0ad0b06b1396b3a8582f6045011cc5d4aa1e746a5bd69b7ebe6cf7fb45fbf0b1b9fcd91730b7d1dba8dd7035b0a45ab05acbda57fe2e8fc4f7521464fe7081e80106e1871ce2bbd11c1c30897c18f49794335ab980dc688f98f7fd132bc62c0a09eeadaea0fbd52e5b4dd2debed1d7ba5ac4e39c3b0b588451a981f69ea77172e35497cd6ead2935475191e97daa7fbb8f14d97b3262621425b0f792fa5cc9bc27bc73308439963d1ae8c11f4ff5cc261bb2d7a42101004b6792987270652c55a4a808202953574ad131a1740a2bd915159e02edf0f9bc69b270b83fde1f6cd91507bcf81cfae7496d584046bd2d3557d6559c9512eb894c85d72d6251e862fef2897780dd2330cc14e3a281316a23d96b8d5dc7360271868504ef45d0d5171e27531ba6cec82a46c3c8704c299e72a89baf38a24b2bbb53a120c76386d560ea960253259fa9e24921b64148f529dcece953bab1bd45459709bce3a0d80e1d62f21a44a7da62d7150f14319d00074d76e3754dfd6047e87fdafbc7f2e59e30c626ffb93273999f949edad140e009464288501752f5a6a9298e4ba61ff1a1bf305eaf20e6808ec6edefcfa22b7ab84a986a44481c958d4a231037c3c28fd5f28b51af87a5b4f2e936364eb06ba23424ecc3cd4028e87a023e43ca1b31ca648b26125f2ec3d9089ed75863a1631c3500e39d96cb98ed80b8a6bb72a626c08f3e2843d7ad71d6495319b265623d3914fbefa0b8e0fc8c7f42310bea3636f7db8f21e7499da6f8afcda56c59f2d6c99298ba4ed8ecbc42b737006101fb793b2c78843cd4cb5e18a4978f7a78703e83f371230c8c030acf0a81e31e60b61789e4c93287e406a0c8888649b45f72efe2781ab733d7dbd19ba80b2c29fb12503899f348a54e64823fee0d8ef934f" } \ No newline at end of file diff --git a/contracts/script/genesis.json b/contracts/script/genesis.json index 2189db8..bab5152 100644 --- a/contracts/script/genesis.json +++ b/contracts/script/genesis.json @@ -1,6 +1,6 @@ { - "trustedClientState": "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000012750000000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000", - "trustedConsensusState": "0000000000000000000000000000000000000000000000000000000066a247514614ece8e91f451fa8ff53bdbb9f2a518223018c3b1b8023d880a51ab023fe7c30b1e591f83bba282520ee0131cdaab496773d8abbb17684b7766da9f2adb8da", + "trustedClientState": "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000012754500000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000673696d642d310000000000000000000000000000000000000000000000000000", + "trustedConsensusState": "0000000000000000000000000000000000000000000000000000000066a36d61154d94d8b1a960773c26199c0b1982cf3496a025e602bf2ef7e307d1e6c0fb8227aef26dd65a2fa3db2c2c9cd895141599627abdf089fcff81d827329809c076", "updateClientVkey": "0x00b8a6a2873e2eb2b0456023e69672caf877239e7c1f1b77cb84e7eb748af3eb", "membershipVkey": "0x005dee562962534ba45f120968c2e0eaa59ace5404e49252264f9f3699edad82", "ucAndMembershipVkey": "0x00dc223d082fda575a3950f0cf145ac567f7e479a44513e79a76f5f5529233a0" diff --git a/e2e/interchaintestv8/sp1_ics07_test.go b/e2e/interchaintestv8/sp1_ics07_test.go index 9248a20..67541ac 100644 --- a/e2e/interchaintestv8/sp1_ics07_test.go +++ b/e2e/interchaintestv8/sp1_ics07_test.go @@ -5,6 +5,7 @@ import ( "crypto/ecdsa" "encoding/hex" "os" + "strconv" "testing" "github.com/stretchr/testify/suite" @@ -67,7 +68,10 @@ func (s *SP1ICS07TendermintTestSuite) SetupSuite(ctx context.Context) { })) s.Require().True(s.Run("Deploy contracts", func() { - s.Require().NoError(operator.RunGenesis("--trust-level", testvalues.DefaultTrustLevel.String())) + s.Require().NoError(operator.RunGenesis( + "--trust-level", testvalues.DefaultTrustLevel.String(), + "--trusting-period", strconv.Itoa(testvalues.DefaultTrustPeriod), + )) stdout, _, err := eth.ForgeScript(ctx, s.UserA.KeyName(), ethereum.ForgeScriptOpts{ ContractRootDir: ".", @@ -110,12 +114,10 @@ func (s *SP1ICS07TendermintTestSuite) TestDeploy() { stakingParams, err := simd.StakingQueryParams(ctx) s.Require().NoError(err) - expectedTrustingPeriod := (stakingParams.UnbondingTime.Seconds() / 3) * 2 - s.Require().Equal(simd.Config().ChainID, clientState.ChainId) s.Require().Equal(uint8(testvalues.DefaultTrustLevel.Numerator), clientState.TrustLevel.Numerator) s.Require().Equal(uint8(testvalues.DefaultTrustLevel.Denominator), clientState.TrustLevel.Denominator) - s.Require().Equal(uint32(expectedTrustingPeriod), clientState.TrustingPeriod) + s.Require().Equal(uint32(testvalues.DefaultTrustPeriod), clientState.TrustingPeriod) s.Require().Equal(uint32(stakingParams.UnbondingTime.Seconds()), clientState.UnbondingPeriod) s.Require().False(clientState.IsFrozen) s.Require().Equal(uint32(1), clientState.LatestHeight.RevisionNumber) @@ -142,12 +144,10 @@ func (s *SP1ICS07TendermintTestSuite) TestUpdateClient() { stakingParams, err := simd.StakingQueryParams(ctx) s.Require().NoError(err) - expectedTrustingPeriod := (stakingParams.UnbondingTime.Seconds() / 3) * 2 - s.Require().Equal(simd.Config().ChainID, clientState.ChainId) s.Require().Equal(uint8(testvalues.DefaultTrustLevel.Numerator), clientState.TrustLevel.Numerator) s.Require().Equal(uint8(testvalues.DefaultTrustLevel.Denominator), clientState.TrustLevel.Denominator) - s.Require().Equal(uint32(expectedTrustingPeriod), clientState.TrustingPeriod) + s.Require().Equal(uint32(testvalues.DefaultTrustPeriod), clientState.TrustingPeriod) s.Require().Equal(uint32(stakingParams.UnbondingTime.Seconds()), clientState.UnbondingPeriod) s.Require().False(clientState.IsFrozen) s.Require().Equal(uint32(1), clientState.LatestHeight.RevisionNumber) diff --git a/e2e/interchaintestv8/testvalues/values.go b/e2e/interchaintestv8/testvalues/values.go index 3760e5f..8bbd341 100644 --- a/e2e/interchaintestv8/testvalues/values.go +++ b/e2e/interchaintestv8/testvalues/values.go @@ -41,4 +41,7 @@ var ( // DefaultTrustLevel is the trust level used by the SP1ICS07Tendermint contract. DefaultTrustLevel = ibctm.Fraction{Numerator: 2, Denominator: 3}.ToTendermint() + + // DefaultTrustPeriod is the trust period used by the SP1ICS07Tendermint contract. + DefaultTrustPeriod = 1209669 ) diff --git a/operator/src/cli/command.rs b/operator/src/cli/command.rs index de27c18..9cb8ae4 100644 --- a/operator/src/cli/command.rs +++ b/operator/src/cli/command.rs @@ -23,6 +23,23 @@ pub enum Commands { Fixtures(fixtures::Cmd), } +/// The trust options for client operations. +#[derive(Clone, Debug, Parser)] +pub struct TrustOptions { + /// Trust level. + #[clap( + long, + default_value = "1/3", + value_parser = parse_trust_threshold, + help = "Trust level as a fraction, e.g. '2/3'", + )] + pub trust_level: TrustThreshold, + + /// Trusting period. [default: 2/3 of unbonding period] + #[clap(long)] + pub trusting_period: Option, +} + /// The cli interface for the genesis command. pub mod genesis { use super::Parser; @@ -33,26 +50,21 @@ pub mod genesis { /// Trusted block height. [default: latest] #[clap(long)] pub trusted_block: Option, + /// Genesis path. #[clap(long, default_value = "../contracts/script")] pub genesis_path: String, - /// Trust level. - #[clap( - long, - default_value = "1/3", - value_parser = super::parse_trust_threshold, - help = "Trust level as a fraction, e.g. '2/3'", - )] - pub trust_level: super::TrustThreshold, - /// Trusting period. [default: 2/3 of unbonding period] - #[clap(long)] - pub trusting_period: Option, + + /// Trust options + #[clap(flatten)] + pub trust_options: super::TrustOptions, } } /// The cli interface for the operator. pub mod operator { use super::Parser; + /// Command line arguments for the operator. #[derive(Parser, Debug, Clone)] pub struct Args { @@ -102,18 +114,9 @@ pub mod fixtures { #[clap(long, short = 'o')] pub output_path: String, - /// Trust level. - #[clap( - long, - default_value = "1/3", - value_parser = super::parse_trust_threshold, - help = "Trust level as a fraction, e.g. '2/3'", - )] - pub trust_level: super::TrustThreshold, - - /// Trusting period. [default: 2/3 of unbonding period] - #[clap(long)] - pub trusting_period: Option, + /// Trust options + #[clap(flatten)] + pub trust_options: super::TrustOptions, } /// The arguments for the `Membership` fixture executable. @@ -132,18 +135,9 @@ pub mod fixtures { #[clap(long, short = 'o')] pub output_path: String, - /// Trust level. - #[clap( - long, - default_value = "1/3", - value_parser = super::parse_trust_threshold, - help = "Trust level as a fraction, e.g. '2/3'", - )] - pub trust_level: super::TrustThreshold, - - /// Trusting period. [default: 2/3 of unbonding period] - #[clap(long)] - pub trusting_period: Option, + /// Trust options + #[clap(flatten)] + pub trust_options: super::TrustOptions, } /// The arguments for the `UpdateClientAndMembership` fixture executable. @@ -166,18 +160,9 @@ pub mod fixtures { #[clap(long, short = 'o')] pub output_path: String, - /// Trust level. - #[clap( - long, - default_value = "1/3", - value_parser = super::parse_trust_threshold, - help = "Trust level as a fraction, e.g. '2/3'", - )] - pub trust_level: super::TrustThreshold, - - /// Trusting period. [default: 2/3 of unbonding period] - #[clap(long)] - pub trusting_period: Option, + /// Trust options + #[clap(flatten)] + pub trust_options: super::TrustOptions, } } diff --git a/operator/src/runners/fixtures/membership.rs b/operator/src/runners/fixtures/membership.rs index 89f08f9..e664f9e 100644 --- a/operator/src/runners/fixtures/membership.rs +++ b/operator/src/runners/fixtures/membership.rs @@ -67,10 +67,13 @@ pub async fn run(args: MembershipCmd) -> anyhow::Result<()> { .try_into()?; // Defaults to the recommended TrustingPeriod: 2/3 of the UnbondingPeriod - let trusting_period = args.trusting_period.unwrap_or(2 * (unbonding_period / 3)); + let trusting_period = args + .trust_options + .trusting_period + .unwrap_or(2 * (unbonding_period / 3)); let trusted_client_state = trusted_light_block.to_sol_client_state( - args.trust_level.try_into()?, + args.trust_options.trust_level.try_into()?, unbonding_period, trusting_period, )?; diff --git a/operator/src/runners/fixtures/uc_and_mem.rs b/operator/src/runners/fixtures/uc_and_mem.rs index ef94ea1..a67626b 100644 --- a/operator/src/runners/fixtures/uc_and_mem.rs +++ b/operator/src/runners/fixtures/uc_and_mem.rs @@ -71,10 +71,13 @@ pub async fn run(args: UpdateClientAndMembershipCmd) -> anyhow::Result<()> { .try_into()?; // Defaults to the recommended TrustingPeriod: 2/3 of the UnbondingPeriod - let trusting_period = args.trusting_period.unwrap_or(2 * (unbonding_period / 3)); + let trusting_period = args + .trust_options + .trusting_period + .unwrap_or(2 * (unbonding_period / 3)); let trusted_client_state = trusted_light_block.to_sol_client_state( - args.trust_level.try_into()?, + args.trust_options.trust_level.try_into()?, unbonding_period, trusting_period, )?; diff --git a/operator/src/runners/fixtures/update_client.rs b/operator/src/runners/fixtures/update_client.rs index 5ecdbb3..e7fe9db 100644 --- a/operator/src/runners/fixtures/update_client.rs +++ b/operator/src/runners/fixtures/update_client.rs @@ -67,10 +67,13 @@ pub async fn run(args: UpdateClientCmd) -> anyhow::Result<()> { .try_into()?; // Defaults to the recommended TrustingPeriod: 2/3 of the UnbondingPeriod - let trusting_period = args.trusting_period.unwrap_or(2 * (unbonding_period / 3)); + let trusting_period = args + .trust_options + .trusting_period + .unwrap_or(2 * (unbonding_period / 3)); let trusted_client_state = trusted_light_block.to_sol_client_state( - args.trust_level.try_into()?, + args.trust_options.trust_level.try_into()?, unbonding_period, trusting_period, )?; diff --git a/operator/src/runners/genesis.rs b/operator/src/runners/genesis.rs index 166fb3b..b104b3e 100644 --- a/operator/src/runners/genesis.rs +++ b/operator/src/runners/genesis.rs @@ -57,10 +57,13 @@ pub async fn run(args: Args) -> anyhow::Result<()> { .try_into()?; // Defaults to the recommended TrustingPeriod: 2/3 of the UnbondingPeriod - let trusting_period = args.trusting_period.unwrap_or(2 * (unbonding_period / 3)); + let trusting_period = args + .trust_options + .trusting_period + .unwrap_or(2 * (unbonding_period / 3)); let trusted_client_state = trusted_light_block.to_sol_client_state( - args.trust_level.try_into()?, + args.trust_options.trust_level.try_into()?, unbonding_period, trusting_period, )?;