z_0_filetest.gno

1.49 Kb ยท 54 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	"testing"
13
14	"gno.land/r/demo/banktest"
15)
16
17func main() {
18	// set up main address and banktest addr.
19	banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest")
20	mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1")
21	testing.SetOriginCaller(mainaddr)
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.NewBanker(std.BankerTypeRealmSend)
26	mainbal := banker.GetCoins(mainaddr)
27	println("main before:", mainbal)
28
29	// simulate a Deposit call. use Send + OriginSend to simulate -send.
30	banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}})
31	testing.SetOriginSend(std.Coins{{"ugnot", 100_000_000}})
32	testing.SetRealm(std.NewCodeRealm("gno.land/r/demo/banktest"))
33	res := banktest.Deposit("ugnot", 50_000_000)
34	println("Deposit():", res)
35
36	// print main balance after.
37	mainbal = banker.GetCoins(mainaddr)
38	println("main after:", mainbal)
39
40	// simulate a Render(). banker should have given back all coins.
41	res = banktest.Render("")
42	println(res)
43}
44
45// Output:
46// main before: 100000000ugnot
47// Deposit(): returned!
48// main after: 50000000ugnot
49// ## recent activity
50//
51//  * g1tnpdmvrmtgql8fmxgsq9rwtst5hsxahk3f05dk 100000000ugnot sent, 50000000ugnot returned, at 2009-02-13 11:31pm UTC
52//
53// ## total deposits
54// 50000000ugnot