diff --git a/e2e/tests/wasm/grandpa_test.go b/e2e/tests/wasm/grandpa_test.go index a6169a8560f..6aa250b1885 100644 --- a/e2e/tests/wasm/grandpa_test.go +++ b/e2e/tests/wasm/grandpa_test.go @@ -19,10 +19,13 @@ import ( "github.com/strangelove-ventures/interchaintest/v8/testutil" testifysuite "github.com/stretchr/testify/suite" + cmtjson "github.com/cometbft/cometbft/libs/json" + "cosmossdk.io/math" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" @@ -30,6 +33,7 @@ import ( transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + ibctesting "github.com/cosmos/ibc-go/v8/testing" ) const ( @@ -124,6 +128,11 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() { err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) s.Require().NoError(err) + t.Run("add 08-wasm to list of allowed clients", func(t *testing.T) { + allowedClients := s.queryAllowedClientsParam(ctx, cosmosChain) + s.allowWasmClients(ctx, cosmosChain, cosmosWallet, allowedClients) + }) + // Create new clients err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) s.Require().NoError(err) @@ -276,6 +285,11 @@ func (s *GrandpaTestSuite) TestMsgTransfer_TimesOut_GrandpaContract() { err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) s.Require().NoError(err) + t.Run("add 08-wasm to list of allowed clients", func(t *testing.T) { + allowedClients := s.queryAllowedClientsParam(ctx, cosmosChain) + s.allowWasmClients(ctx, cosmosChain, cosmosWallet, allowedClients) + }) + // Create new clients err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) s.Require().NoError(err) @@ -340,6 +354,7 @@ func (s *GrandpaTestSuite) TestMsgTransfer_TimesOut_GrandpaContract() { // * Migrates the wasm client contract func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() { ctx := context.Background() + t := s.T() chainA, chainB := s.GetGrandpaTestChains() @@ -377,6 +392,11 @@ func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() { err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) s.Require().NoError(err) + t.Run("add 08-wasm to list of allowed clients", func(t *testing.T) { + allowedClients := s.queryAllowedClientsParam(ctx, cosmosChain) + s.allowWasmClients(ctx, cosmosChain, cosmosWallet, allowedClients) + }) + // Create new clients err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) s.Require().NoError(err) @@ -427,6 +447,7 @@ func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() { // * Migrates the wasm client contract with a contract that will always fail migration func (s *GrandpaTestSuite) TestMsgMigrateContract_ContractError_GrandpaContract() { ctx := context.Background() + t := s.T() chainA, chainB := s.GetGrandpaTestChains() @@ -463,6 +484,11 @@ func (s *GrandpaTestSuite) TestMsgMigrateContract_ContractError_GrandpaContract( err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) s.Require().NoError(err) + t.Run("add 08-wasm to list of allowed clients", func(t *testing.T) { + allowedClients := s.queryAllowedClientsParam(ctx, cosmosChain) + s.allowWasmClients(ctx, cosmosChain, cosmosWallet, allowedClients) + }) + // Create new clients err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts()) s.Require().NoError(err) @@ -510,6 +536,7 @@ func (s *GrandpaTestSuite) TestMsgMigrateContract_ContractError_GrandpaContract( // This contract modifies the unbonding period to 1600s with the trusting period being calculated as (unbonding period / 3). func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() { ctx := context.Background() + t := s.T() // set the trusting period to a value which will still be valid upon client creation, but invalid before the first update // the contract uses 1600s as the unbonding period with the trusting period evaluating to (unbonding period / 3) @@ -553,8 +580,13 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() { err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName) s.Require().NoError(err) + t.Run("add 08-wasm to list of allowed clients", func(t *testing.T) { + allowedClients := s.queryAllowedClientsParam(ctx, cosmosChain) + s.allowWasmClients(ctx, cosmosChain, cosmosWallet, allowedClients) + }) + // create client pair with subject (bad trusting period) - subjectClientID := clienttypes.FormatClientIdentifier(ibcexported.Wasm, 0) + subjectClientID := clienttypes.FormatClientIdentifier(wasmtypes.Wasm, 0) // TODO: The hyperspace relayer makes no use of create client opts // https://github.com/strangelove-ventures/interchaintest/blob/main/relayer/hyperspace/hyperspace_commander.go#L83 s.SetupClients(ctx, r, ibc.CreateClientOptions{ @@ -569,7 +601,7 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() { time.Sleep(modifiedTrustingPeriod) // create client pair with substitute - substituteClientID := clienttypes.FormatClientIdentifier(ibcexported.Wasm, 1) + substituteClientID := clienttypes.FormatClientIdentifier(wasmtypes.Wasm, 1) s.SetupClients(ctx, r, ibc.DefaultClientOpts()) // wait for block @@ -753,3 +785,48 @@ func (s *GrandpaTestSuite) GetGrandpaTestChains() (ibc.Chain, ibc.Chain) { options.ChainBSpec.EncodingConfig = testsuite.SDKEncodingConfig() }) } + +// queryAllowedClientsParam queries the on-chain allowed clients param for 02-client +func (s *GrandpaTestSuite) queryAllowedClientsParam(ctx context.Context, chain ibc.Chain) []string { + if testvalues.SelfParamsFeatureReleases.IsSupported(chain.Config().Images[0].Version) { + queryClient := s.GetChainGRCPClients(chain).ClientQueryClient + res, err := queryClient.ClientParams(ctx, &clienttypes.QueryClientParamsRequest{}) + s.Require().NoError(err) + + return res.Params.AllowedClients + } + queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient + res, err := queryClient.Params(ctx, ¶msproposaltypes.QueryParamsRequest{ + Subspace: ibcexported.ModuleName, + Key: string(clienttypes.KeyAllowedClients), + }) + s.Require().NoError(err) + + var allowedClients []string + err = cmtjson.Unmarshal([]byte(res.Param.Value), &allowedClients) + s.Require().NoError(err) + + return allowedClients +} + +// allowWasmClients adds 08-wasm to the on-chain allowed clients param for 02-client +func (s *GrandpaTestSuite) allowWasmClients(ctx context.Context, chain ibc.Chain, wallet ibc.Wallet, allowedClients []string) { + govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chain) + s.Require().NoError(err) + s.Require().NotNil(govModuleAddress) + + allowedClients = append(allowedClients, wasmtypes.Wasm) + if testvalues.SelfParamsFeatureReleases.IsSupported(chain.Config().Images[0].Version) { + msg := clienttypes.NewMsgUpdateParams(govModuleAddress.String(), clienttypes.NewParams(allowedClients...)) + s.ExecuteAndPassGovV1Proposal(ctx, msg, chain, wallet) + } else { + value, err := cmtjson.Marshal(allowedClients) + s.Require().NoError(err) + changes := []paramsproposaltypes.ParamChange{ + paramsproposaltypes.NewParamChange(ibcexported.ModuleName, string(clienttypes.KeyAllowedClients), string(value)), + } + + proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) + s.ExecuteAndPassGovV1Beta1Proposal(ctx, chain, wallet, proposal) + } +} diff --git a/modules/core/02-client/types/params.go b/modules/core/02-client/types/params.go index dc9b70b5cbc..2234f049e66 100644 --- a/modules/core/02-client/types/params.go +++ b/modules/core/02-client/types/params.go @@ -9,7 +9,7 @@ import ( ) // DefaultAllowedClients are the default clients for the AllowedClients parameter. -var DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Wasm, exported.Localhost} +var DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost} // NewParams creates a new parameter configuration for the ibc client module func NewParams(allowedClients ...string) Params { diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 3a5d5fb0f31..cf5d11ca617 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -22,9 +22,6 @@ const ( // Tendermint is used to indicate that the client uses the Tendermint Consensus Algorithm. Tendermint string = "07-tendermint" - // Wasm is used to indicate that the light client is a on-chain wasm program - Wasm string = "08-wasm" - // Localhost is the client type for the localhost client. Localhost string = "09-localhost" diff --git a/modules/light-clients/08-wasm/keeper/keeper_test.go b/modules/light-clients/08-wasm/keeper/keeper_test.go index d2337806b2b..00b915b373a 100644 --- a/modules/light-clients/08-wasm/keeper/keeper_test.go +++ b/modules/light-clients/08-wasm/keeper/keeper_test.go @@ -79,6 +79,8 @@ func (suite *KeeperTestSuite) SetupWasmWithMockVM() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + + wasmtesting.AllowWasmClients(suite.chainA) } func (suite *KeeperTestSuite) setupWasmWithMockVM() (ibctesting.TestingApp, map[string]json.RawMessage) { diff --git a/modules/light-clients/08-wasm/testing/wasm_endpoint.go b/modules/light-clients/08-wasm/testing/wasm_endpoint.go index 6d126ea35c9..5d391e547a8 100644 --- a/modules/light-clients/08-wasm/testing/wasm_endpoint.go +++ b/modules/light-clients/08-wasm/testing/wasm_endpoint.go @@ -50,3 +50,12 @@ func (endpoint *WasmEndpoint) CreateClient() error { return nil } + +// AllowWasmClients adds 08-wasm to the list of allowed clients +func AllowWasmClients(chain *ibctesting.TestChain) { + ctx := chain.GetContext() + clientKeeper := chain.App.GetIBCKeeper().ClientKeeper + params := clientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, types.Wasm) + clientKeeper.SetParams(ctx, params) +} diff --git a/modules/light-clients/08-wasm/types/client_message.go b/modules/light-clients/08-wasm/types/client_message.go index 483a9ed135c..51409c5aaa9 100644 --- a/modules/light-clients/08-wasm/types/client_message.go +++ b/modules/light-clients/08-wasm/types/client_message.go @@ -10,7 +10,7 @@ var _ exported.ClientMessage = &ClientMessage{} // ClientType is a Wasm light client. func (ClientMessage) ClientType() string { - return exported.Wasm + return Wasm } // ValidateBasic defines a basic validation for the wasm client message. diff --git a/modules/light-clients/08-wasm/types/client_message_test.go b/modules/light-clients/08-wasm/types/client_message_test.go index 4fa2a6ffc51..c405e3fe0f8 100644 --- a/modules/light-clients/08-wasm/types/client_message_test.go +++ b/modules/light-clients/08-wasm/types/client_message_test.go @@ -2,7 +2,6 @@ package types_test import ( "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - "github.com/cosmos/ibc-go/v8/modules/core/exported" ) func (suite *TypesTestSuite) TestClientMessageValidateBasic() { @@ -38,7 +37,7 @@ func (suite *TypesTestSuite) TestClientMessageValidateBasic() { suite.Run(tc.name, func() { clientMessage := tc.clientMessage - suite.Require().Equal(exported.Wasm, clientMessage.ClientType()) + suite.Require().Equal(types.Wasm, clientMessage.ClientType()) err := clientMessage.ValidateBasic() if tc.expPass { diff --git a/modules/light-clients/08-wasm/types/client_state.go b/modules/light-clients/08-wasm/types/client_state.go index 095cfa31096..1764df16d5a 100644 --- a/modules/light-clients/08-wasm/types/client_state.go +++ b/modules/light-clients/08-wasm/types/client_state.go @@ -28,7 +28,7 @@ func NewClientState(data []byte, checksum []byte, height clienttypes.Height) *Cl // ClientType is Wasm light client. func (ClientState) ClientType() string { - return exported.Wasm + return Wasm } // GetLatestHeight returns latest block height. diff --git a/modules/light-clients/08-wasm/types/consensus_state.go b/modules/light-clients/08-wasm/types/consensus_state.go index 28483e4e53b..b3e88c3cfce 100644 --- a/modules/light-clients/08-wasm/types/consensus_state.go +++ b/modules/light-clients/08-wasm/types/consensus_state.go @@ -17,7 +17,7 @@ func NewConsensusState(data []byte) *ConsensusState { // ClientType returns Wasm type. func (ConsensusState) ClientType() string { - return exported.Wasm + return Wasm } // GetTimestamp returns block time in nanoseconds of the header that created consensus state. diff --git a/modules/light-clients/08-wasm/types/consensus_state_test.go b/modules/light-clients/08-wasm/types/consensus_state_test.go index 375f49243f1..76a75be6525 100644 --- a/modules/light-clients/08-wasm/types/consensus_state_test.go +++ b/modules/light-clients/08-wasm/types/consensus_state_test.go @@ -2,7 +2,6 @@ package types_test import ( "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - "github.com/cosmos/ibc-go/v8/modules/core/exported" ) func (suite *TypesTestSuite) TestConsensusStateValidateBasic() { @@ -31,7 +30,7 @@ func (suite *TypesTestSuite) TestConsensusStateValidateBasic() { for _, tc := range testCases { suite.Run(tc.name, func() { // check just to increase coverage - suite.Require().Equal(exported.Wasm, tc.consensusState.ClientType()) + suite.Require().Equal(types.Wasm, tc.consensusState.ClientType()) err := tc.consensusState.ValidateBasic() if tc.expectPass { diff --git a/modules/light-clients/08-wasm/types/keys.go b/modules/light-clients/08-wasm/types/keys.go index a02f69974b8..bea78c2c0d0 100644 --- a/modules/light-clients/08-wasm/types/keys.go +++ b/modules/light-clients/08-wasm/types/keys.go @@ -6,4 +6,7 @@ const ( // StoreKey is the store key string for 08-wasm StoreKey = ModuleName + + // Wasm is the client type for IBC light clients created using 08-wasm + Wasm = ModuleName ) diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index e1729f66997..866f0535a6f 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -79,6 +79,8 @@ func (suite *TypesTestSuite) SetupWasmWithMockVM() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.checksum = storeWasmCode(suite, wasmtesting.Code) + + wasmtesting.AllowWasmClients(suite.chainA) } func (suite *TypesTestSuite) setupWasmWithMockVM() (ibctesting.TestingApp, map[string]json.RawMessage) { diff --git a/modules/light-clients/08-wasm/types/validation.go b/modules/light-clients/08-wasm/types/validation.go index 843d560ca46..d40650a90c9 100644 --- a/modules/light-clients/08-wasm/types/validation.go +++ b/modules/light-clients/08-wasm/types/validation.go @@ -7,7 +7,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" - "github.com/cosmos/ibc-go/v8/modules/core/exported" ) const maxWasmSize = 3 * 1024 * 1024 @@ -50,8 +49,8 @@ func ValidateClientID(clientID string) error { return errorsmod.Wrapf(host.ErrInvalidID, "invalid client identifier %s", clientID) } - if !strings.HasPrefix(clientID, exported.Wasm) { - return errorsmod.Wrapf(host.ErrInvalidID, "client identifier %s does not contain %s prefix", clientID, exported.Wasm) + if !strings.HasPrefix(clientID, Wasm) { + return errorsmod.Wrapf(host.ErrInvalidID, "client identifier %s does not contain %s prefix", clientID, Wasm) } return nil diff --git a/modules/light-clients/08-wasm/types/validation_test.go b/modules/light-clients/08-wasm/types/validation_test.go index 3389c51c954..0dda66e13ac 100644 --- a/modules/light-clients/08-wasm/types/validation_test.go +++ b/modules/light-clients/08-wasm/types/validation_test.go @@ -11,7 +11,6 @@ import ( wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" - "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v8/testing" ) @@ -143,7 +142,7 @@ func TestValidateClientID(t *testing.T) { func() { clientID = ibctesting.FirstClientID }, - errorsmod.Wrapf(host.ErrInvalidID, "client identifier %s does not contain %s prefix", ibctesting.FirstClientID, exported.Wasm), + errorsmod.Wrapf(host.ErrInvalidID, "client identifier %s does not contain %s prefix", ibctesting.FirstClientID, types.Wasm), }, }