Skip to content

Commit

Permalink
test: ensure that the packet commit changes if the packed fields chan…
Browse files Browse the repository at this point in the history
…ges (#7514)

* test: ensure that the packet commit changes if the packed fields changes

* test: fix lint and sequence

* test: tweak test slightly

* chore: fix linter complaint.

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
cl1ckname and DimitrisJim authored Nov 12, 2024
1 parent 84c176a commit 083cfb1
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions modules/core/04-channel/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,44 @@ import (
)

func TestCommitPacket(t *testing.T) {
packet := types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp)

registry := codectypes.NewInterfaceRegistry()
clienttypes.RegisterInterfaces(registry)
types.RegisterInterfaces(registry)

cdc := codec.NewProtoCodec(registry)

packet := types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp)
commitment := types.CommitPacket(cdc, packet)
require.NotNil(t, commitment)

testCases := []struct {
name string
packet types.Packet
}{
{
name: "diff data",
packet: types.NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp),
},
{
name: "diff timeout revision number",
packet: types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, clienttypes.NewHeight(timeoutHeight.RevisionNumber+1, timeoutHeight.RevisionHeight), timeoutTimestamp),
},
{
name: "diff timeout revision height",
packet: types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, clienttypes.NewHeight(timeoutHeight.RevisionNumber, timeoutHeight.RevisionHeight+1), timeoutTimestamp),
},
{
name: "diff timeout timestamp",
packet: types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, uint64(1)),
},
}

for _, tc := range testCases {
testCommitment := types.CommitPacket(cdc, tc.packet)
require.NotNil(t, testCommitment)

require.NotEqual(t, commitment, testCommitment)
}
}

func TestPacketValidateBasic(t *testing.T) {
Expand All @@ -44,8 +72,6 @@ func TestPacketValidateBasic(t *testing.T) {
}

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

err := tc.packet.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "Msg %d failed: %s", i, tc.errMsg)
Expand Down

0 comments on commit 083cfb1

Please sign in to comment.