Search Apps Documentation Source Content File Folder Download Copy Actions Download

z0_filetest.gno

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