z5f_acknowledgement_filetest.gno
2.22 Kb · 73 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "time"
6
7 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
8 "gno.land/p/aib/ibc/types"
9 "gno.land/p/aib/ics23"
10 appstesting "gno.land/r/aib/ibc/apps/testing"
11 "gno.land/r/aib/ibc/core"
12)
13
14// Acknowledgement commitment mismatch
15func main(cur realm) {
16 var (
17 chainID = "chain-id-2"
18 trustedHeight = types.NewHeight(2, 2)
19 clientState = tmtesting.NewClientState(chainID, trustedHeight)
20 apphash = tmtesting.Hash("apphash")
21 trustedValset = tmtesting.GenValset()
22 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
23 counterpartyID = "07-tendermint-42"
24 )
25 clientID := core.CreateClient(cross(cur), clientState, consensusState)
26 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
27 // Register app
28 var (
29 app = appstesting.NewApp(cross(cur))
30 appPortID = "app"
31 )
32 core.RegisterApp(cross(cur), appPortID, app)
33 // Send a packet
34 sendPacket := types.MsgSendPacket{
35 SourceClient: clientID,
36 TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
37 Payloads: []types.Payload{{
38 SourcePort: appPortID,
39 DestinationPort: "destinationPort",
40 Encoding: "application/json",
41 Value: []byte("{}"),
42 Version: "v1",
43 }},
44 }
45 sequence := core.SendPacket(cross(cur), sendPacket)
46
47 // Acknowledge the packet
48 ackPacket := types.MsgAcknowledgement{
49 Packet: types.Packet{
50 Sequence: sequence,
51 SourceClient: clientID,
52 DestinationClient: counterpartyID,
53 // Timeout is different than in SendPacket, so the commitments bytes will
54 // differ as well.
55 TimeoutTimestamp: 1,
56 Payloads: sendPacket.Payloads,
57 },
58 Acknowledgement: types.Acknowledgement{
59 AppAcknowledgements: [][]byte{[]byte("ack")},
60 },
61 ProofAcked: []ics23.CommitmentProof{
62 ics23.CommitmentProof_Exist{
63 Exist: &ics23.ExistenceProof{},
64 },
65 },
66 ProofHeight: trustedHeight,
67 }
68
69 core.Acknowledgement(cross(cur), ackPacket)
70}
71
72// Error:
73// commitment bytes are not equal: got (95f930b7d780346ee34bc62df41384e82d5e665e583fb353dfaa322df8e75299), expected (af551c2bb8928f6b2f452fc421783d5ecd5a71b317b50224f25a9749ed89e479)