diff --git a/e2e/tests/data/migrate_error.wasm.gz b/e2e/tests/data/migrate_error.wasm.gz new file mode 100644 index 00000000000..4a6e92a4456 Binary files /dev/null and b/e2e/tests/data/migrate_error.wasm.gz differ diff --git a/e2e/tests/data/migrate_success.wasm.gz b/e2e/tests/data/migrate_success.wasm.gz new file mode 100644 index 00000000000..621eb77ccda Binary files /dev/null and b/e2e/tests/data/migrate_success.wasm.gz differ diff --git a/e2e/tests/wasm/grandpa_test.go b/e2e/tests/wasm/grandpa_test.go index f9388303263..95b02decca3 100644 --- a/e2e/tests/wasm/grandpa_test.go +++ b/e2e/tests/wasm/grandpa_test.go @@ -34,6 +34,8 @@ const ( composable = "composable" simd = "simd" wasmSimdImage = "ghcr.io/cosmos/ibc-go-wasm-simd" + + defaultWasmClientID = "08-wasm-0" ) func TestGrandpaTestSuite(t *testing.T) { @@ -67,58 +69,7 @@ type GrandpaTestSuite struct { func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() { ctx := context.Background() - chainA, chainB := s.GetChains(func(options *testsuite.ChainOptions) { - // configure chain A (polkadot) - options.ChainASpec.ChainName = composable - options.ChainASpec.Type = "polkadot" - options.ChainASpec.ChainID = "rococo-local" - options.ChainASpec.Name = "composable" - options.ChainASpec.Images = []ibc.DockerImage{ - // TODO: https://github.com/cosmos/ibc-go/issues/4965 - { - Repository: "ghcr.io/misko9/polkadot-node", - Version: "local", - UidGid: "1000:1000", - }, - { - Repository: "ghcr.io/misko9/parachain-node", - Version: "latest", - UidGid: "1000:1000", - }, - } - options.ChainASpec.Bin = "polkadot" - options.ChainASpec.Bech32Prefix = composable - options.ChainASpec.Denom = "uDOT" - options.ChainASpec.GasPrices = "" - options.ChainASpec.GasAdjustment = 0 - options.ChainASpec.TrustingPeriod = "" - options.ChainASpec.CoinType = "354" - - // these values are set by default for our cosmos chains, we need to explicitly remove them here. - options.ChainASpec.ModifyGenesis = nil - options.ChainASpec.ConfigFileOverrides = nil - options.ChainASpec.EncodingConfig = nil - - // configure chain B (cosmos) - options.ChainBSpec.ChainName = simd // Set chain name so that a suffix with a "dash" is not appended (required for hyperspace) - options.ChainBSpec.Type = "cosmos" - options.ChainBSpec.Name = "simd" - options.ChainBSpec.ChainID = simd - options.ChainBSpec.Bin = simd - options.ChainBSpec.Bech32Prefix = "cosmos" - - // TODO: hyperspace relayer assumes a denom of "stake", hard code this here right now. - // https://github.com/cosmos/ibc-go/issues/4964 - options.ChainBSpec.Denom = "stake" - options.ChainBSpec.GasPrices = "0.00stake" - options.ChainBSpec.GasAdjustment = 1 - options.ChainBSpec.TrustingPeriod = "504h" - options.ChainBSpec.CoinType = "118" - - options.ChainBSpec.ChainConfig.NoHostMount = false - options.ChainBSpec.ConfigFileOverrides = getConfigOverrides() - options.ChainBSpec.EncodingConfig = testsuite.SDKEncodingConfig() - }) + chainA, chainB := s.GetGrandpaTestChains() polkadotChain := chainA.(*polkadot.PolkadotChain) cosmosChain := chainB.(*cosmos.CosmosChain) @@ -130,7 +81,6 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() { s.InitGRPCClients(cosmosChain) - var err error cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) file, err := os.Open("../data/ics10_grandpa_cw.wasm") @@ -255,6 +205,174 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() { s.Require().True(parachainUserStake.Amount.Equal(math.NewInt(amountToSend-amountToReflect)), "parachain user's final stake amount not expected") } +// TestMsgMigrateContract_Success_GrandpaContract features +// * sets up a Polkadot parachain +// * sets up a Cosmos chain +// * sets up the Hyperspace relayer +// * Funds a user wallet on both chains +// * Pushes a wasm client contract to the Cosmos chain +// * create client in relayer +// * Pushes a new wasm client contract to the Cosmos chain +// * Migrates the wasm client contract +func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() { + ctx := context.Background() + + chainA, chainB := s.GetGrandpaTestChains() + + polkadotChain := chainA.(*polkadot.PolkadotChain) + cosmosChain := chainB.(*cosmos.CosmosChain) + + // we explicitly skip path creation as the contract needs to be uploaded before we can create clients. + r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) { + options.SkipPathCreation = true + }) + + s.InitGRPCClients(cosmosChain) + + cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + file, err := os.Open("../data/ics10_grandpa_cw.wasm") + s.Require().NoError(err) + + codeHash := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file) + + s.Require().NotEmpty(codeHash, "codehash was empty but should not have been") + + eRep := s.GetRelayerExecReporter() + + // Set client contract hash in cosmos chain config + err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), codeHash) + s.Require().NoError(err) + + // Ensure parachain has started (starts 1 session/epoch after relay chain) + err = testutil.WaitForBlocks(ctx, 1, polkadotChain) + s.Require().NoError(err, "polkadot chain failed to make blocks") + + pathName := s.GetPathName(0) + + err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) + s.Require().NoError(err) + + // Create new clients + err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) + s.Require().NoError(err) + err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness + s.Require().NoError(err) + + // Do not start relayer + + // This contract is a dummy contract that will always succeed migration. + // Other entry points are unimplemented. + migrateFile, err := os.Open("../data/migrate_success.wasm.gz") + s.Require().NoError(err) + + // First Store the code + newCodeHash := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, migrateFile) + s.Require().NotEmpty(newCodeHash, "codehash was empty but should not have been") + + newCodeHashBz, err := hex.DecodeString(newCodeHash) + s.Require().NoError(err) + + // Attempt to migrate the contract + message := wasmtypes.NewMsgMigrateContract( + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + defaultWasmClientID, + newCodeHashBz, + []byte("{}"), + ) + + s.ExecuteAndPassGovV1Proposal(ctx, message, cosmosChain, cosmosWallet) + + clientState, err := s.QueryClientState(ctx, cosmosChain, defaultWasmClientID) + s.Require().NoError(err) + + wasmClientState, ok := clientState.(*wasmtypes.ClientState) + s.Require().True(ok) + + s.Require().Equal(newCodeHashBz, wasmClientState.CodeHash) +} + +// TestMsgMigrateContract_ContractError_GrandpaContract features +// * sets up a Polkadot parachain +// * sets up a Cosmos chain +// * sets up the Hyperspace relayer +// * Funds a user wallet on both chains +// * Pushes a wasm client contract to the Cosmos chain +// * create client in relayer +// * Pushes a new wasm client contract to the Cosmos chain +// * Migrates the wasm client contract with a contract that will always fail migration +func (s *GrandpaTestSuite) TestMsgMigrateContract_ContractError_GrandpaContract() { + ctx := context.Background() + + chainA, chainB := s.GetGrandpaTestChains() + + polkadotChain := chainA.(*polkadot.PolkadotChain) + cosmosChain := chainB.(*cosmos.CosmosChain) + + // we explicitly skip path creation as the contract needs to be uploaded before we can create clients. + r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) { + options.SkipPathCreation = true + }) + + s.InitGRPCClients(cosmosChain) + + cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + file, err := os.Open("../data/ics10_grandpa_cw.wasm") + s.Require().NoError(err) + + codeHash := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file) + + s.Require().NotEmpty(codeHash, "codehash was empty but should not have been") + + eRep := s.GetRelayerExecReporter() + + // Set client contract hash in cosmos chain config + err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), codeHash) + s.Require().NoError(err) + + // Ensure parachain has started (starts 1 session/epoch after relay chain) + err = testutil.WaitForBlocks(ctx, 1, polkadotChain) + s.Require().NoError(err, "polkadot chain failed to make blocks") + + pathName := s.GetPathName(0) + + err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) + s.Require().NoError(err) + + // Create new clients + err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) + s.Require().NoError(err) + err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness + s.Require().NoError(err) + + // Do not start the relayer + + // This contract is a dummy contract that will always fail migration. + // Other entry points are unimplemented. + migrateFile, err := os.Open("../data/migrate_error.wasm.gz") + s.Require().NoError(err) + + // First Store the code + newCodeHash := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, migrateFile) + s.Require().NotEmpty(newCodeHash, "codehash was empty but should not have been") + + newCodeHashBz, err := hex.DecodeString(newCodeHash) + s.Require().NoError(err) + + // Attempt to migrate the contract + message := wasmtypes.NewMsgMigrateContract( + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + defaultWasmClientID, + newCodeHashBz, + []byte("{}"), + ) + + err = s.ExecuteGovV1Proposal(ctx, message, cosmosChain, cosmosWallet) + // This is the error string that is returned from the contract + s.Require().ErrorContains(err, "migration not supported") +} + // extractCodeHashFromGzippedContent takes a gzipped wasm contract and returns the codehash. func (s *GrandpaTestSuite) extractCodeHashFromGzippedContent(zippedContent []byte) string { content, err := wasmtypes.Uncompress(zippedContent, wasmtypes.MaxWasmByteSize()) @@ -336,3 +454,59 @@ func getConfigOverrides() map[string]any { configFileOverrides["config/config.toml"] = configTomlOverrides return configFileOverrides } + +// GetGrandpaTestChains returns the configured chains for the grandpa test suite. +func (s *GrandpaTestSuite) GetGrandpaTestChains() (ibc.Chain, ibc.Chain) { + return s.GetChains(func(options *testsuite.ChainOptions) { + // configure chain A (polkadot) + options.ChainASpec.ChainName = composable + options.ChainASpec.Type = "polkadot" + options.ChainASpec.ChainID = "rococo-local" + options.ChainASpec.Name = "composable" + options.ChainASpec.Images = []ibc.DockerImage{ + // TODO: https://github.com/cosmos/ibc-go/issues/4965 + { + Repository: "ghcr.io/misko9/polkadot-node", + Version: "local", + UidGid: "1000:1000", + }, + { + Repository: "ghcr.io/misko9/parachain-node", + Version: "latest", + UidGid: "1000:1000", + }, + } + options.ChainASpec.Bin = "polkadot" + options.ChainASpec.Bech32Prefix = composable + options.ChainASpec.Denom = "uDOT" + options.ChainASpec.GasPrices = "" + options.ChainASpec.GasAdjustment = 0 + options.ChainASpec.TrustingPeriod = "" + options.ChainASpec.CoinType = "354" + + // these values are set by default for our cosmos chains, we need to explicitly remove them here. + options.ChainASpec.ModifyGenesis = nil + options.ChainASpec.ConfigFileOverrides = nil + options.ChainASpec.EncodingConfig = nil + + // configure chain B (cosmos) + options.ChainBSpec.ChainName = simd // Set chain name so that a suffix with a "dash" is not appended (required for hyperspace) + options.ChainBSpec.Type = "cosmos" + options.ChainBSpec.Name = "simd" + options.ChainBSpec.ChainID = simd + options.ChainBSpec.Bin = simd + options.ChainBSpec.Bech32Prefix = "cosmos" + + // TODO: hyperspace relayer assumes a denom of "stake", hard code this here right now. + // https://github.com/cosmos/ibc-go/issues/4964 + options.ChainBSpec.Denom = "stake" + options.ChainBSpec.GasPrices = "0.00stake" + options.ChainBSpec.GasAdjustment = 1 + options.ChainBSpec.TrustingPeriod = "504h" + options.ChainBSpec.CoinType = "118" + + options.ChainBSpec.ChainConfig.NoHostMount = false + options.ChainBSpec.ConfigFileOverrides = getConfigOverrides() + options.ChainBSpec.EncodingConfig = testsuite.SDKEncodingConfig() + }) +} diff --git a/e2e/testsuite/tx.go b/e2e/testsuite/tx.go index c41f96aeda7..9d193156dfb 100644 --- a/e2e/testsuite/tx.go +++ b/e2e/testsuite/tx.go @@ -136,6 +136,13 @@ If this is a compatibility test, ensure that the fields are being sanitized in t // ExecuteAndPassGovV1Proposal submits a v1 governance proposal using the provided user and message and uses all validators // to vote yes on the proposal. It ensures the proposal successfully passes. func (s *E2ETestSuite) ExecuteAndPassGovV1Proposal(ctx context.Context, msg sdk.Msg, chain ibc.Chain, user ibc.Wallet) { + err := s.ExecuteGovV1Proposal(ctx, msg, chain, user) + s.Require().NoError(err) +} + +// ExecuteGovV1Proposal submits a v1 governance proposal using the provided user and message and uses all validators +// to vote yes on the proposal. +func (s *E2ETestSuite) ExecuteGovV1Proposal(ctx context.Context, msg sdk.Msg, chain ibc.Chain, user ibc.Wallet) error { cosmosChain, ok := chain.(*cosmos.CosmosChain) if !ok { panic("ExecuteAndPassGovV1Proposal must be passed a cosmos.CosmosChain") @@ -167,9 +174,7 @@ func (s *E2ETestSuite) ExecuteAndPassGovV1Proposal(ctx context.Context, msg sdk. s.Require().NoError(cosmosChain.VoteOnProposalAllValidators(ctx, strconv.Itoa(int(proposalID)), cosmos.ProposalVoteYes)) - err = s.waitForGovV1ProposalToPass(ctx, cosmosChain, proposalID) - - s.Require().NoError(err) + return s.waitForGovV1ProposalToPass(ctx, cosmosChain, proposalID) } // waitForGovV1ProposalToPass polls for the entire voting period to see if the proposal has passed. diff --git a/modules/light-clients/08-wasm/types/client_state_test.go b/modules/light-clients/08-wasm/types/client_state_test.go index 0482e94f4fb..2fd9b6997da 100644 --- a/modules/light-clients/08-wasm/types/client_state_test.go +++ b/modules/light-clients/08-wasm/types/client_state_test.go @@ -260,7 +260,7 @@ func (suite *TypesTestSuite) TestInitialize() { { "failure: clientStore prefix does not include clientID", func() { - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, ibctesting.InvalidID) + clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), ibctesting.InvalidID) }, types.ErrWasmContractCallFailed, }, @@ -298,8 +298,8 @@ func (suite *TypesTestSuite) TestInitialize() { clientState = types.NewClientState([]byte{1}, codeHash[:], clienttypes.NewHeight(0, 1)) consensusState = types.NewConsensusState([]byte{2}, 0) - clientID := suite.chainA.App.GetIBCKeeper().ClientKeeper.GenerateClientIdentifier(suite.ctx, clientState.ClientType()) - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, clientID) + clientID := suite.chainA.App.GetIBCKeeper().ClientKeeper.GenerateClientIdentifier(suite.chainA.GetContext(), clientState.ClientType()) + clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID) tc.malleate() @@ -339,7 +339,7 @@ func (suite *TypesTestSuite) TestVerifyMembership() { { "success", func() { - expClientStateBz = suite.store.Get(host.ClientStateKey()) + expClientStateBz = GetSimApp(suite.chainA).GetIBCKeeper().ClientKeeper.MustMarshalClientState(clientState) suite.mockVM.RegisterSudoCallback(types.VerifyMembershipMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, sudoMsg []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction, ) (*wasmvmtypes.Response, uint64, error) { @@ -445,11 +445,11 @@ func (suite *TypesTestSuite) TestVerifyMembership() { proofHeight = clienttypes.NewHeight(0, 1) value = []byte("value") - tc.malleate() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) clientState = endpoint.GetClientState() + tc.malleate() + err = clientState.VerifyMembership(suite.chainA.GetContext(), clientStore, suite.chainA.Codec, proofHeight, 0, 0, proof, path, value) expPass := tc.expError == nil @@ -630,7 +630,7 @@ func (suite *TypesTestSuite) TestVerifyNonMembershipGrandpa() { for _, tc := range testCases { suite.Run(tc.name, func() { suite.SetupWasmGrandpaWithChannel() // reset - clientState, ok = suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, defaultWasmClientID) + clientState, ok = suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), defaultWasmClientID) suite.Require().True(ok) delayTimePeriod = 1000000000 // Hyperspace requires a non-zero delay in seconds. The test data was generated using a 1-second delay @@ -647,8 +647,9 @@ func (suite *TypesTestSuite) TestVerifyNonMembershipGrandpa() { tc.malleate() + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) err = clientState.VerifyNonMembership( - suite.ctx, suite.store, suite.chainA.Codec, + suite.chainA.GetContext(), clientStore, suite.chainA.Codec, height, delayTimePeriod, delayBlockPeriod, proof, path, ) @@ -679,7 +680,7 @@ func (suite *TypesTestSuite) TestVerifyNonMembership() { { "success", func() { - expClientStateBz = suite.store.Get(host.ClientStateKey()) + expClientStateBz = GetSimApp(suite.chainA).GetIBCKeeper().ClientKeeper.MustMarshalClientState(clientState) suite.mockVM.RegisterSudoCallback(types.VerifyNonMembershipMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, sudoMsg []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction, ) (*wasmvmtypes.Response, uint64, error) { @@ -782,11 +783,11 @@ func (suite *TypesTestSuite) TestVerifyNonMembership() { proof = wasmtesting.MockInvalidProofBz proofHeight = clienttypes.NewHeight(0, 1) - tc.malleate() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) clientState = endpoint.GetClientState() + tc.malleate() + err = clientState.VerifyNonMembership(suite.chainA.GetContext(), clientStore, suite.chainA.Codec, proofHeight, 0, 0, proof, path) expPass := tc.expError == nil diff --git a/modules/light-clients/08-wasm/types/genesis_test.go b/modules/light-clients/08-wasm/types/genesis_test.go index f326c1c8e77..94d6f316eda 100644 --- a/modules/light-clients/08-wasm/types/genesis_test.go +++ b/modules/light-clients/08-wasm/types/genesis_test.go @@ -22,7 +22,9 @@ func (suite *TypesTestSuite) TestExportGenesisGrandpa() { suite.Require().NoError(err) clientState := types.NewClientState(clientStateData, suite.codeHash, clienttypes.NewHeight(2000, 4)) - gm := clientState.ExportMetadata(suite.store) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) + + gm := clientState.ExportMetadata(clientStore) suite.Require().NotNil(gm, "client returned nil") suite.Require().Len(gm, 0, "exported metadata has unexpected length") } diff --git a/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go b/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go index f68d0e547e1..6f8a2580e70 100644 --- a/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go +++ b/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go @@ -57,7 +57,7 @@ func (suite *TypesTestSuite) TestVerifyClientMessage() { { "failure: clientStore prefix does not include clientID", func() { - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, ibctesting.InvalidID) + clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), ibctesting.InvalidID) }, types.ErrWasmContractCallFailed, }, @@ -95,7 +95,7 @@ func (suite *TypesTestSuite) TestVerifyClientMessage() { err := endpoint.CreateClient() suite.Require().NoError(err) - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, endpoint.ClientID) + clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) clientState := endpoint.GetClientState() clientMsg = &types.ClientMessage{ @@ -184,7 +184,7 @@ func (suite *TypesTestSuite) TestCheckForMisbehaviour() { Data: []byte{1}, } - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, endpoint.ClientID) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) tc.malleate() diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index 71b0a7691ac..a29ed08edc8 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -15,7 +15,6 @@ import ( storetypes "cosmossdk.io/store/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -42,8 +41,6 @@ type TypesTestSuite struct { chainA *ibctesting.TestChain mockVM *wasmtesting.MockWasmEngine - ctx sdk.Context - store storetypes.KVStore codeHash []byte testData map[string]string } @@ -86,10 +83,6 @@ func (suite *TypesTestSuite) SetupWasmWithMockVM() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - - suite.ctx = suite.chainA.GetContext().WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) - suite.store = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, defaultWasmClientID) - suite.codeHash = storeWasmCode(suite, wasmtesting.Code) } @@ -133,9 +126,6 @@ func (suite *TypesTestSuite) SetupWasmGrandpa() { err = json.Unmarshal(testData, &suite.testData) suite.Require().NoError(err) - suite.ctx = suite.chainA.GetContext().WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) - suite.store = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, defaultWasmClientID) - wasmContract, err := os.ReadFile("../test_data/ics10_grandpa_cw.wasm.gz") suite.Require().NoError(err) @@ -179,11 +169,13 @@ func (suite *TypesTestSuite) SetupWasmGrandpaWithChannel() { // in 08-wasm directory so this should not affect what test app we use. ibctesting.DefaultTestingAppInit = SetupTestingWithChannel suite.SetupWasmGrandpa() - exportedClientState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, defaultWasmClientID) + + exportedClientState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), defaultWasmClientID) suite.Require().True(ok) + clientState := exportedClientState.(*types.ClientState) clientState.CodeHash = suite.codeHash - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.ctx, defaultWasmClientID, clientState) + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), defaultWasmClientID, clientState) } // storeWasmCode stores the wasm code on chain and returns the code hash. diff --git a/modules/light-clients/08-wasm/types/update_test.go b/modules/light-clients/08-wasm/types/update_test.go index 49271d7723a..ba4179d6783 100644 --- a/modules/light-clients/08-wasm/types/update_test.go +++ b/modules/light-clients/08-wasm/types/update_test.go @@ -100,7 +100,7 @@ func (suite *TypesTestSuite) TestUpdateState() { { "failure: clientStore prefix does not include clientID", func() { - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, ibctesting.InvalidID) + clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), ibctesting.InvalidID) }, errorsmod.Wrap(types.ErrWasmContractCallFailed, errorsmod.Wrap(errorsmod.Wrapf(types.ErrRetrieveClientID, "prefix does not contain a valid clientID: %s", errorsmod.Wrapf(host.ErrInvalidID, "invalid client identifier %s", ibctesting.InvalidID)), "failed to retrieve clientID for wasm contract call").Error()), nil, diff --git a/modules/light-clients/08-wasm/types/upgrade_test.go b/modules/light-clients/08-wasm/types/upgrade_test.go index 85583b5d61a..c756560586f 100644 --- a/modules/light-clients/08-wasm/types/upgrade_test.go +++ b/modules/light-clients/08-wasm/types/upgrade_test.go @@ -71,20 +71,24 @@ func (suite *TypesTestSuite) TestVerifyUpgradeGrandpa() { suite.Run(tc.name, func() { // reset suite suite.SetupWasmGrandpaWithChannel() - clientState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, defaultWasmClientID) + + clientState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), defaultWasmClientID) suite.Require().True(ok) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) + upgradedClient = clientState - upgradedConsState, ok = suite.chainA.App.GetIBCKeeper().ClientKeeper.GetLatestClientConsensusState(suite.ctx, defaultWasmClientID) + upgradedConsState, ok = suite.chainA.App.GetIBCKeeper().ClientKeeper.GetLatestClientConsensusState(suite.chainA.GetContext(), defaultWasmClientID) suite.Require().True(ok) + proofUpgradedClient = wasmtesting.MockUpgradedClientStateProofBz proofUpgradedConsState = wasmtesting.MockUpgradedConsensusStateProofBz tc.setup() err = clientState.VerifyUpgradeAndUpdateState( - suite.ctx, + suite.chainA.GetContext(), suite.chainA.Codec, - suite.store, + clientStore, upgradedClient, upgradedConsState, proofUpgradedClient, @@ -93,7 +97,7 @@ func (suite *TypesTestSuite) TestVerifyUpgradeGrandpa() { if tc.expPass { suite.Require().NoError(err) - clientStateBz := suite.store.Get(host.ClientStateKey()) + clientStateBz := clientStore.Get(host.ClientStateKey()) suite.Require().NotEmpty(clientStateBz) newClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, clientStateBz) // Stubbed code will increment client state @@ -194,7 +198,7 @@ func (suite *TypesTestSuite) TestVerifyUpgradeAndUpdateState() { tc.malleate() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, defaultWasmClientID) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) proofUpgradedClient = wasmtesting.MockUpgradedClientStateProofBz proofUpgradedConsState = wasmtesting.MockUpgradedConsensusStateProofBz @@ -214,11 +218,11 @@ func (suite *TypesTestSuite) TestVerifyUpgradeAndUpdateState() { suite.Require().NoError(err) // verify new client state and consensus state - clientStateBz := suite.store.Get(host.ClientStateKey()) + clientStateBz := clientStore.Get(host.ClientStateKey()) suite.Require().NotEmpty(clientStateBz) suite.Require().Equal(upgradedClient, clienttypes.MustUnmarshalClientState(suite.chainA.Codec, clientStateBz)) - consStateBz := suite.store.Get(host.ConsensusStateKey(upgradedClient.GetLatestHeight())) + consStateBz := clientStore.Get(host.ConsensusStateKey(upgradedClient.GetLatestHeight())) suite.Require().NotEmpty(consStateBz) suite.Require().Equal(upgradedConsState, clienttypes.MustUnmarshalConsensusState(suite.chainA.Codec, consStateBz)) } else { diff --git a/modules/light-clients/08-wasm/types/vm_test.go b/modules/light-clients/08-wasm/types/vm_test.go index 92526cc3e14..e401483305f 100644 --- a/modules/light-clients/08-wasm/types/vm_test.go +++ b/modules/light-clients/08-wasm/types/vm_test.go @@ -44,7 +44,8 @@ func (suite *TypesTestSuite) TestWasmInstantiate() { tc.malleate() - err := types.WasmInstantiate(suite.ctx, suite.store, &types.ClientState{}, types.InstantiateMessage{}) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) + err := types.WasmInstantiate(suite.chainA.GetContext(), clientStore, &types.ClientState{}, types.InstantiateMessage{}) expPass := tc.expError == nil if expPass { @@ -89,7 +90,8 @@ func (suite *TypesTestSuite) TestWasmMigrate() { tc.malleate() - err := types.WasmMigrate(suite.ctx, suite.store, &types.ClientState{}, defaultWasmClientID, []byte("{}")) + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) + err := types.WasmMigrate(suite.chainA.GetContext(), clientStore, &types.ClientState{}, defaultWasmClientID, []byte("{}")) expPass := tc.expError == nil if expPass { @@ -150,6 +152,7 @@ func (suite *TypesTestSuite) TestWasmQuery() { suite.Require().NoError(err) clientState := endpoint.GetClientState() + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) wasmClientState, ok := clientState.(*types.ClientState) suite.Require().True(ok) @@ -158,7 +161,7 @@ func (suite *TypesTestSuite) TestWasmQuery() { tc.malleate() - res, err := types.WasmQuery[types.StatusResult](suite.ctx, suite.store, wasmClientState, payload) + res, err := types.WasmQuery[types.StatusResult](suite.chainA.GetContext(), clientStore, wasmClientState, payload) expPass := tc.expError == nil if expPass { @@ -254,6 +257,7 @@ func (suite *TypesTestSuite) TestWasmSudo() { suite.Require().NoError(err) clientState := endpoint.GetClientState() + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) wasmClientState, ok := clientState.(*types.ClientState) suite.Require().True(ok) @@ -262,7 +266,7 @@ func (suite *TypesTestSuite) TestWasmSudo() { tc.malleate() - res, err := types.WasmSudo[types.UpdateStateResult](suite.ctx, suite.store, wasmClientState, payload) + res, err := types.WasmSudo[types.UpdateStateResult](suite.chainA.GetContext(), clientStore, wasmClientState, payload) expPass := tc.expError == nil if expPass {