Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

banker_coins_payment_copy_filetest.gno

1.45 Kb · 45 lines
 1// PKGPATH: gno.land/r/treasury/main
 2
 3package main
 4
 5import (
 6	"chain"
 7	"chain/banker"
 8	"testing"
 9
10	"gno.land/p/nt/treasury/v0"
11)
12
13// coins is this realm's own slice. It is handed to NewCoinsPayment and then
14// rewritten, which is what a realm supplying the coins for a governance
15// payment proposal can do between the vote and the execution.
16var coins = chain.Coins{chain.Coin{Denom: "ugnot", Amount: 10}}
17
18func main(cur realm) {
19	ownerAddr := chain.PackageAddress("gno.land/r/treasury/main")
20	destAddr := chain.PackageAddress("gno.land/r/dest/main")
21
22	banker_ := banker.NewBanker(banker.BankerTypeRealmSend, cur)
23	cbanker, err := treasury.NewCoinsBankerWithOwner(ownerAddr, banker_)
24	if err != nil {
25		panic("failed to create CoinsBanker: " + err.Error())
26	}
27	testing.IssueCoins(ownerAddr, chain.NewCoins(chain.NewCoin("ugnot", 1000)))
28
29	payment := treasury.NewCoinsPayment(coins, destAddr)
30	println("payment as created:", payment.String())
31
32	// The supplying realm rewrites its own array. The payment must not follow.
33	coins[0].Amount = 900
34	println("payment after the rewrite:", payment.String())
35
36	if err := cbanker.Send(0, cur, payment); err != nil {
37		panic("failed to send payment: " + err.Error())
38	}
39	println("owner balance after send:", cbanker.Balances()[0].Amount)
40}
41
42// Output:
43// payment as created: 10ugnot to g1fs92ep7z5vtrp26d767ag3zztsd6wqn9rew4ve
44// payment after the rewrite: 10ugnot to g1fs92ep7z5vtrp26d767ag3zztsd6wqn9rew4ve
45// owner balance after send: 990