|
| 1 | +package ica_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/suite" |
| 7 | + "github.com/tendermint/tendermint/libs/log" |
| 8 | + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" |
| 9 | + dbm "github.com/tendermint/tm-db" |
| 10 | + |
| 11 | + ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts" |
| 12 | + controllertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" |
| 13 | + hosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" |
| 14 | + "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" |
| 15 | + ibctesting "github.com/cosmos/ibc-go/v3/testing" |
| 16 | + "github.com/cosmos/ibc-go/v3/testing/simapp" |
| 17 | +) |
| 18 | + |
| 19 | +type InterchainAccountsTestSuite struct { |
| 20 | + suite.Suite |
| 21 | + |
| 22 | + coordinator *ibctesting.Coordinator |
| 23 | +} |
| 24 | + |
| 25 | +func TestICATestSuite(t *testing.T) { |
| 26 | + suite.Run(t, new(InterchainAccountsTestSuite)) |
| 27 | +} |
| 28 | + |
| 29 | +func (suite *InterchainAccountsTestSuite) SetupTest() { |
| 30 | + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) |
| 31 | +} |
| 32 | + |
| 33 | +func (suite *InterchainAccountsTestSuite) TestInitModule() { |
| 34 | + app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) |
| 35 | + icamodule, ok := app.GetModuleManager().Modules[types.ModuleName].(ica.AppModule) |
| 36 | + suite.Require().True(ok) |
| 37 | + |
| 38 | + header := tmproto.Header{ |
| 39 | + ChainID: "testchain", |
| 40 | + Height: 1, |
| 41 | + Time: suite.coordinator.CurrentTime.UTC(), |
| 42 | + } |
| 43 | + |
| 44 | + ctx := app.GetBaseApp().NewContext(true, header) |
| 45 | + |
| 46 | + // ensure params are not set |
| 47 | + suite.Require().Panics(func() { |
| 48 | + app.ICAControllerKeeper.GetParams(ctx) |
| 49 | + }) |
| 50 | + suite.Require().Panics(func() { |
| 51 | + app.ICAHostKeeper.GetParams(ctx) |
| 52 | + }) |
| 53 | + |
| 54 | + controllerParams := controllertypes.DefaultParams() |
| 55 | + controllerParams.ControllerEnabled = true |
| 56 | + |
| 57 | + hostParams := hosttypes.DefaultParams() |
| 58 | + expAllowMessages := []string{"sdk.Msg"} |
| 59 | + hostParams.HostEnabled = true |
| 60 | + hostParams.AllowMessages = expAllowMessages |
| 61 | + |
| 62 | + suite.Require().False(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID)) |
| 63 | + |
| 64 | + icamodule.InitModule(ctx, controllerParams, hostParams) |
| 65 | + |
| 66 | + controllerParams = app.ICAControllerKeeper.GetParams(ctx) |
| 67 | + suite.Require().True(controllerParams.ControllerEnabled) |
| 68 | + |
| 69 | + hostParams = app.ICAHostKeeper.GetParams(ctx) |
| 70 | + suite.Require().True(hostParams.HostEnabled) |
| 71 | + suite.Require().Equal(expAllowMessages, hostParams.AllowMessages) |
| 72 | + |
| 73 | + suite.Require().True(app.IBCKeeper.PortKeeper.IsBound(ctx, types.PortID)) |
| 74 | +} |
0 commit comments