Kind Realm (renderable)
Name abt
Namespace akkadia / beta
Exported functions 13
Module gno.land/r/akkadia/beta/abt
gno 0.9 This realm implements a recognized token. abt → abt_test.gno gno
⧉
1 package abt 2 3 import ( 4 "math" 5 "testing" 6 7 "gno.land/p/nt/uassert/v0" 8 Allowance (owner string, spender string) int64
Approve (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, spender string, amount int64)
BalanceOf (owner string) int64
GetDecimals () int
GetName () string
GetSymbol () string
IsFrozen () bool
Mint (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, to string, amount int64)
Render (path string) string
SetFrozen (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, value bool)
TotalSupply () int64
Transfer (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, to string, amount int64)
TransferFrom (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, from string, to string, amount int64)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.
"gno.land/r/akkadia/beta/admin"
9 )
10
11 func TestInitialState(t *testing.T) {
12 uassert.Equal(t, "Akkadia Beta Token" , GetName())
13 uassert.Equal(t, "abt" , GetSymbol())
14 uassert.Equal(t, 6 , GetDecimals())
15 uassert.Equal(t, "gno.land/r/akkadia/beta/abt.abt.0000000" , token.ID())
16 uassert.True(t, IsFrozen())
17 uassert.Equal(t, int64 ( 0 ), TotalSupply())
18 uassert.Equal(t, int64 ( 0 ), BalanceOf(abtTest.Owner))
19 uassert.Equal(t, int64 ( 0 ), Allowance(abtTest.Owner, abtTest.Other))
20 }
21
22 func TestMintWhileFrozen(cur realm, t *testing.T) {
23 setupABT(cross(cur), t)
24 for _, caller := range []address{abtTest.Admin, abtTest.Operator} {
25 testing.SetOriginCaller(caller)
26 testing.SetRealm(testing.NewUserRealm(caller))
27 Mint(cross(cur), abtTest.Owner, 100 )
28 Mint(cross(cur), abtTest.Other, 10 )
29 }
30 uassert.True(t, IsFrozen())
31 uassert.Equal(t, int64 ( 220 ), TotalSupply())
32 uassert.Equal(t, int64 ( 200 ), BalanceOf(abtTest.Owner))
33 uassert.Equal(t, int64 ( 20 ), BalanceOf(abtTest.Other))
34 uassert.Equal(t, int64 ( 0 ), Allowance(abtTest.Owner, abtTest.Other))
35 }
36
37 func TestMintInvalidInput(cur realm, t *testing.T) {
38 cases := [] struct {
39 name string
40 to address
41 amount int64
42 panicMsg string
43 }{
44 { "empty address" , address( "" ), 1 , "invalid abt recipient" },
45 { "invalid address" , address( "invalid" ), 1 , "invalid abt recipient" },
46 { "zero" , abtTest.Owner, 0 , "abt amount must be positive" },
47 { "negative" , abtTest.Owner, - 1 , "abt amount must be positive" },
48 { "minimum int64" , abtTest.Owner, math.MinInt64, "abt amount must be positive" },
49 }
50 for _, tc := range cases {
51 t.Run(tc.name, func (cur realm, t *testing.T) {
52 setupABT(cross(cur), t)
53 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
54 Mint(cross(cur), abtTest.Owner, 7 )
55 uassert.AbortsWithMessage(t, cur, tc.panicMsg, func () {
56 Mint(cross(cur), tc.to, tc.amount)
57 })
58 uassert.Equal(t, int64 ( 7 ), TotalSupply())
59 uassert.Equal(t, int64 ( 7 ), BalanceOf(abtTest.Owner))
60 uassert.Equal(t, int64 ( 0 ), BalanceOf(abtTest.Other))
61 })
62 }
63 }
64
65 func TestMintOverflow(cur realm, t *testing.T) {
66 setupABT(cross(cur), t)
67 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
68 Mint(cross(cur), abtTest.Owner, math.MaxInt64)
69 for _, to := range []address{abtTest.Owner, abtTest.Other} {
70 uassert.AbortsWithMessage(t, cur, "abt mint failed: mint overflow" , func () {
71 Mint(cross(cur), to, 1 )
72 })
73 }
74 uassert.Equal(t, int64 (math.MaxInt64), TotalSupply())
75 uassert.Equal(t, int64 (math.MaxInt64), BalanceOf(abtTest.Owner))
76 uassert.Equal(t, int64 ( 0 ), BalanceOf(abtTest.Other))
77 }
78
79 func TestFreezeLifecycle(cur realm, t *testing.T) {
80 setupABT(cross(cur), t)
81 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
82 Mint(cross(cur), abtTest.Owner, 100 )
83 SetFrozen(cross(cur), true )
84 SetFrozen(cross(cur), false )
85 SetFrozen(cross(cur), false )
86 Mint(cross(cur), abtTest.Owner, 5 )
87 testing.SetOriginCaller(abtTest.Owner)
88 testing.SetRealm(testing.NewUserRealm(abtTest.Owner))
89 Transfer(cross(cur), abtTest.Other, 10 )
90 Approve(cross(cur), abtTest.Other, 40 )
91 testing.SetOriginCaller(abtTest.Other)
92 testing.SetRealm(testing.NewUserRealm(abtTest.Other))
93 TransferFrom(cross(cur), abtTest.Owner, abtTest.Admin, 15 )
94 uassert.Equal(t, int64 ( 80 ), BalanceOf(abtTest.Owner))
95 uassert.Equal(t, int64 ( 10 ), BalanceOf(abtTest.Other))
96 uassert.Equal(t, int64 ( 15 ), BalanceOf(abtTest.Admin))
97 uassert.Equal(t, int64 ( 25 ), Allowance(abtTest.Owner, abtTest.Other))
98 testing.SetOriginCaller(abtTest.Admin)
99 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
100 SetFrozen(cross(cur), true )
101 testing.SetOriginCaller(abtTest.Owner)
102 testing.SetRealm(testing.NewUserRealm(abtTest.Owner))
103 uassert.AbortsWithMessage(t, cur, "abt is frozen" , func () { Approve(cross(cur), abtTest.Other, 0 ) })
104 uassert.AbortsWithMessage(t, cur, "abt is frozen" , func () { Transfer(cross(cur), abtTest.Other, 1 ) })
105 testing.SetOriginCaller(abtTest.Other)
106 testing.SetRealm(testing.NewUserRealm(abtTest.Other))
107 uassert.AbortsWithMessage(t, cur, "abt is frozen" , func () {
108 TransferFrom(cross(cur), abtTest.Owner, abtTest.Admin, 25 )
109 })
110 uassert.Equal(t, int64 ( 25 ), Allowance(abtTest.Owner, abtTest.Other))
111 uassert.Equal(t, int64 ( 80 ), BalanceOf(abtTest.Owner))
112 uassert.Equal(t, int64 ( 105 ), TotalSupply())
113 testing.SetOriginCaller(abtTest.Admin)
114 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
115 SetFrozen(cross(cur), false )
116 testing.SetOriginCaller(abtTest.Other)
117 testing.SetRealm(testing.NewUserRealm(abtTest.Other))
118 TransferFrom(cross(cur), abtTest.Owner, abtTest.Admin, 25 )
119 uassert.Equal(t, int64 ( 0 ), Allowance(abtTest.Owner, abtTest.Other))
120 uassert.Equal(t, int64 ( 55 ), BalanceOf(abtTest.Owner))
121 uassert.Equal(t, int64 ( 40 ), BalanceOf(abtTest.Admin))
122 uassert.Equal(t, int64 ( 105 ), TotalSupply())
123 testing.SetOriginCaller(abtTest.Owner)
124 testing.SetRealm(testing.NewUserRealm(abtTest.Owner))
125 Approve(cross(cur), abtTest.Other, 5 )
126 Approve(cross(cur), abtTest.Other, 7 )
127 uassert.Equal(t, int64 ( 7 ), Allowance(abtTest.Owner, abtTest.Other))
128 Approve(cross(cur), abtTest.Other, 0 )
129 uassert.Equal(t, int64 ( 0 ), Allowance(abtTest.Owner, abtTest.Other))
130 }
131
132 func TestMintRoleChanges(cur realm, t *testing.T) {
133 setupABT(cross(cur), t)
134 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
135 admin.UnsetOperator(cross(cur), abtTest.Operator)
136 testing.SetOriginCaller(abtTest.Operator)
137 testing.SetRealm(testing.NewUserRealm(abtTest.Operator))
138 uassert.AbortsWithMessage(t, cur, "admin or operator access required" , func () { Mint(cross(cur), abtTest.Owner, 1 ) })
139 testing.SetOriginCaller(abtTest.Admin)
140 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
141 admin.TransferAdmin(cross(cur), abtTest.Other)
142 testing.SetOriginCaller(abtTest.Other)
143 testing.SetRealm(testing.NewUserRealm(abtTest.Other))
144 admin.AcceptAdmin(cross(cur))
145 Mint(cross(cur), abtTest.Owner, 3 )
146 SetFrozen(cross(cur), false )
147 testing.SetOriginCaller(abtTest.Admin)
148 testing.SetRealm(testing.NewUserRealm(abtTest.Admin))
149 uassert.AbortsWithMessage(t, cur, "admin or operator access required" , func () { Mint(cross(cur), abtTest.Owner, 1 ) })
150 uassert.AbortsWithMessage(t, cur, "admin access required" , func () { SetFrozen(cross(cur), true ) })
151 uassert.Equal(t, int64 ( 3 ), TotalSupply())
152 uassert.False(t, IsFrozen())
153 }
154