Skip to content

Commit

Permalink
Fix (most) mauth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 4, 2022
1 parent 511ae46 commit de882f1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
37 changes: 37 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 17 additions & 11 deletions x/mauth/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()
}
Expand All @@ -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")
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions x/mauth/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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)
Expand Down

0 comments on commit de882f1

Please sign in to comment.