z3a_send_packet_filetest.gno
5.86 Kb · 196 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4
5import (
6 "time"
7
8 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
9 "gno.land/p/aib/ibc/types"
10 appstesting "gno.land/r/aib/ibc/apps/testing"
11 "gno.land/r/aib/ibc/core"
12)
13
14// SendPacket success
15func main(cur realm) {
16 var (
17 chainID = "chain-id-2"
18 clientState = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
19 apphash = tmtesting.Hash("apphash")
20 trustedValset = tmtesting.GenValset()
21 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
22 )
23 clientID := core.CreateClient(cross(cur), clientState, consensusState)
24 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
25
26 println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
27 // Register 2 apps
28 var (
29 app1 = appstesting.NewApp(cross(cur))
30 app1PortID = "app1"
31 )
32 core.RegisterApp(cross(cur), app1PortID, app1)
33 var (
34 app2 = appstesting.NewApp(cross(cur))
35 app2PortID = "app2"
36 )
37 core.RegisterApp(cross(cur), app2PortID, app2)
38
39 packet := types.MsgSendPacket{
40 SourceClient: clientID,
41 TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
42 Payloads: []types.Payload{
43 {
44 SourcePort: app1PortID,
45 DestinationPort: "destinationPort",
46 Encoding: "application/json",
47 Value: []byte("{}"),
48 Version: "v1",
49 },
50 {
51 SourcePort: app2PortID,
52 DestinationPort: "destinationPort",
53 Encoding: "application/json",
54 Value: []byte("{}"),
55 Version: "v1",
56 },
57 },
58 }
59
60 sequence := core.SendPacket(cross(cur), packet)
61
62 println("returned sequence:", sequence)
63 println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
64 println("----------- app1 report")
65 println(app1.Report())
66 println("----------- app2 report")
67 println(app2.Report())
68
69 // Send the packet an other time to assert sequence increasing
70 sequence = core.SendPacket(cross(cur), packet)
71
72 println("returned sequence:", sequence)
73 println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
74 println("----------- assert render clients/07-tendermint-1/packet_commitments")
75 println(core.Render("clients/" + clientID + "/packet_commitments"))
76 println("----------- assert render clients/07-tendermint-1/packet_commitments/1")
77 println(core.Render("clients/" + clientID + "/packet_commitments/1"))
78}
79
80// Output:
81// next sequence: {"next_sequence_send": 1}"
82// returned sequence: 1
83// next sequence: {"next_sequence_send": 2}"
84// ----------- app1 report
85// OnSendPacket (1)
86// - sourceClient: 07-tendermint-1
87// - destinationClient: 07-tendermint-2
88// - sequence: 1
89// - payload:
90// - sourcePort: app1
91// - destinationPort: destinationPort
92// - version: v1
93// - encoding: application/json
94// - value: {}
95//
96// OnRecvPacket (0)
97// OnTimeoutPacket (0)
98// OnAcknowledgementPacket (0)
99//
100// ----------- app2 report
101// OnSendPacket (1)
102// - sourceClient: 07-tendermint-1
103// - destinationClient: 07-tendermint-2
104// - sequence: 1
105// - payload:
106// - sourcePort: app2
107// - destinationPort: destinationPort
108// - version: v1
109// - encoding: application/json
110// - value: {}
111//
112// OnRecvPacket (0)
113// OnTimeoutPacket (0)
114// OnAcknowledgementPacket (0)
115//
116// returned sequence: 2
117// next sequence: {"next_sequence_send": 3}"
118// ----------- assert render clients/07-tendermint-1/packet_commitments
119// {"items":[{"sequence":"1","data":"IrnGu6pyeXzbWlH2gsUv6cZlxEZjTGa5OfMKACFYs4E="},{"sequence":"2","data":"IrnGu6pyeXzbWlH2gsUv6cZlxEZjTGa5OfMKACFYs4E="}],"page":1,"total":1}
120// ----------- assert render clients/07-tendermint-1/packet_commitments/1
121// {"sequence":"1","data":"IrnGu6pyeXzbWlH2gsUv6cZlxEZjTGa5OfMKACFYs4E="}
122
123// Events:
124// [
125// {
126// "type": "create_client",
127// "attrs": [
128// {
129// "key": "client_id",
130// "value": "07-tendermint-1"
131// },
132// {
133// "key": "client_type",
134// "value": "07-tendermint"
135// },
136// {
137// "key": "consensus_heights",
138// "value": "2/2"
139// }
140// ],
141// "pkg_path": "gno.land/r/aib/ibc/core"
142// },
143// {
144// "type": "send_packet",
145// "attrs": [
146// {
147// "key": "packet_source_client",
148// "value": "07-tendermint-1"
149// },
150// {
151// "key": "packet_dest_client",
152// "value": "07-tendermint-2"
153// },
154// {
155// "key": "packet_sequence",
156// "value": "1"
157// },
158// {
159// "key": "packet_timeout_timestamp",
160// "value": "1234571490"
161// },
162// {
163// "key": "encoded_packet_hex",
164// "value": "0801120f30372d74656e6465726d696e742d311a0f30372d74656e6465726d696e742d3220e2a1d8cc042a310a0461707031120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d2a310a0461707032120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
165// }
166// ],
167// "pkg_path": "gno.land/r/aib/ibc/core"
168// },
169// {
170// "type": "send_packet",
171// "attrs": [
172// {
173// "key": "packet_source_client",
174// "value": "07-tendermint-1"
175// },
176// {
177// "key": "packet_dest_client",
178// "value": "07-tendermint-2"
179// },
180// {
181// "key": "packet_sequence",
182// "value": "2"
183// },
184// {
185// "key": "packet_timeout_timestamp",
186// "value": "1234571490"
187// },
188// {
189// "key": "encoded_packet_hex",
190// "value": "0802120f30372d74656e6465726d696e742d311a0f30372d74656e6465726d696e742d3220e2a1d8cc042a310a0461707031120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d2a310a0461707032120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
191// }
192// ],
193// "pkg_path": "gno.land/r/aib/ibc/core"
194// }
195// ]
196