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