token_identity_filetest.gno
3.78 Kb · 171 lines
1// PKGPATH: gno.land/r/demo/grc20identity
2
3package grc20identity
4
5import (
6 "chain"
7
8 "gno.land/p/demo/tokens/grc20"
9 "gno.land/p/nt/seqid/v0"
10)
11
12var nextTokenID seqid.ID
13
14func main(cur realm) {
15 first, firstLedger := newToken(cur)
16 second, secondLedger := newToken(cur)
17
18 if first.ID() != "gno.land/r/demo/grc20identity.DUP.0000001" {
19 panic("unexpected first token ID: " + first.ID())
20 }
21 if second.ID() != "gno.land/r/demo/grc20identity.DUP.0000002" {
22 panic("unexpected second token ID: " + second.ID())
23 }
24
25 holder := chain.PackageAddress("holder")
26 spender := chain.PackageAddress("spender")
27 firstLedger.Mint(holder, 1)
28 firstLedger.Approve(holder, spender, 1)
29 secondLedger.Mint(holder, 2)
30 secondLedger.Approve(holder, spender, 2)
31}
32
33func newToken(cur realm) (*grc20.Token, *grc20.PrivateLedger) {
34 return grc20.NewToken("Same", "DUP", 6, nextTokenID.Next(), cur)
35}
36
37// Events:
38// [
39// {
40// "type": "NewToken",
41// "attrs": [
42// {
43// "key": "token",
44// "value": "gno.land/r/demo/grc20identity.DUP.0000001"
45// },
46// {
47// "key": "name",
48// "value": "Same"
49// },
50// {
51// "key": "symbol",
52// "value": "DUP"
53// },
54// {
55// "key": "decimals",
56// "value": "6"
57// }
58// ],
59// "pkg_path": "gno.land/p/demo/tokens/grc20"
60// },
61// {
62// "type": "NewToken",
63// "attrs": [
64// {
65// "key": "token",
66// "value": "gno.land/r/demo/grc20identity.DUP.0000002"
67// },
68// {
69// "key": "name",
70// "value": "Same"
71// },
72// {
73// "key": "symbol",
74// "value": "DUP"
75// },
76// {
77// "key": "decimals",
78// "value": "6"
79// }
80// ],
81// "pkg_path": "gno.land/p/demo/tokens/grc20"
82// },
83// {
84// "type": "Transfer",
85// "attrs": [
86// {
87// "key": "token",
88// "value": "gno.land/r/demo/grc20identity.DUP.0000001"
89// },
90// {
91// "key": "from",
92// "value": ""
93// },
94// {
95// "key": "to",
96// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
97// },
98// {
99// "key": "value",
100// "value": "1"
101// }
102// ],
103// "pkg_path": "gno.land/p/demo/tokens/grc20"
104// },
105// {
106// "type": "Approval",
107// "attrs": [
108// {
109// "key": "token",
110// "value": "gno.land/r/demo/grc20identity.DUP.0000001"
111// },
112// {
113// "key": "owner",
114// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
115// },
116// {
117// "key": "spender",
118// "value": "g148tp8xkvvk3l73lmxywpdlsxgdujjlclx7wfyg"
119// },
120// {
121// "key": "value",
122// "value": "1"
123// }
124// ],
125// "pkg_path": "gno.land/p/demo/tokens/grc20"
126// },
127// {
128// "type": "Transfer",
129// "attrs": [
130// {
131// "key": "token",
132// "value": "gno.land/r/demo/grc20identity.DUP.0000002"
133// },
134// {
135// "key": "from",
136// "value": ""
137// },
138// {
139// "key": "to",
140// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
141// },
142// {
143// "key": "value",
144// "value": "2"
145// }
146// ],
147// "pkg_path": "gno.land/p/demo/tokens/grc20"
148// },
149// {
150// "type": "Approval",
151// "attrs": [
152// {
153// "key": "token",
154// "value": "gno.land/r/demo/grc20identity.DUP.0000002"
155// },
156// {
157// "key": "owner",
158// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
159// },
160// {
161// "key": "spender",
162// "value": "g148tp8xkvvk3l73lmxywpdlsxgdujjlclx7wfyg"
163// },
164// {
165// "key": "value",
166// "value": "2"
167// }
168// ],
169// "pkg_path": "gno.land/p/demo/tokens/grc20"
170// }
171// ]