Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Check for error returned in channel msg_tests #5492

Merged
Merged
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
338ba87
update test for MsgChannelOpenInit
expertdicer Dec 23, 2023
a170892
update test for MsgChannelOpenTry
expertdicer Dec 23, 2023
077d754
Use error as expError.
DimitrisJim Dec 23, 2023
0e4c0f3
update TestMsgChannelOpenAckValidateBasic
expertdicer Dec 25, 2023
c6bb11d
update TestMsgChannelOpenConfirmValidateBasic
expertdicer Dec 25, 2023
e9cf3b9
update TestMsgChannelCloseInitValidateBasic and TestMsgChannelCloseCo…
expertdicer Dec 25, 2023
1c2cb66
update TestMsgRecvPacketValidateBasic
expertdicer Dec 25, 2023
45e18a3
update TestMsgTimeoutValidateBasic
expertdicer Dec 25, 2023
e6b892b
update TestMsgTimeoutOnCloseValidateBasic, TestMsgAcknowledgementVali…
expertdicer Dec 25, 2023
86f4507
update TestMsgChannelUpgradeAckValidateBasic, TestMsgChannelUpgradeCo…
expertdicer Dec 25, 2023
3a73da0
update TestMsgChannelUpgradeOpenValidateBasic and TestMsgChannelUpgra…
expertdicer Dec 25, 2023
12d5e4f
update TestMsgChannelUpgradeCancelValidateBasic
expertdicer Dec 25, 2023
497b9d1
Merge branch 'main' into nguyen/update-channel-msg-tests
DimitrisJim Jan 2, 2024
fd2c0c2
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 3, 2024
8f3709e
review comment
crodriguezvega Jan 3, 2024
c7bab84
reorder test cases
crodriguezvega Jan 3, 2024
ed45a5d
remove unnecessary expPass variables
crodriguezvega Jan 3, 2024
5e3b0e7
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 4, 2024
47892dc
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 4, 2024
7e896cc
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 5, 2024
d11913c
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 5, 2024
f416809
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 5, 2024
aafd1d8
Merge branch 'main' into nguyen/update-channel-msg-tests
crodriguezvega Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 271 additions & 32 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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"
Expand Down Expand Up @@ -119,33 +120,137 @@
tryOpenChannel := types.NewChannel(types.TRYOPEN, types.ORDERED, counterparty, connHops, version)

testCases := []struct {
name string
msg *types.MsgChannelOpenInit
expPass bool
name string
msg *types.MsgChannelOpenInit
expErr error
}{
{"", 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},
{
"success",
types.NewMsgChannelOpenInit(portid, version, types.ORDERED, connHops, cpportid, addr),
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),
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.NewMsgChannelOpenInit(invalidLongPort, version, types.ORDERED, connHops, cpportid, addr),
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.NewMsgChannelOpenInit(invalidPort, version, types.ORDERED, connHops, cpportid, addr),
errorsmod.Wrap(
errorsmod.Wrapf(
host.ErrInvalidID,
"identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'",
invalidPort,
), "invalid port ID"),
},
{
"invalid channel order",
types.NewMsgChannelOpenInit(portid, version, types.Order(3),
connHops, cpportid, addr),
errorsmod.Wrap(types.ErrInvalidChannelOrdering, types.Order(3).String()),
},
{
"connection hops more than 1 ",
types.NewMsgChannelOpenInit(portid, version, types.ORDERED, invalidConnHops, cpportid, addr),
errorsmod.Wrap(
types.ErrTooManyConnectionHops,
"current IBC version only supports one connection hop",
),
},
{
"too short connection id",
types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidShortConnHops, cpportid, addr),
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",
),
},
{
"too long connection id",
types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, invalidLongConnHops, cpportid, addr),
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",
),
},
{
"connection id contains non-alpha",
types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, []string{invalidConnection}, cpportid, addr),
errorsmod.Wrap(
errorsmod.Wrapf(
host.ErrInvalidID,
"identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'",
invalidConnection,
), "invalid connection hop ID",
),
},
{
"invalid counterparty port id",
types.NewMsgChannelOpenInit(portid, version, types.UNORDERED, connHops, invalidPort, addr),
errorsmod.Wrap(
errorsmod.Wrapf(
host.ErrInvalidID,
"identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'",
invalidPort,
), "invalid counterparty port ID",
),
},
{
"channel not in INIT state",
&types.MsgChannelOpenInit{portid, tryOpenChannel, addr},
errorsmod.Wrapf(types.ErrInvalidChannelState,
"channel state must be INIT in MsgChannelOpenInit. expected: %s, got: %s",
types.INIT, tryOpenChannel.State,
),
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {

Check failure on line 245 in modules/core/04-channel/types/msgs_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
err := tc.msg.ValidateBasic()
if tc.expPass {

expPass := tc.expErr == nil
if expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().Equal(err.Error(), tc.expErr.Error())
}
})
}
Expand All @@ -171,23 +276,156 @@
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,
expertdicer marked this conversation as resolved.
Show resolved Hide resolved
"",
},
{
"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 {
Expand All @@ -200,6 +438,7 @@
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Assert().Equal(err.Error(), tc.expErr)
}
})
}
Expand Down
Loading