z0_filetest.gno
1.97 Kb ยท 66 lines
1// PKGPATH: gno.land/r/demo/wugnot_test
2package wugnot_test
3
4import (
5 "fmt"
6 "std"
7 "testing"
8
9 "gno.land/p/demo/testutils"
10 "gno.land/r/demo/wugnot"
11)
12
13var (
14 addr1 = testutils.TestAddress("test1")
15 addrc = std.DerivePkgAddr("gno.land/r/demo/wugnot")
16)
17
18func main() {
19 // issue ugnots
20 testing.IssueCoins(addr1, std.Coins{{"ugnot", 100000001}})
21 printBalances()
22 // println(wugnot.Render("queues"))
23 // println("A -", wugnot.Render(""))
24
25 // deposit of 123400ugnot from addr1
26 // origin send must be simulated
27 coins := std.Coins{{"ugnot", 123_400}}
28 testing.SetOriginCaller(addr1)
29 testing.SetOriginSend(coins)
30 std.NewBanker(std.BankerTypeRealmSend).SendCoins(addr1, addrc, coins)
31 wugnot.Deposit(cross)
32 printBalances()
33
34 // withdraw of 4242ugnot to addr1
35 wugnot.Withdraw(cross, 4242)
36 printBalances()
37}
38
39func printBalances() {
40 printSingleBalance := func(name string, addr std.Address) {
41 wugnotBal := wugnot.BalanceOf(addr)
42 testing.SetOriginCaller(addr)
43 robanker := std.NewBanker(std.BankerTypeReadonly)
44 coins := robanker.GetCoins(addr).AmountOf("ugnot")
45 fmt.Printf("| %-13s | addr=%s | wugnot=%-6d | ugnot=%-9d |\n",
46 name, addr, wugnotBal, coins)
47 }
48 println("-----------")
49 printSingleBalance("wugnot", addrc)
50 printSingleBalance("addr1", addr1)
51 println("-----------")
52}
53
54// Output:
55// -----------
56// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=0 |
57// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0 | ugnot=100000001 |
58// -----------
59// -----------
60// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=123400 |
61// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=123400 | ugnot=99876601 |
62// -----------
63// -----------
64// | wugnot | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0 | ugnot=119158 |
65// | addr1 | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=119158 | ugnot=99880843 |
66// -----------