From de882f1ef1ca6f67476fc59942dc1491fc470a86 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 4 May 2022 13:21:11 +0200 Subject: [PATCH] Fix (most) mauth tests --- app/app.go | 37 +++++++++++++++++++++++++++++++ x/mauth/keeper/keeper_test.go | 28 ++++++++++++++--------- x/mauth/keeper/msg_server_test.go | 8 +++---- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/app/app.go b/app/app.go index 85030c050f..ec7d1ae8a2 100644 --- a/app/app.go +++ b/app/app.go @@ -906,3 +906,40 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } + +// TestingApp functions + +// GetBaseApp implements the TestingApp interface. +func (app *WasmApp) GetBaseApp() *baseapp.BaseApp { + return app.BaseApp +} + +// GetStakingKeeper implements the TestingApp interface. +func (app *WasmApp) GetStakingKeeper() stakingkeeper.Keeper { + return app.stakingKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *WasmApp) GetIBCKeeper() *ibckeeper.Keeper { + return app.ibcKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *WasmApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.scopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *WasmApp) GetTxConfig() client.TxConfig { + return MakeEncodingConfig().TxConfig +} + +// GetICAControllerKeeper implements the TestingApp interface. +func (app *WasmApp) GetICAControllerKeeper() icacontrollerkeeper.Keeper { + return app.icaControllerKeeper +} + +// GetInterTxKeeper implements the TestingApp interface. +func (app *WasmApp) GetInterTxKeeper() intertxkeeper.Keeper { + return app.interTxKeeper +} diff --git a/x/mauth/keeper/keeper_test.go b/x/mauth/keeper/keeper_test.go index dddca597f2..5f5fe511b2 100644 --- a/x/mauth/keeper/keeper_test.go +++ b/x/mauth/keeper/keeper_test.go @@ -15,18 +15,25 @@ import ( ibctesting "github.com/cosmos/ibc-go/v3/testing" icaapp "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm" ) var ( + // TestPortID defines a resuable port identifier for testing purposes + TestPortID, _ = icatypes.NewControllerPortID(TestOwnerAddress) // TestAccAddress defines a resuable bech32 address for testing purposes // TODO: update crypto.AddressHash() when sdk uses address.Module() - TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID) + TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), ibctesting.FirstConnectionID, TestPortID) // TestOwnerAddress defines a reusable bech32 address for testing purposes TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs" - // TestPortID defines a resuable port identifier for testing purposes - TestPortID, _ = icatypes.GeneratePortID(TestOwnerAddress, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) // TestVersion defines a resuable interchainaccounts version string for testing purposes - TestVersion = icatypes.NewAppVersion(icatypes.VersionPrefix, TestAccAddress.String()) + TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ + Version: icatypes.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + })) ) func init() { @@ -35,8 +42,7 @@ func init() { func SetupICATestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { db := dbm.NewMemDB() - encCdc := icaapp.MakeEncodingConfig() - app := icaapp.NewGaiaApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, icaapp.DefaultNodeHome, 5, encCdc, icaapp.EmptyAppOptions{}) + app := icaapp.NewWasmApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, icaapp.DefaultNodeHome, 0, icaapp.MakeEncodingConfig(), wasm.EnableAllProposals, icaapp.EmptyBaseAppOptions{}, nil) // TODO: figure out if it's ok that w MakeEncodingConfig inside of our Genesis.go. It would be a different instance than the one used in app return app, icaapp.NewDefaultGenesisState() } @@ -52,8 +58,8 @@ type KeeperTestSuite struct { chainB *ibctesting.TestChain } -func (suite *KeeperTestSuite) GetICAApp(chain *ibctesting.TestChain) *icaapp.GaiaApp { - app, ok := chain.App.(*icaapp.GaiaApp) +func (suite *KeeperTestSuite) GetICAApp(chain *ibctesting.TestChain) *icaapp.WasmApp { + app, ok := chain.App.(*icaapp.WasmApp) if !ok { panic("not ica app") } @@ -69,8 +75,8 @@ func TestKeeperTestSuite(t *testing.T) { // SetupTest creates a coordinator with 2 test chains. func (suite *KeeperTestSuite) SetupTest() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) } func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { @@ -79,7 +85,7 @@ func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { path.EndpointB.ChannelConfig.PortID = icatypes.PortID path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - path.EndpointA.ChannelConfig.Version = icatypes.VersionPrefix + path.EndpointA.ChannelConfig.Version = icatypes.Version path.EndpointB.ChannelConfig.Version = TestVersion return path diff --git a/x/mauth/keeper/msg_server_test.go b/x/mauth/keeper/msg_server_test.go index 851e569d90..6dc3c5325b 100644 --- a/x/mauth/keeper/msg_server_test.go +++ b/x/mauth/keeper/msg_server_test.go @@ -26,7 +26,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { { "port is already bound", func() { - suite.GetICAApp(suite.chainA).IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) + suite.GetICAApp(suite.chainA).GetIBCKeeper().PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) }, false, }, @@ -40,10 +40,10 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { { "MsgChanOpenInit fails - channel is already active", func() { - portID, err := icatypes.GeneratePortID(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) + portID, err := icatypes.NewControllerPortID(owner) suite.Require().NoError(err) - suite.GetICAApp(suite.chainA).ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID) + suite.GetICAApp(suite.chainA).GetICAControllerKeeper().SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID) }, false, }, @@ -62,7 +62,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { tc.malleate() // malleate mutates test data - msgSrv := keeper.NewMsgServerImpl(suite.GetICAApp(suite.chainA).InterTxKeeper) + msgSrv := keeper.NewMsgServerImpl(suite.GetICAApp(suite.chainA).GetInterTxKeeper()) msg := types.NewMsgRegisterAccount(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) res, err := msgSrv.RegisterAccount(sdk.WrapSDKContext(suite.chainA.GetContext()), msg)