token_identity_filetest.gno
2.88 Kb · 127 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": "Transfer",
41// "attrs": [
42// {
43// "key": "token",
44// "value": "gno.land/r/demo/grc20identity.DUP.0000001"
45// },
46// {
47// "key": "from",
48// "value": ""
49// },
50// {
51// "key": "to",
52// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
53// },
54// {
55// "key": "value",
56// "value": "1"
57// }
58// ],
59// "pkg_path": "gno.land/p/demo/tokens/grc20"
60// },
61// {
62// "type": "Approval",
63// "attrs": [
64// {
65// "key": "token",
66// "value": "gno.land/r/demo/grc20identity.DUP.0000001"
67// },
68// {
69// "key": "owner",
70// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
71// },
72// {
73// "key": "spender",
74// "value": "g148tp8xkvvk3l73lmxywpdlsxgdujjlclx7wfyg"
75// },
76// {
77// "key": "value",
78// "value": "1"
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.0000002"
89// },
90// {
91// "key": "from",
92// "value": ""
93// },
94// {
95// "key": "to",
96// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
97// },
98// {
99// "key": "value",
100// "value": "2"
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.0000002"
111// },
112// {
113// "key": "owner",
114// "value": "g18rwjsdf0kcy673ta0q4ujwvsncz4k2a8gcv94t"
115// },
116// {
117// "key": "spender",
118// "value": "g148tp8xkvvk3l73lmxywpdlsxgdujjlclx7wfyg"
119// },
120// {
121// "key": "value",
122// "value": "2"
123// }
124// ],
125// "pkg_path": "gno.land/p/demo/tokens/grc20"
126// }
127// ]