commitment_test.gno
1.41 Kb · 54 lines
1package types_test
2
3import (
4 "encoding/hex"
5 "testing"
6
7 "gno.land/p/aib/ibc/types"
8 "gno.land/p/nt/urequire/v0"
9)
10
11// TestCommitPacket is primarily used to document the expected commitment output
12// so that other implementations (such as the IBC Solidity) can replicate the
13// same commitment output. But it is also useful to catch any changes in the commitment.
14func TestCommitPacket(t *testing.T) {
15 var packet types.Packet
16 testCases := []struct {
17 name string
18 malleate func()
19 expectedHash string
20 }{
21 {
22 "json packet",
23 func() {}, // default is json packet
24 "a096722aa6534040a0efbdae05765132a7b223ad306d6512f3734821bd046505",
25 },
26 }
27
28 for _, tc := range testCases {
29 t.Run(tc.name, func(t *testing.T) {
30 transferData := `{"denom":"uatom","amount":"1000000","sender":"sender","receiver":"receiver","memo":"memo"}`
31 packet = types.Packet{
32 Sequence: 1,
33 SourceClient: "07-tendermint-0",
34 DestinationClient: "07-tendermint-1",
35 TimeoutTimestamp: 100,
36 Payloads: []types.Payload{
37 {
38 SourcePort: "transfer",
39 DestinationPort: "transfer",
40 Version: "ics20-1",
41 Encoding: "application/json",
42 Value: []byte(transferData),
43 },
44 },
45 }
46 tc.malleate()
47
48 commitment := types.CommitPacket(packet)
49
50 urequire.Equal(t, tc.expectedHash, hex.EncodeToString(commitment))
51 urequire.Equal(t, 32, len(commitment))
52 })
53 }
54}