From 49d002cf931ce3cc19ba264a974fd8930a5c3b43 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 16 Apr 2024 10:11:59 +0100 Subject: [PATCH] Address more findings. --- modules/light-clients/08-wasm/client/cli/tx.go | 2 +- .../08-wasm/keeper/contract_keeper_test.go | 6 ++++-- modules/light-clients/08-wasm/keeper/keeper_test.go | 3 ++- .../light-clients/08-wasm/keeper/msg_server_test.go | 4 +++- .../light-clients/08-wasm/light_client_module_test.go | 6 ++++-- modules/light-clients/08-wasm/testing/simapp/app.go | 8 ++++++-- modules/light-clients/08-wasm/testing/values.go | 10 +++++----- modules/light-clients/08-wasm/types/store.go | 8 +++++++- modules/light-clients/08-wasm/types/types_test.go | 5 +++-- modules/light-clients/08-wasm/wasm_test.go | 5 +++-- 10 files changed, 38 insertions(+), 19 deletions(-) diff --git a/modules/light-clients/08-wasm/client/cli/tx.go b/modules/light-clients/08-wasm/client/cli/tx.go index d16523141f6..7e85a26b7e5 100644 --- a/modules/light-clients/08-wasm/client/cli/tx.go +++ b/modules/light-clients/08-wasm/client/cli/tx.go @@ -15,7 +15,7 @@ import ( govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - types "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ) diff --git a/modules/light-clients/08-wasm/keeper/contract_keeper_test.go b/modules/light-clients/08-wasm/keeper/contract_keeper_test.go index 0727842b1a8..f258db7d570 100644 --- a/modules/light-clients/08-wasm/keeper/contract_keeper_test.go +++ b/modules/light-clients/08-wasm/keeper/contract_keeper_test.go @@ -34,7 +34,8 @@ func (suite *KeeperTestSuite) TestWasmInstantiate() { err := json.Unmarshal(initMsg, &payload) suite.Require().NoError(err) - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, payload.Checksum, wrappedClientState.LatestHeight) clientStateBz := clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState) @@ -147,7 +148,8 @@ func (suite *KeeperTestSuite) TestWasmInstantiate() { suite.Require().NoError(err) // Change the checksum to something else. - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, []byte("new checksum"), wrappedClientState.LatestHeight) store.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState)) diff --git a/modules/light-clients/08-wasm/keeper/keeper_test.go b/modules/light-clients/08-wasm/keeper/keeper_test.go index 90f6d2b5223..6f7b54550ee 100644 --- a/modules/light-clients/08-wasm/keeper/keeper_test.go +++ b/modules/light-clients/08-wasm/keeper/keeper_test.go @@ -89,7 +89,8 @@ func (suite *KeeperTestSuite) setupWasmWithMockVM() (ibctesting.TestingApp, map[ err := json.Unmarshal(initMsg, &payload) suite.Require().NoError(err) - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, payload.Checksum, wrappedClientState.LatestHeight) clientStateBz := clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState) diff --git a/modules/light-clients/08-wasm/keeper/msg_server_test.go b/modules/light-clients/08-wasm/keeper/msg_server_test.go index 6c4dfa59abc..568294fa38d 100644 --- a/modules/light-clients/08-wasm/keeper/msg_server_test.go +++ b/modules/light-clients/08-wasm/keeper/msg_server_test.go @@ -175,7 +175,9 @@ func (suite *KeeperTestSuite) TestMsgMigrateContract() { suite.mockVM.MigrateFn = func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, store wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.ContractResult, uint64, error) { // the checksum written in the client state will later be overwritten by the message server. expClientStateBz := wasmtesting.CreateMockClientStateBz(suite.chainA.App.AppCodec(), []byte("invalid checksum")) - expClientState = clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), expClientStateBz).(*types.ClientState) + var ok bool + expClientState, ok = clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), expClientStateBz).(*types.ClientState) + suite.Require().True(ok) store.Set(host.ClientStateKey(), expClientStateBz) data, err := json.Marshal(types.EmptyResult{}) diff --git a/modules/light-clients/08-wasm/light_client_module_test.go b/modules/light-clients/08-wasm/light_client_module_test.go index ce961fee859..9f238a7772e 100644 --- a/modules/light-clients/08-wasm/light_client_module_test.go +++ b/modules/light-clients/08-wasm/light_client_module_test.go @@ -260,7 +260,8 @@ func (suite *WasmTestSuite) TestInitialize() { suite.Require().Equal(env.Contract.Address, wasmClientID) - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, payload.Checksum, wrappedClientState.LatestHeight) clientStateBz := clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState) @@ -824,7 +825,8 @@ func (suite *WasmTestSuite) TestVerifyUpgradeAndUpdateState() { suite.Require().NoError(err) // set new client state and consensus state - wrappedUpgradedClient := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), expectedUpgradedClient.Data).(*ibctm.ClientState) + wrappedUpgradedClient, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), expectedUpgradedClient.Data).(*ibctm.ClientState) + suite.Require().True(ok) store.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), upgradedClient)) store.Set(host.ConsensusStateKey(wrappedUpgradedClient.LatestHeight), clienttypes.MustMarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState)) diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index b8fc325bfcd..8537c7f797d 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -125,7 +125,7 @@ import ( ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - transfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" @@ -565,8 +565,12 @@ func NewSimApp( // initialize ICA module with mock module as the authentication module on the controller side var icaControllerStack porttypes.IBCModule + var ok bool icaControllerStack = ibcmock.NewIBCModule(&mockModule, ibcmock.NewIBCApp("", scopedICAMockKeeper)) - app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule) + app.ICAAuthModule, ok = icaControllerStack.(ibcmock.IBCModule) + if !ok { + panic(fmt.Errorf("cannot convert %T into %T", icaControllerStack, app.ICAAuthModule)) + } icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper) icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper) diff --git a/modules/light-clients/08-wasm/testing/values.go b/modules/light-clients/08-wasm/testing/values.go index f7e27c5d7c1..71dca5474b1 100644 --- a/modules/light-clients/08-wasm/testing/values.go +++ b/modules/light-clients/08-wasm/testing/values.go @@ -10,7 +10,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" - testing "github.com/cosmos/ibc-go/v8/testing" + ibctesting "github.com/cosmos/ibc-go/v8/testing" ) var ( @@ -37,12 +37,12 @@ func CreateMockTendermintClientState(height clienttypes.Height) *ibctm.ClientSta return ibctm.NewClientState( "chain-id", ibctm.DefaultTrustLevel, - testing.TrustingPeriod, - testing.UnbondingPeriod, - testing.MaxClockDrift, + ibctesting.TrustingPeriod, + ibctesting.UnbondingPeriod, + ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs(), - testing.UpgradePath, + ibctesting.UpgradePath, ) } diff --git a/modules/light-clients/08-wasm/types/store.go b/modules/light-clients/08-wasm/types/store.go index bb5f5f785e8..a7160def824 100644 --- a/modules/light-clients/08-wasm/types/store.go +++ b/modules/light-clients/08-wasm/types/store.go @@ -3,6 +3,7 @@ package types import ( "bytes" "errors" + "fmt" "io" wasmvm "github.com/CosmWasm/wasmvm/v2" @@ -35,7 +36,12 @@ func GetClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - return clientStateI.(*ClientState), true + var clientState *ClientState + clientState, ok := clientStateI.(*ClientState) + if !ok { + panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState)) + } + return clientState, ok } // Checksum is a type alias used for wasm byte code checksums. diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index b743f67eb31..c6dd8c21023 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -18,7 +18,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing" - simapp "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp" + "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -90,7 +90,8 @@ func (suite *TypesTestSuite) setupWasmWithMockVM() (ibctesting.TestingApp, map[s err := json.Unmarshal(initMsg, &payload) suite.Require().NoError(err) - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, payload.Checksum, wrappedClientState.LatestHeight) clientStateBz := clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState) diff --git a/modules/light-clients/08-wasm/wasm_test.go b/modules/light-clients/08-wasm/wasm_test.go index e51ea3efde8..28b959b58be 100644 --- a/modules/light-clients/08-wasm/wasm_test.go +++ b/modules/light-clients/08-wasm/wasm_test.go @@ -18,7 +18,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing" - simapp "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp" + "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -85,7 +85,8 @@ func (suite *WasmTestSuite) setupWasmWithMockVM() (ibctesting.TestingApp, map[st err := json.Unmarshal(initMsg, &payload) suite.Require().NoError(err) - wrappedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + wrappedClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), payload.ClientState).(*ibctm.ClientState) + suite.Require().True(ok) clientState := types.NewClientState(payload.ClientState, payload.Checksum, wrappedClientState.LatestHeight) clientStateBz := clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), clientState)