z5aaa_transfer_filetest.gno
5.12 Kb · 189 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "chain"
6 "time"
7
8 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
9 "gno.land/p/aib/ibc/types"
10
11 "gno.land/r/aib/ibc/apps/testing/grc20test"
12 "gno.land/r/aib/ibc/apps/transfer"
13 "gno.land/r/aib/ibc/core"
14)
15
16// Transfer: success for non-IBC GRC20 token
17func main(cur realm) {
18 var (
19 chainID = "chain-id-2"
20 clientState = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
21 apphash = tmtesting.Hash("apphash")
22 trustedValset = tmtesting.GenValset()
23 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
24 )
25 clientID := core.CreateClient(cross(cur), clientState, consensusState)
26 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
27
28 caller := cur.Previous().Address()
29
30 // Mint test GRC20 tokens to the caller
31 grc20test.Mint(cross(cur), caller, 1000)
32
33 // Approve the transfer app realm to spend 100 tokens
34 transferAppAddr := chain.PackageAddress("gno.land/r/aib/ibc/apps/transfer")
35 grc20test.Approve(cross(cur), caller, transferAppAddr, 100)
36
37 // grc20reg key for the test token (registered with empty slug)
38 denom := "gno.land/r/aib/ibc/apps/testing/grc20test." + grc20test.Slug
39
40 println("----------- balance before Transfer:", grc20test.BalanceOf(caller))
41
42 transfer.Transfer(cross(cur), clientID, "atone1user", denom, 100, uint64(time.Now().Add(time.Hour).Unix()), "")
43
44 println("----------- balance after Transfer:", grc20test.BalanceOf(caller))
45}
46
47// Output:
48// ----------- balance before Transfer: 1000
49// ----------- balance after Transfer: 900
50
51// Events:
52// [
53// {
54// "type": "create_client",
55// "attrs": [
56// {
57// "key": "client_id",
58// "value": "07-tendermint-1"
59// },
60// {
61// "key": "client_type",
62// "value": "07-tendermint"
63// },
64// {
65// "key": "consensus_heights",
66// "value": "2/2"
67// }
68// ],
69// "pkg_path": "gno.land/r/aib/ibc/core"
70// },
71// {
72// "type": "Transfer",
73// "attrs": [
74// {
75// "key": "token",
76// "value": "gno.land/r/aib/ibc/apps/testing/grc20test.TEST"
77// },
78// {
79// "key": "from",
80// "value": ""
81// },
82// {
83// "key": "to",
84// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"
85// },
86// {
87// "key": "value",
88// "value": "1000"
89// }
90// ],
91// "pkg_path": "gno.land/p/demo/tokens/grc20"
92// },
93// {
94// "type": "Approval",
95// "attrs": [
96// {
97// "key": "token",
98// "value": "gno.land/r/aib/ibc/apps/testing/grc20test.TEST"
99// },
100// {
101// "key": "owner",
102// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"
103// },
104// {
105// "key": "spender",
106// "value": "g1tp3gk4quumurav4858hjfdy6hxtyffwmnxyr00"
107// },
108// {
109// "key": "value",
110// "value": "100"
111// }
112// ],
113// "pkg_path": "gno.land/p/demo/tokens/grc20"
114// },
115// {
116// "type": "send_packet",
117// "attrs": [
118// {
119// "key": "packet_source_client",
120// "value": "07-tendermint-1"
121// },
122// {
123// "key": "packet_dest_client",
124// "value": "07-tendermint-2"
125// },
126// {
127// "key": "packet_sequence",
128// "value": "1"
129// },
130// {
131// "key": "packet_timeout_timestamp",
132// "value": "1234571490"
133// },
134// {
135// "key": "encoded_packet_hex",
136// "value": "0801120f30372d74656e6465726d696e742d311a0f30372d74656e6465726d696e742d3220e2a1d8cc042aa2010a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a6b0a2e676e6f2e6c616e643a723a6169623a6962633a617070733a74657374696e673a6772633230746573742e5445535412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e653175736572"
137// }
138// ],
139// "pkg_path": "gno.land/r/aib/ibc/core"
140// },
141// {
142// "type": "Transfer",
143// "attrs": [
144// {
145// "key": "token",
146// "value": "gno.land/r/aib/ibc/apps/testing/grc20test.TEST"
147// },
148// {
149// "key": "from",
150// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"
151// },
152// {
153// "key": "to",
154// "value": "g1tp3gk4quumurav4858hjfdy6hxtyffwmnxyr00"
155// },
156// {
157// "key": "value",
158// "value": "100"
159// }
160// ],
161// "pkg_path": "gno.land/p/demo/tokens/grc20"
162// },
163// {
164// "type": "ibc_transfer",
165// "attrs": [
166// {
167// "key": "sender",
168// "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"
169// },
170// {
171// "key": "receiver",
172// "value": "atone1user"
173// },
174// {
175// "key": "denom",
176// "value": "gno.land:r:aib:ibc:apps:testing:grc20test.TEST"
177// },
178// {
179// "key": "amount",
180// "value": "100"
181// },
182// {
183// "key": "memo",
184// "value": ""
185// }
186// ],
187// "pkg_path": "gno.land/r/aib/ibc/apps/transfer"
188// }
189// ]