Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use expected errors in ica host test. #7181

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
{
"account address generation is block dependent", func() {
Expand All @@ -155,12 +155,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {

// ensure account registration is simulated in a separate block
suite.chainB.NextBlock()
}, true,
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
}, nil,
},
{
"success: ICA auth module callback returns error", func() {
Expand All @@ -171,7 +166,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
) (string, error) {
return "", fmt.Errorf("mock ica auth fails")
}
}, true,
}, nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move this test up together the success ones.

},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, types.ErrHostSubModuleDisabled,
},
}

Expand Down Expand Up @@ -217,14 +217,14 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version,
)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)

addr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, counterparty.PortId)
suite.Require().True(exists)
suite.Require().NotNil(addr)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
suite.Require().Equal("", version)
}
})
Expand Down Expand Up @@ -273,15 +273,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
"success", func() {}, nil,
},
{
"success: ICA auth module callback returns error", func() {
Expand All @@ -291,7 +286,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() {
) error {
return fmt.Errorf("mock ica auth fails")
}
}, true,
}, nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, types.ErrHostSubModuleDisabled,
},
}

Expand Down Expand Up @@ -323,10 +323,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() {

err = cbs.OnChanOpenConfirm(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down Expand Up @@ -364,10 +364,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success", func() {}, true,
"success", func() {}, nil,
},
}

Expand All @@ -394,10 +394,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
err = cbs.OnChanCloseConfirm(
suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down Expand Up @@ -548,10 +548,10 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"ICA OnAcknowledgementPacket fails with ErrInvalidChannelFlow", func() {}, false,
"ICA OnAcknowledgementPacket fails with ErrInvalidChannelFlow", func() {}, icatypes.ErrInvalidChannelFlow,
},
}

Expand Down Expand Up @@ -589,10 +589,10 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() {

err = cbs.OnAcknowledgementPacket(suite.chainB.GetContext(), path.EndpointB.GetChannel().Version, packet, []byte("ackBytes"), nil)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -603,10 +603,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"ICA OnTimeoutPacket fails with ErrInvalidChannelFlow", func() {}, false,
"ICA OnTimeoutPacket fails with ErrInvalidChannelFlow", func() {}, icatypes.ErrInvalidChannelFlow,
},
}

Expand Down Expand Up @@ -644,10 +644,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {

err = cbs.OnTimeoutPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, nil)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down
20 changes: 10 additions & 10 deletions modules/apps/27-interchain-accounts/host/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func (suite *KeeperTestSuite) TestInitGenesis() {

func (suite *KeeperTestSuite) TestGenesisParams() {
testCases := []struct {
name string
input types.Params
expPass bool
name string
input types.Params
expPanicMsg string
}{
{"success: set default params", types.DefaultParams(), true},
{"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true},
{"success: set empty byte for allow messages", types.NewParams(true, nil), true},
{"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false},
{"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false},
{"success: set default params", types.DefaultParams(), ""},
{"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), ""},
{"success: set empty byte for allow messages", types.NewParams(true, nil), ""},
{"failure: set empty string for allow messages", types.NewParams(true, []string{""}), "could not set ica host params at genesis: parameter must not contain empty strings: []"},
{"failure: set space string for allow messages", types.NewParams(true, []string{" "}), "could not set ica host params at genesis: parameter must not contain empty strings: [ ]"},
}

for _, tc := range testCases {
Expand All @@ -89,7 +89,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
Port: icatypes.HostPortID,
Params: tc.input,
}
if tc.expPass {
if tc.expPanicMsg == "" {
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState)

channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID)
Expand All @@ -104,7 +104,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)
} else {
suite.Require().Panics(func() {
suite.PanicsWithError(tc.expPanicMsg, func() {
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState)
})
}
Expand Down
Loading
Loading