From 338ba8746dd067d88b2c05da2d8e4d867b739088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Sat, 23 Dec 2023 09:43:30 +0700 Subject: [PATCH 01/15] update test for MsgChannelOpenInit --- modules/core/04-channel/types/msgs_test.go | 140 +++++++++++++++++++-- 1 file changed, 128 insertions(+), 12 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 5a7bec0c889..28c99697d7a 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -7,6 +7,7 @@ import ( dbm "github.com/cosmos/cosmos-db" testifysuite "github.com/stretchr/testify/suite" + errorsmod "cosmossdk.io/errors" log "cosmossdk.io/log" "cosmossdk.io/store/iavl" "cosmossdk.io/store/metrics" @@ -122,19 +123,132 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { name string msg *types.MsgChannelOpenInit expPass bool + expErr string }{ - {"", types.NewMsgChannelOpenInit(portid, version, types.ORDERED, connHops, cpportid, addr), true}, - {"too short port id", types.NewMsgChannelOpenInit(invalidShortPort, version, types.ORDERED, connHops, cpportid, addr), false}, - {"too long port id", types.NewMsgChannelOpenInit(invalidLongPort, version, types.ORDERED, connHops, cpportid, addr), false}, - {"port id contains non-alpha", types.NewMsgChannelOpenInit(invalidPort, version, types.ORDERED, connHops, cpportid, addr), false}, - {"invalid channel order", types.NewMsgChannelOpenInit(portid, version, types.Order(3), connHops, cpportid, addr), false}, - {"connection hops more than 1 ", types.NewMsgChannelOpenInit(portid, version, types.ORDERED, invalidConnHops, cpportid, addr), false}, - {"too short connection id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, addr), false}, - {"too long connection id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, addr), false}, - {"connection id contains non-alpha", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, addr), false}, - {"", types.NewMsgChannelOpenInit(portid, "", types.UNORDERED, connHops, cpportid, addr), true}, - {"invalid counterparty port id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, connHops, invalidPort, addr), false}, - {"channel not in INIT state", &types.MsgChannelOpenInit{portid, tryOpenChannel, addr}, false}, + { + "", + types.NewMsgChannelOpenInit(portid, version, types.ORDERED, connHops, cpportid, addr), + true, + "", + }, + { + "too short port id", + types.NewMsgChannelOpenInit(invalidShortPort, version, types.ORDERED, connHops, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, + len(invalidShortPort), + 2, + host.DefaultMaxPortCharacterLength, + ), "invalid port ID").Error(), + }, + { + "too long port id", + types.NewMsgChannelOpenInit(invalidLongPort, version, types.ORDERED, connHops, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, + len(invalidLongPort), + 2, + host.DefaultMaxPortCharacterLength, + ), "invalid port ID").Error(), + }, + { + "port id contains non-alpha", + types.NewMsgChannelOpenInit(invalidPort, version, types.ORDERED, connHops, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID").Error(), + }, + { + "invalid channel order", + types.NewMsgChannelOpenInit(portid, version, types.Order(3), + connHops, cpportid, addr), + false, + errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(3).String()).Error(), + }, + { + "connection hops more than 1 ", + types.NewMsgChannelOpenInit(portid, version, types.ORDERED, invalidConnHops, cpportid, addr), + false, + errorsmod.Wrap( + types.ErrTooManyConnectionHops, + "current IBC version only supports one connection hop", + ).Error(), + }, + { + "too short connection id", + types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortConnection, len(invalidShortConnection), 10, host.DefaultMaxCharacterLength), + "invalid connection hop ID", + ).Error(), + }, + { + "too long connection id", + types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongConnection, len(invalidLongConnection), 10, host.DefaultMaxCharacterLength), + "invalid connection hop ID", + ).Error(), + }, + { + "connection id contains non-alpha", + types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidConnection, + ), "invalid connection hop ID", + ).Error(), + }, + { + "", + types.NewMsgChannelOpenInit(portid, "", types.UNORDERED, connHops, cpportid, addr), + true, + "", + }, + { + "invalid counterparty port id", + types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, connHops, invalidPort, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid counterparty port ID", + ).Error(), + }, + { + "channel not in INIT state", + &types.MsgChannelOpenInit{portid, tryOpenChannel, addr}, + false, + errorsmod.Wrapf(types.ErrInvalidChannelState, + "channel state must be INIT in MsgChannelOpenInit. expected: %s, got: %s", + types.INIT, tryOpenChannel.State, + ).Error(), + }, } for _, tc := range testCases { @@ -146,6 +260,8 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Assert().Equal(err.Error(), tc.expErr) + // suite.Assert().Equal(err.Error(), tc.expErr) } }) } From a1708925722cecf208265df5d6b8866bb04e2779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Sat, 23 Dec 2023 10:21:47 +0700 Subject: [PATCH 02/15] update test for MsgChannelOpenTry --- modules/core/04-channel/types/msgs_test.go | 167 ++++++++++++++++++--- 1 file changed, 150 insertions(+), 17 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 28c99697d7a..b7054b950b6 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -261,7 +261,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { } else { suite.Require().Error(err) suite.Assert().Equal(err.Error(), tc.expErr) - // suite.Assert().Equal(err.Error(), tc.expErr) } }) } @@ -287,23 +286,156 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { name string msg *types.MsgChannelOpenTry expPass bool + expErr string }{ - {"", types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), true}, - {"too short port id", types.NewMsgChannelOpenTry(invalidShortPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"too long port id", types.NewMsgChannelOpenTry(invalidLongPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"port id contains non-alpha", types.NewMsgChannelOpenTry(invalidPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"", types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), true}, - {"invalid channel order", types.NewMsgChannelOpenTry(portid, version, types.Order(4), connHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"connection hops more than 1 ", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidConnHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"too short connection id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"too long connection id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"connection id contains non-alpha", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, cpchanid, version, suite.proof, height, addr), false}, - {"", types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), true}, - {"invalid counterparty port id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, invalidPort, cpchanid, version, suite.proof, height, addr), false}, - {"invalid counterparty channel id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, invalidChannel, version, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), false}, - {"channel not in TRYOPEN state", &types.MsgChannelOpenTry{portid, "", initChannel, version, suite.proof, height, addr}, false}, - {"previous channel id is not empty", &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, false}, + { + "", + types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + true, + "", + }, + { + "too short port id", + types.NewMsgChannelOpenTry(invalidShortPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ).Error(), + }, + { + "too long port id", + types.NewMsgChannelOpenTry(invalidLongPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ).Error(), + }, + { + "port id contains non-alpha", + types.NewMsgChannelOpenTry(invalidPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ).Error(), + }, + { + "", + types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), + true, + "", + }, + { + "invalid channel order", + types.NewMsgChannelOpenTry(portid, version, types.Order(4), connHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(4).String()).Error(), + }, + { + "connection hops more than 1 ", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidConnHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + types.ErrTooManyConnectionHops, + "current IBC version only supports one connection hop", + ).Error(), + }, + { + "too short connection id", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", invalidShortConnection, len(invalidShortConnection), 10, host.DefaultMaxCharacterLength), + "invalid connection hop ID", + ).Error(), + }, + { + "too long connection id", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", invalidLongConnection, len(invalidLongConnection), 10, host.DefaultMaxCharacterLength), + "invalid connection hop ID", + ).Error(), + }, + { + "connection id contains non-alpha", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidConnection, + ), "invalid connection hop ID", + ).Error(), + }, + { + "", + types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + true, + "", + }, + { + "invalid counterparty port id", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, invalidPort, cpchanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid counterparty port ID", + ).Error(), + }, + { + "invalid counterparty channel id", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, invalidChannel, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidChannel, + ), "invalid counterparty channel ID", + ).Error(), + }, + { + "empty proof", + types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof").Error(), + }, + { + "channel not in TRYOPEN state", + &types.MsgChannelOpenTry{portid, "", initChannel, version, suite.proof, height, addr}, + false, + errorsmod.Wrapf(types.ErrInvalidChannelState, + "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", + types.TRYOPEN, initChannel.State, + ).Error(), + }, + { + "previous channel id is not empty", + &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, + false, + errorsmod.Wrap(types.ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported").Error(), + }, } for _, tc := range testCases { @@ -316,6 +448,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Assert().Equal(err.Error(), tc.expErr) } }) } From 077d754f7260d8c76e9cbddea0b2bbd8324d4991 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Sat, 23 Dec 2023 11:13:20 +0200 Subject: [PATCH 03/15] Use error as expError. --- modules/core/04-channel/types/msgs_test.go | 60 +++++++++------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index b7054b950b6..b7d6bf44545 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -120,21 +120,23 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { tryOpenChannel := types.NewChannel(types.TRYOPEN, types.ORDERED, counterparty, connHops, version) testCases := []struct { - name string - msg *types.MsgChannelOpenInit - expPass bool - expErr string + name string + msg *types.MsgChannelOpenInit + expErr error }{ { - "", + "success", types.NewMsgChannelOpenInit(portid, version, types.ORDERED, connHops, cpportid, addr), - true, - "", + nil, + }, + { + "success: empty version", + types.NewMsgChannelOpenInit(portid, "", types.UNORDERED, connHops, cpportid, addr), + nil, }, { "too short port id", types.NewMsgChannelOpenInit(invalidShortPort, version, types.ORDERED, connHops, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -143,12 +145,11 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength, - ), "invalid port ID").Error(), + ), "invalid port ID"), }, { "too long port id", types.NewMsgChannelOpenInit(invalidLongPort, version, types.ORDERED, connHops, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -157,97 +158,83 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength, - ), "invalid port ID").Error(), + ), "invalid port ID"), }, { "port id contains non-alpha", types.NewMsgChannelOpenInit(invalidPort, version, types.ORDERED, connHops, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidPort, - ), "invalid port ID").Error(), + ), "invalid port ID"), }, { "invalid channel order", types.NewMsgChannelOpenInit(portid, version, types.Order(3), connHops, cpportid, addr), - false, - errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(3).String()).Error(), + errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(3).String()), }, { "connection hops more than 1 ", types.NewMsgChannelOpenInit(portid, version, types.ORDERED, invalidConnHops, cpportid, addr), - false, errorsmod.Wrap( types.ErrTooManyConnectionHops, "current IBC version only supports one connection hop", - ).Error(), + ), }, { "too short connection id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", invalidShortConnection, len(invalidShortConnection), 10, host.DefaultMaxCharacterLength), "invalid connection hop ID", - ).Error(), + ), }, { "too long connection id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", invalidLongConnection, len(invalidLongConnection), 10, host.DefaultMaxCharacterLength), "invalid connection hop ID", - ).Error(), + ), }, { "connection id contains non-alpha", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidConnection, ), "invalid connection hop ID", - ).Error(), - }, - { - "", - types.NewMsgChannelOpenInit(portid, "", types.UNORDERED, connHops, cpportid, addr), - true, - "", + ), }, { "invalid counterparty port id", types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, connHops, invalidPort, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidPort, ), "invalid counterparty port ID", - ).Error(), + ), }, { "channel not in INIT state", &types.MsgChannelOpenInit{portid, tryOpenChannel, addr}, - false, errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state must be INIT in MsgChannelOpenInit. expected: %s, got: %s", types.INIT, tryOpenChannel.State, - ).Error(), + ), }, } @@ -255,12 +242,15 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { tc := tc suite.Run(tc.name, func() { + err := tc.msg.ValidateBasic() - if tc.expPass { + + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) - suite.Assert().Equal(err.Error(), tc.expErr) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 0e4c0f3e506f5b2fef416f54f8b1727c9de35b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 09:59:27 +0700 Subject: [PATCH 04/15] update TestMsgChannelOpenAckValidateBasic --- modules/core/04-channel/types/msgs_test.go | 154 +++++++++++++++------ 1 file changed, 115 insertions(+), 39 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index b7d6bf44545..0777fdc93d9 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -276,13 +276,25 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { name string msg *types.MsgChannelOpenTry expPass bool - expErr string + expErr error }{ { - "", + "success", types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), true, - "", + nil, + }, + { + "success with empty counterpartyVersion", + types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), + true, + nil, + }, + { + "success with empty channel version", + types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + true, + nil, }, { "too short port id", @@ -294,7 +306,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s has invalid length: %d, must be between %d-%d characters", invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), "invalid port ID", - ).Error(), + ), }, { "too long port id", @@ -306,7 +318,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s has invalid length: %d, must be between %d-%d characters", invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), "invalid port ID", - ).Error(), + ), }, { "port id contains non-alpha", @@ -318,19 +330,13 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidPort, ), "invalid port ID", - ).Error(), - }, - { - "", - types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), - true, - "", + ), }, { "invalid channel order", types.NewMsgChannelOpenTry(portid, version, types.Order(4), connHops, cpportid, cpchanid, version, suite.proof, height, addr), false, - errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(4).String()).Error(), + errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(4).String()), }, { "connection hops more than 1 ", @@ -339,7 +345,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { errorsmod.Wrap( types.ErrTooManyConnectionHops, "current IBC version only supports one connection hop", - ).Error(), + ), }, { "too short connection id", @@ -350,7 +356,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { host.ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", invalidShortConnection, len(invalidShortConnection), 10, host.DefaultMaxCharacterLength), "invalid connection hop ID", - ).Error(), + ), }, { "too long connection id", @@ -361,7 +367,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { host.ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", invalidLongConnection, len(invalidLongConnection), 10, host.DefaultMaxCharacterLength), "invalid connection hop ID", - ).Error(), + ), }, { "connection id contains non-alpha", @@ -373,13 +379,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidConnection, ), "invalid connection hop ID", - ).Error(), - }, - { - "", - types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - true, - "", + ), }, { "invalid counterparty port id", @@ -391,7 +391,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidPort, ), "invalid counterparty port ID", - ).Error(), + ), }, { "invalid counterparty channel id", @@ -403,13 +403,13 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", invalidChannel, ), "invalid counterparty channel ID", - ).Error(), + ), }, { "empty proof", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), false, - errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof").Error(), + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof"), }, { "channel not in TRYOPEN state", @@ -418,13 +418,13 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", types.TRYOPEN, initChannel.State, - ).Error(), + ), }, { "previous channel id is not empty", &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, false, - errorsmod.Wrap(types.ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported").Error(), + errorsmod.Wrap(types.ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported"), }, } @@ -438,7 +438,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) - suite.Assert().Equal(err.Error(), tc.expErr) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -461,17 +461,92 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { name string msg *types.MsgChannelOpenAck expPass bool + expErr error }{ - {"", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, suite.proof, height, addr), true}, - {"too short port id", types.NewMsgChannelOpenAck(invalidShortPort, chanid, chanid, version, suite.proof, height, addr), false}, - {"too long port id", types.NewMsgChannelOpenAck(invalidLongPort, chanid, chanid, version, suite.proof, height, addr), false}, - {"port id contains non-alpha", types.NewMsgChannelOpenAck(invalidPort, chanid, chanid, version, suite.proof, height, addr), false}, - {"too short channel id", types.NewMsgChannelOpenAck(portid, invalidShortChannel, chanid, version, suite.proof, height, addr), false}, - {"too long channel id", types.NewMsgChannelOpenAck(portid, invalidLongChannel, chanid, version, suite.proof, height, addr), false}, - {"channel id contains non-alpha", types.NewMsgChannelOpenAck(portid, invalidChannel, chanid, version, suite.proof, height, addr), false}, - {"", types.NewMsgChannelOpenAck(portid, chanid, chanid, "", suite.proof, height, addr), true}, - {"empty proof", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, emptyProof, height, addr), false}, - {"invalid counterparty channel id", types.NewMsgChannelOpenAck(portid, chanid, invalidShortChannel, version, suite.proof, height, addr), false}, + { + "success", + types.NewMsgChannelOpenAck(portid, chanid, chanid, version, suite.proof, height, addr), + true, + nil, + }, + { + "success empty cpv", + types.NewMsgChannelOpenAck(portid, chanid, chanid, "", suite.proof, height, addr), + true, + nil, + }, + { + "too short port id", + types.NewMsgChannelOpenAck(invalidShortPort, chanid, chanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "too long port id", + types.NewMsgChannelOpenAck(invalidLongPort, chanid, chanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "port id contains non-alpha", + types.NewMsgChannelOpenAck(invalidPort, chanid, chanid, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), + }, + { + "too short channel id", + types.NewMsgChannelOpenAck(portid, invalidShortChannel, chanid, version, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "too long channel id", + types.NewMsgChannelOpenAck(portid, invalidLongChannel, chanid, version, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "channel id contains non-alpha", + types.NewMsgChannelOpenAck(portid, invalidChannel, chanid, version, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "empty proof", + types.NewMsgChannelOpenAck(portid, chanid, chanid, version, emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty try proof"), + }, + { + "invalid counterparty channel id", + types.NewMsgChannelOpenAck(portid, chanid, invalidShortChannel, version, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortChannel, len(invalidShortChannel), 8, host.DefaultMaxCharacterLength), + "invalid counterparty channel ID", + ), + }, } for _, tc := range testCases { @@ -484,6 +559,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From c6bb11da44879379a79bf7d8e4d778753db1bd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 10:05:29 +0700 Subject: [PATCH 05/15] update TestMsgChannelOpenConfirmValidateBasic --- modules/core/04-channel/types/msgs_test.go | 77 +++++++++++++++++++--- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 0777fdc93d9..c39a0fbc49e 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -242,7 +242,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenInitValidateBasic() { tc := tc suite.Run(tc.name, func() { - err := tc.msg.ValidateBasic() expPass := tc.expErr == nil @@ -582,15 +581,74 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { name string msg *types.MsgChannelOpenConfirm expPass bool + expErr error }{ - {"", types.NewMsgChannelOpenConfirm(portid, chanid, suite.proof, height, addr), true}, - {"too short port id", types.NewMsgChannelOpenConfirm(invalidShortPort, chanid, suite.proof, height, addr), false}, - {"too long port id", types.NewMsgChannelOpenConfirm(invalidLongPort, chanid, suite.proof, height, addr), false}, - {"port id contains non-alpha", types.NewMsgChannelOpenConfirm(invalidPort, chanid, suite.proof, height, addr), false}, - {"too short channel id", types.NewMsgChannelOpenConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, - {"too long channel id", types.NewMsgChannelOpenConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, - {"channel id contains non-alpha", types.NewMsgChannelOpenConfirm(portid, invalidChannel, suite.proof, height, addr), false}, - {"empty proof", types.NewMsgChannelOpenConfirm(portid, chanid, emptyProof, height, addr), false}, + { + "success", + types.NewMsgChannelOpenConfirm(portid, chanid, suite.proof, height, addr), + true, + nil, + }, + { + "too short port id", + types.NewMsgChannelOpenConfirm(invalidShortPort, chanid, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "too long port id", + types.NewMsgChannelOpenConfirm(invalidLongPort, chanid, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "port id contains non-alpha", + types.NewMsgChannelOpenConfirm(invalidPort, chanid, suite.proof, height, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), + }, + { + "too short channel id", + types.NewMsgChannelOpenConfirm(portid, invalidShortChannel, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "too long channel id", + types.NewMsgChannelOpenConfirm(portid, invalidLongChannel, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "channel id contains non-alpha", + types.NewMsgChannelOpenConfirm(portid, invalidChannel, suite.proof, height, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "empty proof", + types.NewMsgChannelOpenConfirm(portid, chanid, emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof"), + }, } for _, tc := range testCases { @@ -603,6 +661,7 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From e9cf3b91c75e277302b09b19a9467f582f1e3f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 10:20:55 +0700 Subject: [PATCH 06/15] update TestMsgChannelCloseInitValidateBasic and TestMsgChannelCloseConfirmValidateBasic --- modules/core/04-channel/types/msgs_test.go | 152 ++++++++++++++++++--- 1 file changed, 136 insertions(+), 16 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index c39a0fbc49e..962b2fff50e 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -684,14 +684,68 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { name string msg *types.MsgChannelCloseInit expPass bool + expErr error }{ - {"", types.NewMsgChannelCloseInit(portid, chanid, addr), true}, - {"too short port id", types.NewMsgChannelCloseInit(invalidShortPort, chanid, addr), false}, - {"too long port id", types.NewMsgChannelCloseInit(invalidLongPort, chanid, addr), false}, - {"port id contains non-alpha", types.NewMsgChannelCloseInit(invalidPort, chanid, addr), false}, - {"too short channel id", types.NewMsgChannelCloseInit(portid, invalidShortChannel, addr), false}, - {"too long channel id", types.NewMsgChannelCloseInit(portid, invalidLongChannel, addr), false}, - {"channel id contains non-alpha", types.NewMsgChannelCloseInit(portid, invalidChannel, addr), false}, + { + "success", + types.NewMsgChannelCloseInit(portid, chanid, addr), + true, + nil, + }, + { + "too short port id", + types.NewMsgChannelCloseInit(invalidShortPort, chanid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "too long port id", + types.NewMsgChannelCloseInit(invalidLongPort, chanid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "port id contains non-alpha", + types.NewMsgChannelCloseInit(invalidPort, chanid, addr), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), + }, + { + "too short channel id", + types.NewMsgChannelCloseInit(portid, invalidShortChannel, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "too long channel id", + types.NewMsgChannelCloseInit(portid, invalidLongChannel, addr), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "channel id contains non-alpha", + types.NewMsgChannelCloseInit(portid, invalidChannel, addr), + false, + types.ErrInvalidChannelIdentifier, + }, } for _, tc := range testCases { @@ -704,6 +758,7 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -726,16 +781,80 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { name string msg *types.MsgChannelCloseConfirm expPass bool + expErr error }{ - {"success", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 0), true}, - {"success, positive counterparty upgrade sequence", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 1), true}, - {"too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr, 0), false}, - {"too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr, 0), false}, - {"port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr, 0), false}, - {"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr, 0), false}, - {"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr, 0), false}, - {"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr, 0), false}, - {"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr, 0), false}, + { + "success", + types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 0), + true, + nil, + }, + { + "success, positive counterparty upgrade sequence", + types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 1), + true, + nil, + }, + { + "too short port id", + types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr, 0), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidShortPort, len(invalidShortPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "too long port id", + types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr, 0), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s has invalid length: %d, must be between %d-%d characters", + invalidLongPort, len(invalidLongPort), 2, host.DefaultMaxPortCharacterLength), + "invalid port ID", + ), + }, + { + "port id contains non-alpha", + types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr, 0), + false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), + }, + { + "too short channel id", + types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr, 0), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "too long channel id", + types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr, 0), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "channel id contains non-alpha", + types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr, 0), + false, + types.ErrInvalidChannelIdentifier, + }, + { + "empty proof", + types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr, 0), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof"), + }, } for _, tc := range testCases { @@ -748,6 +867,7 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 1c2cb664a3a65e85071b8736187bf9b814b3c1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 10:48:26 +0700 Subject: [PATCH 07/15] update TestMsgRecvPacketValidateBasic --- modules/core/04-channel/types/msgs_test.go | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 962b2fff50e..d03eb8a61a4 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -1,6 +1,7 @@ package types_test import ( + "errors" "fmt" "testing" @@ -890,11 +891,32 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { name string msg *types.MsgRecvPacket expPass bool + expErr error }{ - {"success", types.NewMsgRecvPacket(packet, suite.proof, height, addr), true}, - {"missing signer address", types.NewMsgRecvPacket(packet, suite.proof, height, emptyAddr), false}, - {"proof contain empty proof", types.NewMsgRecvPacket(packet, emptyProof, height, addr), false}, - {"invalid packet", types.NewMsgRecvPacket(invalidPacket, suite.proof, height, addr), false}, + { + "success", + types.NewMsgRecvPacket(packet, suite.proof, height, addr), + true, + nil, + }, + { + "missing signer address", + types.NewMsgRecvPacket(packet, suite.proof, height, emptyAddr), + false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), + }, + { + "proof contain empty proof", + types.NewMsgRecvPacket(packet, emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty commitment proof"), + }, + { + "invalid packet", + types.NewMsgRecvPacket(invalidPacket, suite.proof, height, addr), + false, + errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), + }, } for _, tc := range testCases { @@ -907,6 +929,7 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { suite.NoError(err) } else { suite.Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 45e18a3e41d887be81d5d9fb8b2ff502ced7dc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 10:50:40 +0700 Subject: [PATCH 08/15] update TestMsgTimeoutValidateBasic --- modules/core/04-channel/types/msgs_test.go | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index d03eb8a61a4..8b921f1b622 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -952,12 +952,38 @@ func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { name string msg *types.MsgTimeout expPass bool + expErr error }{ - {"success", types.NewMsgTimeout(packet, 1, suite.proof, height, addr), true}, - {"seq 0", types.NewMsgTimeout(packet, 0, suite.proof, height, addr), false}, - {"missing signer address", types.NewMsgTimeout(packet, 1, suite.proof, height, emptyAddr), false}, - {"cannot submit an empty proof", types.NewMsgTimeout(packet, 1, emptyProof, height, addr), false}, - {"invalid packet", types.NewMsgTimeout(invalidPacket, 1, suite.proof, height, addr), false}, + { + "success", + types.NewMsgTimeout(packet, 1, suite.proof, height, addr), + true, + nil, + }, + { + "seq 0", + types.NewMsgTimeout(packet, 0, suite.proof, height, addr), + false, + errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0"), + }, + { + "missing signer address", + types.NewMsgTimeout(packet, 1, suite.proof, height, emptyAddr), + false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), + }, + { + "cannot submit an empty proof", + types.NewMsgTimeout(packet, 1, emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof"), + }, + { + "invalid packet", + types.NewMsgTimeout(invalidPacket, 1, suite.proof, height, addr), + false, + errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), + }, } for _, tc := range testCases { @@ -970,6 +996,7 @@ func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From e6b892bd27ad407eb42a100dedac1d5bccd755c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 11:03:03 +0700 Subject: [PATCH 09/15] update TestMsgTimeoutOnCloseValidateBasic, TestMsgAcknowledgementValidateBasic, TestMsgChannelUpgradeInitValidateBasic, TestMsgChannelUpgradeTryValidateBasic --- modules/core/04-channel/types/msgs_test.go | 120 ++++++++++++++++++--- 1 file changed, 108 insertions(+), 12 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 8b921f1b622..69ef5cba58f 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -1019,14 +1019,50 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { name string msg *types.MsgTimeoutOnClose expPass bool + expErr error }{ - {"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 0), true}, - {"success, positive counterparty upgrade sequence", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 1), true}, - {"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr, 0), false}, - {"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr, 0), false}, - {"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr, 0), false}, - {"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr, 0), false}, - {"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr, 0), false}, + { + "success", + types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 0), + true, + nil, + }, + { + "success, positive counterparty upgrade sequence", + types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 1), + true, + nil, + }, + { + "seq 0", + types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr, 0), + false, + errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0"), + }, + { + "signer address is empty", + types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr, 0), + false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), + }, + { + "empty proof", + types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr, 0), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof"), + }, + { + "empty proof close", + types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr, 0), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end"), + }, + { + "invalid packet", + types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr, 0), + false, + errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), + }, } for _, tc := range testCases { @@ -1039,6 +1075,7 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -1061,12 +1098,38 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { name string msg *types.MsgAcknowledgement expPass bool + expErr error }{ - {"success", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, addr), true}, - {"empty ack", types.NewMsgAcknowledgement(packet, nil, suite.proof, height, addr), false}, - {"missing signer address", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, emptyAddr), false}, - {"cannot submit an empty proof", types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, height, addr), false}, - {"invalid packet", types.NewMsgAcknowledgement(invalidPacket, packet.GetData(), suite.proof, height, addr), false}, + { + "success", + types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, addr), + true, + nil, + }, + { + "empty ack", + types.NewMsgAcknowledgement(packet, nil, suite.proof, height, addr), + false, + errorsmod.Wrap(types.ErrInvalidAcknowledgement, "ack bytes cannot be empty"), + }, + { + "missing signer address", + types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, emptyAddr), + false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), + }, + { + "cannot submit an empty proof", + types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, height, addr), + false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof"), + }, + { + "invalid packet", + types.NewMsgAcknowledgement(invalidPacket, packet.GetData(), suite.proof, height, addr), + false, + errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), + }, } for _, tc := range testCases { @@ -1079,6 +1142,7 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -1103,11 +1167,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "invalid port identifier", @@ -1115,6 +1181,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1122,6 +1195,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "empty proposed upgrade channel version", @@ -1129,6 +1203,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { msg.Fields.Version = " " }, false, + errorsmod.Wrap(types.ErrInvalidChannelVersion, "version cannot be empty"), }, { "missing signer address", @@ -1136,6 +1211,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1155,6 +1231,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -1183,11 +1260,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "invalid port identifier", @@ -1195,6 +1274,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1202,6 +1288,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "counterparty sequence cannot be zero", @@ -1209,6 +1296,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.CounterpartyUpgradeSequence = 0 }, false, + errorsmod.Wrap(types.ErrInvalidUpgradeSequence, "counterparty sequence cannot be 0"), }, { "invalid connection hops", @@ -1216,6 +1304,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.ProposedUpgradeConnectionHops = []string{} }, false, + errorsmod.Wrap(types.ErrInvalidUpgrade, "proposed connection hops cannot be empty"), }, { "invalid counterparty upgrade fields ordering", @@ -1223,6 +1312,9 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.CounterpartyUpgradeFields.Ordering = types.NONE }, false, + errorsmod.Wrap( + errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.NONE.String()), "error validating counterparty upgrade fields", + ), }, { "cannot submit an empty channel proof", @@ -1230,6 +1322,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.ProofChannel = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { "cannot submit an empty upgrade proof", @@ -1237,6 +1330,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.ProofUpgrade = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade proof"), }, { "missing signer address", @@ -1244,6 +1338,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1269,6 +1364,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 86f4507a961eabcc7942da95795df7fc04a81e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 11:10:53 +0700 Subject: [PATCH 10/15] update TestMsgChannelUpgradeAckValidateBasic, TestMsgChannelUpgradeConfirmValidateBasic --- modules/core/04-channel/types/msgs_test.go | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 69ef5cba58f..e16df7036db 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -1399,11 +1399,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "invalid port identifier", @@ -1411,6 +1413,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1418,6 +1427,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "cannot submit an empty channel proof", @@ -1425,6 +1435,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { msg.ProofChannel = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { "cannot submit an empty upgrade proof", @@ -1432,6 +1443,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { msg.ProofUpgrade = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade sequence proof"), }, { "missing signer address", @@ -1439,6 +1451,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1464,6 +1477,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -1498,11 +1512,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "success: counterparty state set to FLUSHCOMPLETE", @@ -1510,6 +1526,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.CounterpartyChannelState = types.FLUSHCOMPLETE }, true, + nil, }, { "invalid port identifier", @@ -1517,6 +1534,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1524,6 +1548,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "invalid counterparty channel state", @@ -1531,6 +1556,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.CounterpartyChannelState = types.CLOSED }, false, + errorsmod.Wrapf(types.ErrInvalidChannelState, "expected channel state to be one of: %s or %s, got: %s", types.FLUSHING, types.FLUSHCOMPLETE, types.CLOSED), }, { "cannot submit an empty channel proof", @@ -1538,6 +1564,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.ProofChannel = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { "cannot submit an empty upgrade proof", @@ -1545,6 +1572,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.ProofUpgrade = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade proof"), }, { "missing signer address", @@ -1552,6 +1580,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1577,6 +1606,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 3a73da084ef17500abbf3f6cc43ae6b727eedccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 11:15:30 +0700 Subject: [PATCH 11/15] update TestMsgChannelUpgradeOpenValidateBasic and TestMsgChannelUpgradeTimeoutValidateBasic --- modules/core/04-channel/types/msgs_test.go | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index e16df7036db..116085af1e2 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -1632,11 +1632,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success: flushcomplete state", func() {}, true, + nil, }, { "success: open state", @@ -1644,6 +1646,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.CounterpartyChannelState = types.OPEN }, true, + nil, }, { "invalid port identifier", @@ -1651,6 +1654,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1658,6 +1668,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "invalid counterparty channel state", @@ -1665,6 +1676,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.CounterpartyChannelState = types.CLOSED }, false, + errorsmod.Wrapf(types.ErrInvalidChannelState, "expected channel state to be one of: [%s, %s], got: %s", types.FLUSHCOMPLETE, types.OPEN, types.CLOSED), }, { "cannot submit an empty channel proof", @@ -1672,6 +1684,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.ProofChannel = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { "missing signer address", @@ -1679,6 +1692,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1698,6 +1712,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } @@ -1710,11 +1725,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "invalid port identifier", @@ -1722,6 +1739,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1729,6 +1753,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "cannot submit an empty proof", @@ -1736,6 +1761,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { msg.ProofChannel = emptyProof }, false, + errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof"), }, { "invalid counterparty channel state", @@ -1743,6 +1769,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { msg.CounterpartyChannel.State = types.CLOSED }, false, + errorsmod.Wrapf(types.ErrInvalidChannelState, "expected counterparty channel state to be one of: [%s, %s], got: %s", types.FLUSHING, types.OPEN, types.CLOSED), }, { "missing signer address", @@ -1750,6 +1777,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1770,6 +1798,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 12d5e4fffc8b7ffa421c9f93adbf1cb0771c9293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Mon, 25 Dec 2023 11:18:10 +0700 Subject: [PATCH 12/15] update TestMsgChannelUpgradeCancelValidateBasic --- modules/core/04-channel/types/msgs_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 116085af1e2..9c9386abc6d 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -1828,11 +1828,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { name string malleate func() expPass bool + expErr error }{ { "success", func() {}, true, + nil, }, { "invalid port identifier", @@ -1840,6 +1842,13 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { msg.PortId = invalidPort }, false, + errorsmod.Wrap( + errorsmod.Wrapf( + host.ErrInvalidID, + "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", + invalidPort, + ), "invalid port ID", + ), }, { "invalid channel identifier", @@ -1847,6 +1856,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { msg.ChannelId = invalidChannel }, false, + types.ErrInvalidChannelIdentifier, }, { "can submit an empty proof", @@ -1854,6 +1864,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { msg.ProofErrorReceipt = emptyProof }, true, + nil, }, { "missing signer address", @@ -1861,6 +1872,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { msg.Signer = emptyAddr }, false, + errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1876,6 +1888,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.Require().Equal(err.Error(), tc.expErr.Error()) } }) } From 8f3709e24a534858c2aa7d73e6469e1b361ce17a Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 3 Jan 2024 21:34:48 +0100 Subject: [PATCH 13/15] review comment --- modules/core/04-channel/types/msgs_test.go | 26 +++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 9c9386abc6d..3eafaee3b85 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -273,33 +273,28 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { initChannel := types.NewChannel(types.INIT, types.ORDERED, counterparty, connHops, version) testCases := []struct { - name string - msg *types.MsgChannelOpenTry - expPass bool - expErr error + name string + msg *types.MsgChannelOpenTry + expErr error }{ { "success", types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - true, nil, }, { "success with empty counterpartyVersion", types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), - true, nil, }, { "success with empty channel version", types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - true, nil, }, { "too short port id", types.NewMsgChannelOpenTry(invalidShortPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -311,7 +306,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "too long port id", types.NewMsgChannelOpenTry(invalidLongPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -323,7 +317,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "port id contains non-alpha", types.NewMsgChannelOpenTry(invalidPort, version, types.ORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -335,13 +328,11 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "invalid channel order", types.NewMsgChannelOpenTry(portid, version, types.Order(4), connHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(4).String()), }, { "connection hops more than 1 ", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidConnHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( types.ErrTooManyConnectionHops, "current IBC version only supports one connection hop", @@ -350,7 +341,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "too short connection id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -361,7 +351,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "too long connection id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -372,7 +361,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "connection id contains non-alpha", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -384,7 +372,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "invalid counterparty port id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, invalidPort, cpchanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -396,7 +383,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "invalid counterparty channel id", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, invalidChannel, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -408,13 +394,11 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "empty proof", types.NewMsgChannelOpenTry(portid, version, types.UNORDERED, connHops, cpportid, cpchanid, version, emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof"), }, { "channel not in TRYOPEN state", &types.MsgChannelOpenTry{portid, "", initChannel, version, suite.proof, height, addr}, - false, errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", types.TRYOPEN, initChannel.State, @@ -423,7 +407,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { { "previous channel id is not empty", &types.MsgChannelOpenTry{portid, chanid, initChannel, version, suite.proof, height, addr}, - false, errorsmod.Wrap(types.ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported"), }, } @@ -434,7 +417,8 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) From c7bab84a92c6238828d566e775369212f82c4023 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 3 Jan 2024 21:37:58 +0100 Subject: [PATCH 14/15] reorder test cases --- modules/core/04-channel/types/msgs_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 3eafaee3b85..b06ab28449f 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -283,13 +283,13 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryValidateBasic() { nil, }, { - "success with empty counterpartyVersion", - types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), + "success with empty channel version", + types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), nil, }, { - "success with empty channel version", - types.NewMsgChannelOpenTry(portid, "", types.UNORDERED, connHops, cpportid, cpchanid, version, suite.proof, height, addr), + "success with empty counterparty version", + types.NewMsgChannelOpenTry(portid, version, types.ORDERED, connHops, cpportid, cpchanid, "", suite.proof, height, addr), nil, }, { From ed45a5df94c60cdf304f42abf4a75c71fe8a1005 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 3 Jan 2024 21:56:38 +0100 Subject: [PATCH 15/15] remove unnecessary expPass variables --- modules/core/04-channel/types/msgs_test.go | 209 ++++++--------------- 1 file changed, 54 insertions(+), 155 deletions(-) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index b06ab28449f..b5b458d9c8d 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -442,27 +442,23 @@ func (suite *TypesTestSuite) TestMsgChannelOpenTryGetSigners() { func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { testCases := []struct { - name string - msg *types.MsgChannelOpenAck - expPass bool - expErr error + name string + msg *types.MsgChannelOpenAck + expErr error }{ { "success", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, suite.proof, height, addr), - true, nil, }, { "success empty cpv", types.NewMsgChannelOpenAck(portid, chanid, chanid, "", suite.proof, height, addr), - true, nil, }, { "too short port id", types.NewMsgChannelOpenAck(invalidShortPort, chanid, chanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -474,7 +470,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { { "too long port id", types.NewMsgChannelOpenAck(invalidLongPort, chanid, chanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -486,7 +481,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { { "port id contains non-alpha", types.NewMsgChannelOpenAck(invalidPort, chanid, chanid, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -498,31 +492,26 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { { "too short channel id", types.NewMsgChannelOpenAck(portid, invalidShortChannel, chanid, version, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "too long channel id", types.NewMsgChannelOpenAck(portid, invalidLongChannel, chanid, version, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "channel id contains non-alpha", types.NewMsgChannelOpenAck(portid, invalidChannel, chanid, version, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "empty proof", types.NewMsgChannelOpenAck(portid, chanid, chanid, version, emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty try proof"), }, { "invalid counterparty channel id", types.NewMsgChannelOpenAck(portid, chanid, invalidShortChannel, version, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -539,7 +528,8 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -563,21 +553,18 @@ func (suite *TypesTestSuite) TestMsgChannelOpenAckGetSigners() { func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { testCases := []struct { - name string - msg *types.MsgChannelOpenConfirm - expPass bool - expErr error + name string + msg *types.MsgChannelOpenConfirm + expErr error }{ { "success", types.NewMsgChannelOpenConfirm(portid, chanid, suite.proof, height, addr), - true, nil, }, { "too short port id", types.NewMsgChannelOpenConfirm(invalidShortPort, chanid, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -589,7 +576,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { { "too long port id", types.NewMsgChannelOpenConfirm(invalidLongPort, chanid, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -601,7 +587,6 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { { "port id contains non-alpha", types.NewMsgChannelOpenConfirm(invalidPort, chanid, suite.proof, height, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -613,25 +598,21 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { { "too short channel id", types.NewMsgChannelOpenConfirm(portid, invalidShortChannel, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "too long channel id", types.NewMsgChannelOpenConfirm(portid, invalidLongChannel, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "channel id contains non-alpha", types.NewMsgChannelOpenConfirm(portid, invalidChannel, suite.proof, height, addr), - false, types.ErrInvalidChannelIdentifier, }, { "empty proof", types.NewMsgChannelOpenConfirm(portid, chanid, emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof"), }, } @@ -642,7 +623,8 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -666,21 +648,18 @@ func (suite *TypesTestSuite) TestMsgChannelOpenConfirmGetSigners() { func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { testCases := []struct { - name string - msg *types.MsgChannelCloseInit - expPass bool - expErr error + name string + msg *types.MsgChannelCloseInit + expErr error }{ { "success", types.NewMsgChannelCloseInit(portid, chanid, addr), - true, nil, }, { "too short port id", types.NewMsgChannelCloseInit(invalidShortPort, chanid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -692,7 +671,6 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { { "too long port id", types.NewMsgChannelCloseInit(invalidLongPort, chanid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -704,7 +682,6 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { { "port id contains non-alpha", types.NewMsgChannelCloseInit(invalidPort, chanid, addr), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -716,19 +693,16 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { { "too short channel id", types.NewMsgChannelCloseInit(portid, invalidShortChannel, addr), - false, types.ErrInvalidChannelIdentifier, }, { "too long channel id", types.NewMsgChannelCloseInit(portid, invalidLongChannel, addr), - false, types.ErrInvalidChannelIdentifier, }, { "channel id contains non-alpha", types.NewMsgChannelCloseInit(portid, invalidChannel, addr), - false, types.ErrInvalidChannelIdentifier, }, } @@ -739,7 +713,8 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -763,27 +738,23 @@ func (suite *TypesTestSuite) TestMsgChannelCloseInitGetSigners() { func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { testCases := []struct { - name string - msg *types.MsgChannelCloseConfirm - expPass bool - expErr error + name string + msg *types.MsgChannelCloseConfirm + expErr error }{ { "success", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 0), - true, nil, }, { "success, positive counterparty upgrade sequence", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 1), - true, nil, }, { "too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr, 0), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -795,7 +766,6 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { { "too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr, 0), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -807,7 +777,6 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { { "port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr, 0), - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -819,25 +788,21 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { { "too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr, 0), - false, types.ErrInvalidChannelIdentifier, }, { "too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr, 0), - false, types.ErrInvalidChannelIdentifier, }, { "channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr, 0), - false, types.ErrInvalidChannelIdentifier, }, { "empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr, 0), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty init proof"), }, } @@ -848,7 +813,8 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -872,33 +838,28 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmGetSigners() { func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { testCases := []struct { - name string - msg *types.MsgRecvPacket - expPass bool - expErr error + name string + msg *types.MsgRecvPacket + expErr error }{ { "success", types.NewMsgRecvPacket(packet, suite.proof, height, addr), - true, nil, }, { "missing signer address", types.NewMsgRecvPacket(packet, suite.proof, height, emptyAddr), - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, { "proof contain empty proof", types.NewMsgRecvPacket(packet, emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty commitment proof"), }, { "invalid packet", types.NewMsgRecvPacket(invalidPacket, suite.proof, height, addr), - false, errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), }, } @@ -909,7 +870,8 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.NoError(err) } else { suite.Error(err) @@ -933,39 +895,33 @@ func (suite *TypesTestSuite) TestMsgRecvPacketGetSigners() { func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { testCases := []struct { - name string - msg *types.MsgTimeout - expPass bool - expErr error + name string + msg *types.MsgTimeout + expErr error }{ { "success", types.NewMsgTimeout(packet, 1, suite.proof, height, addr), - true, nil, }, { "seq 0", types.NewMsgTimeout(packet, 0, suite.proof, height, addr), - false, errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0"), }, { "missing signer address", types.NewMsgTimeout(packet, 1, suite.proof, height, emptyAddr), - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, { "cannot submit an empty proof", types.NewMsgTimeout(packet, 1, emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof"), }, { "invalid packet", types.NewMsgTimeout(invalidPacket, 1, suite.proof, height, addr), - false, errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), }, } @@ -976,7 +932,8 @@ func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1000,51 +957,43 @@ func (suite *TypesTestSuite) TestMsgTimeoutGetSigners() { func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { testCases := []struct { - name string - msg *types.MsgTimeoutOnClose - expPass bool - expErr error + name string + msg *types.MsgTimeoutOnClose + expErr error }{ { "success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 0), - true, nil, }, { "success, positive counterparty upgrade sequence", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 1), - true, nil, }, { "seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr, 0), - false, errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0"), }, { "signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr, 0), - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, { "empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr, 0), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof"), }, { "empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr, 0), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end"), }, { "invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr, 0), - false, errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), }, } @@ -1055,7 +1004,8 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1079,39 +1029,33 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseGetSigners() { func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { testCases := []struct { - name string - msg *types.MsgAcknowledgement - expPass bool - expErr error + name string + msg *types.MsgAcknowledgement + expErr error }{ { "success", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, addr), - true, nil, }, { "empty ack", types.NewMsgAcknowledgement(packet, nil, suite.proof, height, addr), - false, errorsmod.Wrap(types.ErrInvalidAcknowledgement, "ack bytes cannot be empty"), }, { "missing signer address", types.NewMsgAcknowledgement(packet, packet.GetData(), suite.proof, height, emptyAddr), - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, { "cannot submit an empty proof", types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, height, addr), - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty acknowledgement proof"), }, { "invalid packet", types.NewMsgAcknowledgement(invalidPacket, packet.GetData(), suite.proof, height, addr), - false, errorsmod.Wrap(types.ErrInvalidPacket, "packet sequence cannot be 0"), }, } @@ -1122,7 +1066,8 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() { suite.Run(tc.name, func() { err := tc.msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1150,13 +1095,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1164,7 +1107,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1178,7 +1120,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1186,7 +1127,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { func() { msg.Fields.Version = " " }, - false, errorsmod.Wrap(types.ErrInvalidChannelVersion, "version cannot be empty"), }, { @@ -1194,7 +1134,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1211,7 +1150,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1243,13 +1183,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1257,7 +1195,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1271,7 +1208,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1279,7 +1215,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.CounterpartyUpgradeSequence = 0 }, - false, errorsmod.Wrap(types.ErrInvalidUpgradeSequence, "counterparty sequence cannot be 0"), }, { @@ -1287,7 +1222,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.ProposedUpgradeConnectionHops = []string{} }, - false, errorsmod.Wrap(types.ErrInvalidUpgrade, "proposed connection hops cannot be empty"), }, { @@ -1295,7 +1229,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.CounterpartyUpgradeFields.Ordering = types.NONE }, - false, errorsmod.Wrap( errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.NONE.String()), "error validating counterparty upgrade fields", ), @@ -1305,7 +1238,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.ProofChannel = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { @@ -1313,7 +1245,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.ProofUpgrade = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade proof"), }, { @@ -1321,7 +1252,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1344,7 +1274,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTryValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1382,13 +1313,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1396,7 +1325,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1410,7 +1338,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1418,7 +1345,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { func() { msg.ProofChannel = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { @@ -1426,7 +1352,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { func() { msg.ProofUpgrade = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade sequence proof"), }, { @@ -1434,7 +1359,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1457,7 +1381,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1495,13 +1420,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1509,7 +1432,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.CounterpartyChannelState = types.FLUSHCOMPLETE }, - true, nil, }, { @@ -1517,7 +1439,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1531,7 +1452,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1539,7 +1459,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.CounterpartyChannelState = types.CLOSED }, - false, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected channel state to be one of: %s or %s, got: %s", types.FLUSHING, types.FLUSHCOMPLETE, types.CLOSED), }, { @@ -1547,7 +1466,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.ProofChannel = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { @@ -1555,7 +1473,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.ProofUpgrade = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty upgrade proof"), }, { @@ -1563,7 +1480,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1586,7 +1502,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1615,13 +1532,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success: flushcomplete state", func() {}, - true, nil, }, { @@ -1629,7 +1544,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.CounterpartyChannelState = types.OPEN }, - true, nil, }, { @@ -1637,7 +1551,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1651,7 +1564,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1659,7 +1571,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.CounterpartyChannelState = types.CLOSED }, - false, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected channel state to be one of: [%s, %s], got: %s", types.FLUSHCOMPLETE, types.OPEN, types.CLOSED), }, { @@ -1667,7 +1578,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.ProofChannel = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty channel proof"), }, { @@ -1675,7 +1585,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1692,7 +1601,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1708,13 +1618,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1722,7 +1630,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1736,7 +1643,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1744,7 +1650,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { func() { msg.ProofChannel = emptyProof }, - false, errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof"), }, { @@ -1752,7 +1657,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { func() { msg.CounterpartyChannel.State = types.CLOSED }, - false, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected counterparty channel state to be one of: [%s, %s], got: %s", types.FLUSHING, types.OPEN, types.CLOSED), }, { @@ -1760,7 +1664,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1778,7 +1681,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) @@ -1811,13 +1715,11 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { testCases := []struct { name string malleate func() - expPass bool expErr error }{ { "success", func() {}, - true, nil, }, { @@ -1825,7 +1727,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { func() { msg.PortId = invalidPort }, - false, errorsmod.Wrap( errorsmod.Wrapf( host.ErrInvalidID, @@ -1839,7 +1740,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { func() { msg.ChannelId = invalidChannel }, - false, types.ErrInvalidChannelIdentifier, }, { @@ -1847,7 +1747,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { func() { msg.ProofErrorReceipt = emptyProof }, - true, nil, }, { @@ -1855,7 +1754,6 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { func() { msg.Signer = emptyAddr }, - false, errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", errors.New("empty address string is not allowed")), }, } @@ -1868,7 +1766,8 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() { tc.malleate() err := msg.ValidateBasic() - if tc.expPass { + expPass := tc.expErr == nil + if expPass { suite.Require().NoError(err) } else { suite.Require().Error(err)