Search Apps Documentation Source Content File Folder Download Copy

z_0_filetest.gno

1.45 Kb ยท 53 lines
 1// Empty line between the directives is important for them to be parsed
 2// independently. :facepalm:
 3
 4// PKGPATH: gno.land/r/demo/bank1
 5
 6// SEND: 100000000ugnot
 7
 8package bank1
 9
10import (
11	"std"
12
13	"gno.land/r/demo/banktest"
14)
15
16func main() {
17	// set up main address and banktest addr.
18	banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest")
19	mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1")
20	std.TestSetOrigCaller(mainaddr)
21	std.TestSetOrigPkgAddr(banktestAddr)
22
23	// get and print balance of mainaddr.
24	// with the SEND, + 200 gnot given by the TestContext, main should have 300gnot.
25	banker := std.GetBanker(std.BankerTypeRealmSend)
26	mainbal := banker.GetCoins(mainaddr)
27	println("main before:", mainbal)
28
29	// simulate a Deposit call. use Send + OrigSend to simulate -send.
30	banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}})
31	std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil)
32	res := banktest.Deposit("ugnot", 50_000_000)
33	println("Deposit():", res)
34
35	// print main balance after.
36	mainbal = banker.GetCoins(mainaddr)
37	println("main after:", mainbal)
38
39	// simulate a Render(). banker should have given back all coins.
40	res = banktest.Render("")
41	println(res)
42}
43
44// Output:
45// main before: 100000000ugnot
46// Deposit(): returned!
47// main after: 50000000ugnot
48// ## recent activity
49//
50//  * g1tnpdmvrmtgql8fmxgsq9rwtst5hsxahk3f05dk 100000000ugnot sent, 50000000ugnot returned, at 2009-02-13 11:31pm UTC
51//
52// ## total deposits
53// 50000000ugnot