z5aa_acknowledgement_filetest.gno
8.52 Kb · 276 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "encoding/hex"
6 "time"
7
8 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
9 "gno.land/p/aib/ibc/types"
10 "gno.land/p/aib/ics23"
11 appstesting "gno.land/r/aib/ibc/apps/testing"
12 "gno.land/r/aib/ibc/core"
13)
14
15// Acknowledgement success with authorized relayer
16func main(cur realm) {
17 core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
18 core.AddRelayer(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
19 var (
20 chainID = "chain-id-2"
21 trustedHeight = types.NewHeight(2, 2)
22 clientState = tmtesting.NewClientState(chainID, trustedHeight)
23 apphash, _ = hex.DecodeString("a119217258843545bc79dd7df4c050c6c2a21b1de7c132dd065fd7463f743e2d")
24 trustedValset = tmtesting.GenValset()
25 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
26 counterpartyID = "07-tendermint-42"
27 )
28 clientID := core.CreateClient(cross(cur), clientState, consensusState)
29 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
30 // Register app
31 var (
32 app = appstesting.NewApp(cross(cur))
33 appPortID = "app"
34 )
35 core.RegisterApp(cross(cur), appPortID, app)
36 // Send a packet
37 sendPacket := types.MsgSendPacket{
38 SourceClient: clientID,
39 TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
40 Payloads: []types.Payload{{
41 SourcePort: appPortID,
42 DestinationPort: "destinationPort",
43 Encoding: "application/json",
44 Value: []byte("{}"),
45 Version: "v1",
46 }},
47 }
48
49 sequence := core.SendPacket(cross(cur), sendPacket)
50
51 // Acknowledge the packet
52 specs := ics23.IavlSpec()
53 // Generate the proof of acknowledgement written during the RecvPacket of the
54 // counterparty client.
55 // NOTE proof generated by ./cmd/gen-proof 'prefix2' '07-tendermint-42' 'acknowledgement' '{"response":{"result":"BQ=="}}'
56 proofAcked := []ics23.CommitmentProof{
57
58 // iavl proof
59 ics23.CommitmentProof_Exist{
60 Exist: &ics23.ExistenceProof{
61 Key: []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x03\x00\x00\x00\x00\x00\x00\x00\x01"),
62 Value: []byte("\x21\x29\x3f\x61\xea\x42\x91\xdc\x31\x88\xaa\x8b\xe6\xde\x66\xeb\x0e\xe0\x5b\x10\x03\x25\xb0\x31\x3b\x25\x84\xf2\xc0\x96\x11\xaf"),
63 Leaf: &ics23.LeafOp{
64 Hash: specs.LeafSpec.Hash,
65 PrehashKey: specs.LeafSpec.PrehashKey,
66 PrehashValue: specs.LeafSpec.PrehashValue,
67 Length: specs.LeafSpec.Length,
68 Prefix: []byte("\x00\x02\x02"),
69 },
70 Path: []*ics23.InnerOp{
71 {
72 Hash: specs.InnerSpec.Hash,
73 Prefix: []byte("\x02\x04\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"),
74 Suffix: []byte(""),
75 },
76 {
77 Hash: specs.InnerSpec.Hash,
78 Prefix: []byte("\x04\x08\x02\x20"),
79 Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"),
80 },
81 {
82 Hash: specs.InnerSpec.Hash,
83 Prefix: []byte("\x06\x0c\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"),
84 Suffix: []byte(""),
85 },
86 },
87 },
88 },
89
90 // rootmulti proof
91 ics23.CommitmentProof_Exist{
92 Exist: &ics23.ExistenceProof{
93 Key: []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
94 Value: []byte("\x54\x67\x6b\x16\xcf\xa5\x41\x3e\x30\x2b\x0d\xff\x76\x7d\x1d\xa8\x11\x44\x0b\x38\x36\x08\xc7\xd8\xab\x6a\x1b\x36\x47\x82\x1f\x1d"),
95 Leaf: &ics23.LeafOp{
96 Hash: specs.LeafSpec.Hash,
97 PrehashKey: specs.LeafSpec.PrehashKey,
98 PrehashValue: specs.LeafSpec.PrehashValue,
99 Length: specs.LeafSpec.Length,
100 Prefix: []byte("\x00"),
101 },
102 Path: []*ics23.InnerOp{},
103 },
104 },
105 }
106
107 ackPacket := types.MsgAcknowledgement{
108 Packet: types.Packet{
109 Sequence: sequence,
110 SourceClient: clientID,
111 DestinationClient: counterpartyID,
112 TimeoutTimestamp: sendPacket.TimeoutTimestamp,
113 Payloads: sendPacket.Payloads,
114 },
115 Acknowledgement: types.Acknowledgement{
116 AppAcknowledgements: [][]byte{[]byte(`{"response":{"result":"BQ=="}}`)},
117 },
118 ProofAcked: proofAcked,
119 ProofHeight: trustedHeight,
120 }
121
122 res := core.Acknowledgement(cross(cur), ackPacket)
123
124 println("res:", res)
125 println("\n----------- assert render clients/07-tendermint-1/packet_commitments")
126 println(core.Render("clients/" + clientID + "/packet_commitments"))
127 println("----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared)")
128 println(core.Render("clients/" + clientID + "/packet_commitments/1"))
129 println("\n----------- app report")
130 println(app.Report())
131
132 // assert NOOP response (res=1) if ack is resubmitted
133 res = core.Acknowledgement(cross(cur), ackPacket)
134
135 println("res:", res)
136 println("\n----------- app report")
137 println(app.Report())
138}
139
140// Output:
141// res: (2 gno.land/p/aib/ibc/types.ResponseResultType)
142//
143// ----------- assert render clients/07-tendermint-1/packet_commitments
144// {"items":[],"page":1,"total":1}
145// ----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared)
146// {"error":"sequence 1 not found"}
147//
148// ----------- app report
149// OnSendPacket (1)
150// - sourceClient: 07-tendermint-1
151// - destinationClient: 07-tendermint-42
152// - sequence: 1
153// - payload:
154// - sourcePort: app
155// - destinationPort: destinationPort
156// - version: v1
157// - encoding: application/json
158// - value: {}
159//
160// OnRecvPacket (0)
161// OnTimeoutPacket (0)
162// OnAcknowledgementPacket (1)
163// - sourceClient: 07-tendermint-1
164// - destinationClient: 07-tendermint-42
165// - sequence: 1
166// - payload:
167// - sourcePort: app
168// - destinationPort: destinationPort
169// - version: v1
170// - encoding: application/json
171// - value: {}
172// - ack: {"response":{"result":"BQ=="}}
173//
174//
175// res: (1 gno.land/p/aib/ibc/types.ResponseResultType)
176//
177// ----------- app report
178// OnSendPacket (1)
179// - sourceClient: 07-tendermint-1
180// - destinationClient: 07-tendermint-42
181// - sequence: 1
182// - payload:
183// - sourcePort: app
184// - destinationPort: destinationPort
185// - version: v1
186// - encoding: application/json
187// - value: {}
188//
189// OnRecvPacket (0)
190// OnTimeoutPacket (0)
191// OnAcknowledgementPacket (1)
192// - sourceClient: 07-tendermint-1
193// - destinationClient: 07-tendermint-42
194// - sequence: 1
195// - payload:
196// - sourcePort: app
197// - destinationPort: destinationPort
198// - version: v1
199// - encoding: application/json
200// - value: {}
201// - ack: {"response":{"result":"BQ=="}}
202
203// Events:
204// [
205// {
206// "type": "create_client",
207// "attrs": [
208// {
209// "key": "client_id",
210// "value": "07-tendermint-1"
211// },
212// {
213// "key": "client_type",
214// "value": "07-tendermint"
215// },
216// {
217// "key": "consensus_heights",
218// "value": "2/2"
219// }
220// ],
221// "pkg_path": "gno.land/r/aib/ibc/core"
222// },
223// {
224// "type": "send_packet",
225// "attrs": [
226// {
227// "key": "packet_source_client",
228// "value": "07-tendermint-1"
229// },
230// {
231// "key": "packet_dest_client",
232// "value": "07-tendermint-42"
233// },
234// {
235// "key": "packet_sequence",
236// "value": "1"
237// },
238// {
239// "key": "packet_timeout_timestamp",
240// "value": "1234571490"
241// },
242// {
243// "key": "encoded_packet_hex",
244// "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
245// }
246// ],
247// "pkg_path": "gno.land/r/aib/ibc/core"
248// },
249// {
250// "type": "acknowledge_packet",
251// "attrs": [
252// {
253// "key": "packet_source_client",
254// "value": "07-tendermint-1"
255// },
256// {
257// "key": "packet_dest_client",
258// "value": "07-tendermint-42"
259// },
260// {
261// "key": "packet_sequence",
262// "value": "1"
263// },
264// {
265// "key": "packet_timeout_timestamp",
266// "value": "1234571490"
267// },
268// {
269// "key": "encoded_packet_hex",
270// "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
271// }
272// ],
273// "pkg_path": "gno.land/r/aib/ibc/core"
274// }
275// ]
276