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(ante): refactor ante tests to use expected errors #6310

Merged
merged 5 commits into from
May 16, 2024
Merged
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
49 changes: 25 additions & 24 deletions modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante_test
import (
"testing"

"github.com/cosmos/btcutil/bech32"
"github.com/stretchr/testify/require"
testifysuite "github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -180,39 +181,39 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
testCases := []struct {
name string
malleate func(suite *AnteTestSuite) []sdk.Msg
expPass bool
expError error
}{
{
"success on one new RecvPacket message",
func(suite *AnteTestSuite) []sdk.Msg {
// the RecvPacket message has not been submitted to the chain yet, so it will succeed
return []sdk.Msg{suite.createRecvPacketMessage(false)}
},
true,
nil,
},
{
"success on one new Acknowledgement message",
func(suite *AnteTestSuite) []sdk.Msg {
// the Acknowledgement message has not been submitted to the chain yet, so it will succeed
return []sdk.Msg{suite.createAcknowledgementMessage(false)}
},
true,
nil,
},
{
"success on one new Timeout message",
func(suite *AnteTestSuite) []sdk.Msg {
// the Timeout message has not been submitted to the chain yet, so it will succeed
return []sdk.Msg{suite.createTimeoutMessage(false)}
},
true,
nil,
},
{
"success on one new TimeoutOnClose message",
func(suite *AnteTestSuite) []sdk.Msg {
// the TimeoutOnClose message has not been submitted to the chain yet, so it will succeed
return []sdk.Msg{suite.createTimeoutOnCloseMessage(false)}
},
true,
nil,
},
{
"success on three new messages of each type",
Expand Down Expand Up @@ -241,7 +242,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
}
return msgs
},
true,
nil,
},
{
"success on three redundant messages of RecvPacket, Acknowledgement and TimeoutOnClose, and one new Timeout message",
Expand Down Expand Up @@ -271,7 +272,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
}
return msgs
},
true,
nil,
},
{
"success on one new message and two redundant messages of each type",
Expand Down Expand Up @@ -301,21 +302,21 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
}
return msgs
},
true,
nil,
},
{
"success on one new UpdateClient message",
func(suite *AnteTestSuite) []sdk.Msg {
return []sdk.Msg{suite.createUpdateClientMessage()}
},
true,
nil,
},
{
"success on three new UpdateClient messages",
func(suite *AnteTestSuite) []sdk.Msg {
return []sdk.Msg{suite.createUpdateClientMessage(), suite.createUpdateClientMessage(), suite.createUpdateClientMessage()}
},
true,
nil,
},
{
"success on three new Updateclient messages and one new RecvPacket message",
Expand All @@ -327,7 +328,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
suite.createRecvPacketMessage(false),
}
},
true,
nil,
},
{
"success on three redundant RecvPacket messages and one SubmitMisbehaviour message",
Expand All @@ -342,14 +343,14 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
msgs = append(msgs, &clienttypes.MsgSubmitMisbehaviour{}) //nolint:staticcheck // we're using the deprecated message for testing
return msgs
},
true,
nil,
},
{
"no success on one redundant RecvPacket message",
func(suite *AnteTestSuite) []sdk.Msg {
return []sdk.Msg{suite.createRecvPacketMessage(true)}
},
false,
channeltypes.ErrRedundantTx,
},
{
"no success on three redundant messages of each type",
Expand All @@ -374,20 +375,20 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
}
return msgs
},
false,
channeltypes.ErrRedundantTx,
},
{
"no success on one new UpdateClient message and three redundant RecvPacket messages",
func(suite *AnteTestSuite) []sdk.Msg {
msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{}}
msgs := []sdk.Msg{suite.createUpdateClientMessage()}

for i := 1; i <= 3; i++ {
msgs = append(msgs, suite.createRecvPacketMessage(true))
}

return msgs
},
false,
channeltypes.ErrRedundantTx,
},
{
"no success on one new UpdateClient message: invalid client identifier",
Expand All @@ -398,7 +399,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: ibctesting.InvalidID, ClientMessage: clientMsg}}
return msgs
},
false,
clienttypes.ErrClientNotActive,
},
{
"no success on one new UpdateClient message: client module not found",
Expand All @@ -409,7 +410,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: clienttypes.FormatClientIdentifier("08-wasm", 1), ClientMessage: clientMsg}}
return msgs
},
false,
clienttypes.ErrClientNotActive,
},
{
"no success on one new UpdateClient message: no consensus state for trusted height",
Expand All @@ -420,7 +421,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: suite.path.EndpointA.ClientID, ClientMessage: clientMsg}}
return msgs
},
false,
clienttypes.ErrConsensusStateNotFound,
},
{
"no success on three new UpdateClient messages and three redundant messages of each type",
Expand All @@ -445,7 +446,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
}
return msgs
},
false,
channeltypes.ErrRedundantTx,
},
{
"no success on one new message and one invalid message",
Expand All @@ -460,7 +461,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
channeltypes.NewMsgRecvPacket(packet, []byte("proof"), clienttypes.NewHeight(1, 1), "signer"),
}
},
false,
bech32.ErrInvalidLength(6),
},
{
"no success on one new message and one redundant message in the same block",
Expand All @@ -484,7 +485,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {

return []sdk.Msg{msg}
},
false,
channeltypes.ErrRedundantTx,
},
}

Expand Down Expand Up @@ -515,10 +516,10 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
suite.Require().NoError(err, "antedecorator should not error on DeliverTx")

_, err = decorator.AnteHandle(checkCtx, tx, false, next)
if tc.expPass {
if tc.expError == nil {
suite.Require().NoError(err, "non-strict decorator did not pass as expected")
} else {
suite.Require().Error(err, "non-strict antehandler did not return error as expected")
suite.Require().ErrorIs(err, tc.expError, "non-strict antehandler did not return error as expected")
}
})
}
Expand Down
Loading