z3a_send_packet_filetest.gno
5.28 Kb · 178 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, only app1 is targeted by the packet payload.
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 }
52
53 sequence := core.SendPacket(cross(cur), packet)
54
55 println("returned sequence:", sequence)
56 println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
57 println("----------- app1 report")
58 println(app1.Report())
59 println("----------- app2 report")
60 println(app2.Report())
61
62 // Send the packet an other time to assert sequence increasing
63 sequence = core.SendPacket(cross(cur), packet)
64
65 println("returned sequence:", sequence)
66 println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
67 println("----------- assert render clients/07-tendermint-1/packet_commitments")
68 println(core.Render("clients/" + clientID + "/packet_commitments"))
69 println("----------- assert render clients/07-tendermint-1/packet_commitments/1")
70 println(core.Render("clients/" + clientID + "/packet_commitments/1"))
71}
72
73// Output:
74// next sequence: {"next_sequence_send": 1}"
75// returned sequence: 1
76// next sequence: {"next_sequence_send": 2}"
77// ----------- app1 report
78// OnSendPacket (1)
79// - sourceClient: 07-tendermint-1
80// - destinationClient: 07-tendermint-2
81// - sequence: 1
82// - payload:
83// - sourcePort: app1
84// - destinationPort: destinationPort
85// - version: v1
86// - encoding: application/json
87// - value: {}
88//
89// OnRecvPacket (0)
90// OnTimeoutPacket (0)
91// OnAcknowledgementPacket (0)
92//
93// ----------- app2 report
94// OnSendPacket (0)
95// OnRecvPacket (0)
96// OnTimeoutPacket (0)
97// OnAcknowledgementPacket (0)
98//
99// returned sequence: 2
100// next sequence: {"next_sequence_send": 3}"
101// ----------- assert render clients/07-tendermint-1/packet_commitments
102// {"items":[{"sequence":"1","data":"oyZ+seOMNQrPOErL+0WJp0pHKAMur2SlkdChrVRzm28="},{"sequence":"2","data":"oyZ+seOMNQrPOErL+0WJp0pHKAMur2SlkdChrVRzm28="}],"page":1,"total":1}
103// ----------- assert render clients/07-tendermint-1/packet_commitments/1
104// {"sequence":"1","data":"oyZ+seOMNQrPOErL+0WJp0pHKAMur2SlkdChrVRzm28="}
105
106// Events:
107// [
108// {
109// "type": "create_client",
110// "attrs": [
111// {
112// "key": "client_id",
113// "value": "07-tendermint-1"
114// },
115// {
116// "key": "client_type",
117// "value": "07-tendermint"
118// },
119// {
120// "key": "consensus_heights",
121// "value": "2/2"
122// }
123// ],
124// "pkg_path": "gno.land/r/aib/ibc/core"
125// },
126// {
127// "type": "send_packet",
128// "attrs": [
129// {
130// "key": "packet_source_client",
131// "value": "07-tendermint-1"
132// },
133// {
134// "key": "packet_dest_client",
135// "value": "07-tendermint-2"
136// },
137// {
138// "key": "packet_sequence",
139// "value": "1"
140// },
141// {
142// "key": "packet_timeout_timestamp",
143// "value": "1234571490"
144// },
145// {
146// "key": "encoded_packet_hex",
147// "value": "0801120f30372d74656e6465726d696e742d311a0f30372d74656e6465726d696e742d3220e2a1d8cc042a310a0461707031120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
148// }
149// ],
150// "pkg_path": "gno.land/r/aib/ibc/core"
151// },
152// {
153// "type": "send_packet",
154// "attrs": [
155// {
156// "key": "packet_source_client",
157// "value": "07-tendermint-1"
158// },
159// {
160// "key": "packet_dest_client",
161// "value": "07-tendermint-2"
162// },
163// {
164// "key": "packet_sequence",
165// "value": "2"
166// },
167// {
168// "key": "packet_timeout_timestamp",
169// "value": "1234571490"
170// },
171// {
172// "key": "encoded_packet_hex",
173// "value": "0802120f30372d74656e6465726d696e742d311a0f30372d74656e6465726d696e742d3220e2a1d8cc042a310a0461707031120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
174// }
175// ],
176// "pkg_path": "gno.land/r/aib/ibc/core"
177// }
178// ]