From 1b248ee8bcdd94ba87bd4ca6da1cc6f3cb605f47 Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Sun, 26 Jan 2025 21:24:05 +0100 Subject: [PATCH] feat: e2e test client update after IBC Client Expiration --- tests/e2e/chain.go | 2 + tests/e2e/e2e_ibc_test.go | 39 +++++++++++++++ tests/e2e/e2e_setup_test.go | 69 ++++++++++++++++++++++++--- tests/e2e/e2e_test.go | 4 ++ tests/e2e/scripts/hermes_bootstrap.sh | 6 +-- 5 files changed, 111 insertions(+), 9 deletions(-) diff --git a/tests/e2e/chain.go b/tests/e2e/chain.go index 00fd78f..350c177 100644 --- a/tests/e2e/chain.go +++ b/tests/e2e/chain.go @@ -20,6 +20,7 @@ import ( paramsproptypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibctypes "github.com/cosmos/ibc-go/v7/modules/core/types" teritoriparams "github.com/TERITORI/teritori-chain/app/params" ) @@ -45,6 +46,7 @@ func init() { cryptocodec.RegisterInterfaces(encodingConfig.InterfaceRegistry) govv1types.RegisterInterfaces(encodingConfig.InterfaceRegistry) govv1beta1types.RegisterInterfaces(encodingConfig.InterfaceRegistry) + ibctypes.RegisterInterfaces(encodingConfig.InterfaceRegistry) paramsproptypes.RegisterInterfaces(encodingConfig.InterfaceRegistry) paramsproptypes.RegisterLegacyAminoCodec(encodingConfig.Amino) diff --git a/tests/e2e/e2e_ibc_test.go b/tests/e2e/e2e_ibc_test.go index a6868a7..946dfc1 100644 --- a/tests/e2e/e2e_ibc_test.go +++ b/tests/e2e/e2e_ibc_test.go @@ -143,6 +143,27 @@ func (s *IntegrationTestSuite) createChannel() { s.T().Logf("IBC transfer channel created between chains %s and %s", s.chainA.id, s.chainB.id) } +func (s *IntegrationTestSuite) createClient(hostChain, referenceChain *chain) { + s.T().Logf("creating IBC Client between chains %s and %s", s.chainA.id, s.chainB.id) + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + hermesCmd := []string{ + hermesBinary, + "--json", + "create", + "client", + "--host-chain", hostChain.id, + "--reference-chain", referenceChain.id, + } + + fmt.Printf("hermesCmd %+v", hermesCmd) + _, err := s.executeHermesCommand(ctx, hermesCmd) + s.Require().NoError(err, "failed to create IBC client between chains: %s", err) + + s.T().Logf("IBC Client created between chains %s and %s", s.chainA.id, s.chainB.id) +} + // This function will complete the channel handshake in cases when ChanOpenInit was initiated // by some transaction that was previously executed on the chain. For example, // ICA MsgRegisterInterchainAccount will perform ChanOpenInit during its execution. @@ -275,6 +296,24 @@ func (s *IntegrationTestSuite) testIBCTokenTransfer() { }) } +func (s *IntegrationTestSuite) testIBCClientUpgrade() { + s.Run("upgrade_client_chainA", func() { + senderAddress, _ := s.chainA.validators[0].keyInfo.GetAddress() + sender := senderAddress.String() + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) + + time.Sleep(4 * time.Minute) + s.createClient(s.chainA, s.chainB) + time.Sleep(1 * time.Minute) + + proposalCounter++ + submitGovFlags := []string{"update-client", "07-tendermint-0", "07-tendermint-1", "--title", "IBCClientUpgrade", "--description", "IBC Client Upgrade", "--deposit", depositAmount.String()} + depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()} + voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"} + s.submitLegacyGovProposal(chainAAPIEndpoint, sender, proposalCounter, "IBCClientUpgrade", submitGovFlags, depositGovFlags, voteGovFlags, "vote", true) + }) +} + /* TestMultihopIBCTokenTransfer tests that sending an IBC transfer using the IBC Packet Forward Middleware accepts a port, channel and account address diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index beb6503..c83f696 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -63,12 +63,14 @@ const ( numberOfEvidences = 10 slashingShares int64 = 10000 - proposalMaxTotalBypassFilename = "proposal_max_total_bypass.json" - proposalCommunitySpendFilename = "proposal_community_spend.json" - proposalLSMParamUpdateFilename = "proposal_lsm_param_update.json" - proposalBlocksPerEpochFilename = "proposal_blocks_per_epoch.json" - proposalFailExpedited = "proposal_fail_expedited.json" - proposalExpeditedSoftwareUpgrade = "proposal_expedited_software_upgrade.json" + proposalMaxTotalBypassFilename = "proposal_max_total_bypass.json" + proposalCommunitySpendFilename = "proposal_community_spend.json" + proposalLSMParamUpdateFilename = "proposal_lsm_param_update.json" + proposalBlocksPerEpochFilename = "proposal_blocks_per_epoch.json" + proposalFailExpedited = "proposal_fail_expedited.json" + proposalExpeditedSoftwareUpgrade = "proposal_expedited_software_upgrade.json" + proposalTendermintClientUpdate = "proposal_tendermint_client_update.json" + proposalTendermintClientMisbehaviour = "proposal_tendermint_client_misbehaviour.json" // proposalAddConsumerChainFilename = "proposal_add_consumer.json" // proposalRemoveConsumerChainFilename = "proposal_remove_consumer.json" @@ -862,3 +864,58 @@ func configFile(filename string) string { filepath := filepath.Join(teritoriConfigPath, filename) return filepath } + +func (s *IntegrationTestSuite) writeGovClientUpdateProposal(c *chain, subjectClientID, substituteClientID string) { + body := `{ +"messages": [ + { + "@type": "/cosmos.gov.v1.MsgExecLegacyContent", + "content": { + "@type": "/ibc.core.client.v1.ClientUpdateProposal", + "title": "client update proposal", + "description": "This proposal is about udating the IBC Tendermint client %s, which references", + "subject_client_id": "%s", + "substitute_client_id": "%s" + }, + "authority": "tori10d07y265gmmuvt4z0w9aw880jnsr700jckyvdr" + } +], + "deposit": "100utori", +"proposer": "sample proposer", +"metadata": "sample metadata", +"title": "client update proposal", +"summary": "client update proposal" +}` + + body = fmt.Sprintf(body, subjectClientID, subjectClientID, substituteClientID) + + err := writeFile(filepath.Join(c.validators[0].configDir(), "config", proposalTendermintClientUpdate), []byte(body)) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) writeGovClientMisbehaviourProposal(c *chain, clientID string) { + body := `{ +"messages": [ + { + "@type": "/cosmos.gov.v1.MsgExecLegacyContent", + "content": { + "@type": "/ibc.core.client.v1.MsgSubmitMisbehaviour", + "title": "client misbehaviour proposal", + "description": "This proposal is about submitting misbehaviour for the IBC Tendermint client %s", + "client_id": "%s" + }, + "authority": "tori10d07y265gmmuvt4z0w9aw880jnsr700jckyvdr" + } +], + "deposit": "100utori", +"proposer": "sample proposer", +"metadata": "sample metadata", +"title": "client misbehaviour proposal", +"summary": "client misbehaviour proposal" +}` + + body = fmt.Sprintf(body, clientID, clientID) + + err := writeFile(filepath.Join(c.validators[0].configDir(), "config", proposalTendermintClientMisbehaviour), []byte(body)) + s.Require().NoError(err) +} diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 867b36f..47a30a6 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -86,3 +86,7 @@ func (s *IntegrationTestSuite) TestVesting() { s.testContinuousVestingAccount(chainAAPI) // s.testPeriodicVestingAccount(chainAAPI) TODO: add back when v0.45 adds the missing CLI command. } +func (s *IntegrationTestSuite) TestZero() { + s.testIBCClientUpgrade() + s.testIBCTokenTransfer() +} diff --git a/tests/e2e/scripts/hermes_bootstrap.sh b/tests/e2e/scripts/hermes_bootstrap.sh index 5b5dfa7..c8800e9 100644 --- a/tests/e2e/scripts/hermes_bootstrap.sh +++ b/tests/e2e/scripts/hermes_bootstrap.sh @@ -74,7 +74,7 @@ max_gas = 6000000 gas_price = { price = 0.005, denom = 'utori' } gas_multiplier = 1.5 clock_drift = '1m' # to accommodate docker containers -trusting_period = '14days' +trusting_period = '5m' trust_threshold = { numerator = '1', denominator = '3' } dynamic_gas_price = { enabled = true, multiplier = 1.3, max = 0.05 } EOF @@ -126,7 +126,7 @@ max_gas = 6000000 gas_price = { price = 0, denom = 'utori' } gas_multiplier = 1.5 clock_drift = '1m' # to accommodate docker containers -trusting_period = '14days' +trusting_period = '5m' trust_threshold = { numerator = '1', denominator = '3' } dynamic_gas_price = { enabled = true, multiplier = 1.3, max = 0.05 } @@ -144,7 +144,7 @@ max_gas = 6000000 gas_price = { price = 0, denom = 'utori' } gas_multiplier = 1.5 clock_drift = '1m' # to accommodate docker containers -trusting_period = '14days' +trusting_period = '5m' trust_threshold = { numerator = '1', denominator = '3' } dynamic_gas_price = { enabled = true, multiplier = 1.3, max = 0.05 } EOF