Skip to content

Commit

Permalink
chore(ante): refactor ante tests to use expected errors (#6310)
Browse files Browse the repository at this point in the history
* add expErr and fix nil updateClientMessage on testcase setup

* linting

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
TropicalDog17 and DimitrisJim authored May 16, 2024
1 parent e8c852d commit 76eb0da
Showing 1 changed file with 25 additions and 24 deletions.
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

0 comments on commit 76eb0da

Please sign in to comment.