1// PKGPATH: gno.land/r/demo/wugnot_test
2package wugnot_test
3
4import (
5 "fmt"
6 "std"
7
8 "gno.land/p/demo/testutils"
9 "gno.land/r/demo/wugnot"
10
11 pusers "gno.land/p/demo/users"
12)
13
14var (
15 addr1 = testutils.TestAddress("test1")
16 addrc = std.DerivePkgAddr("gno.land/r/demo/wugnot")
17 addrt = std.DerivePkgAddr("gno.land/r/demo/wugnot_test")
18)
19
20func main() {
21 std.TestSetOrigPkgAddr(addrc)
22 std.TestIssueCoins(addrc, std.Coins{{"ugnot", 100000001}}) // TODO: remove this
23
24 // issue ugnots
25 std.TestIssueCoins(addr1, std.Coins{{"ugnot", 100000001}})
26
27 // print initial state
28 printBalances()
29 // println(wugnot.Render("queues"))
30 // println("A -", wugnot.Render(""))
31
32 std.TestSetOrigCaller(addr1)
33 std.TestSetOrigSend(std.Coins{{"ugnot", 123_400}}, nil)
34 wugnot.Deposit()
35 printBalances()
36 wugnot.Withdraw(4242)
37 printBalances()
38}
39
40func printBalances() {
41 printSingleBalance := func(name string, addr std.Address) {
42 wugnotBal := wugnot.BalanceOf(pusers.AddressOrName(addr))
43 std.TestSetOrigCaller(addr)
44 robanker := std.GetBanker(std.BankerTypeReadonly)
45 coins := robanker.GetCoins(addr).AmountOf("ugnot")
46 fmt.Printf("| %-13s | addr=%s | wugnot=%-5d | ugnot=%-9d |\n",
47 name, addr, wugnotBal, coins)
48 }
49 println("-----------")
50 printSingleBalance("wugnot_test", addrt)
51 printSingleBalance("wugnot", addrc)
52 printSingleBalance("addr1", addr1)
53 println("-----------")
54}
55
56// Output:
57// -----------
58// | wugnot_test | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=0 | ugnot=0 |
59// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=100000001 |
60// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0 | ugnot=100000001 |
61// -----------
62// -----------
63// | wugnot_test | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=123400 | ugnot=0 |
64// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=100000001 |
65// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0 | ugnot=100000001 |
66// -----------
67// -----------
68// | wugnot_test | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=119158 | ugnot=4242 |
69// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=99995759 |
70// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0 | ugnot=100000001 |
71// -----------
z0_filetest.gno
2.33 Kb ยท 71 lines