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

z_treasury_payment_request_test.gno

1.93 Kb · 50 lines
 1package impl
 2
 3import (
 4	"testing"
 5
 6	trs_pkg "gno.land/p/nt/treasury/v0"
 7	"gno.land/p/nt/urequire/v0"
 8)
 9
10// Named z_* for the same reason as z_upgrade_request_test.gno: govdao_test.gno
11// asserts hard-coded proposal ids, and this test creates no proposal.
12
13// foreignPayment satisfies trs_pkg.Payment without being one of treasury's own
14// impls. BankerID names a banker the treasury really has registered, and
15// String says whatever this realm likes.
16type foreignPayment struct{}
17
18func (foreignPayment) BankerID() string { return "Coins" }
19
20func (foreignPayment) String() string { return "42ugnot to g1nobody" }
21
22// The immutability NewCoinsPayment provides is a property of the concrete
23// type, not of the Payment interface: a foreign impl renders a payment line
24// members vote on and then fails CoinsBanker.Send's type assertion at
25// execution, spending a whole vote cycle on a proposal that can never
26// execute. Rejected at construction so the proposer sees it, not the voters.
27func TestTreasuryPaymentRequestRejectsForeignPayment(cur realm, t *testing.T) {
28	testing.SetOriginCaller(m1)
29	testing.SetRealm(testing.NewUserRealm(m1))
30
31	// PanicsWithMessage, not AbortsWithMessage: same-realm call, so the guard
32	// raises a plain panic rather than a cross-realm abort.
33	urequire.PanicsWithMessage(t, cur,
34		"payment must be built by treasury.NewCoinsPayment or treasury.NewGRC20Payment",
35		func() {
36			NewTreasuryPaymentRequest(cur, foreignPayment{}, "a reason")
37		})
38}
39
40// The check must not reject the real thing. GRC20 is used here because the
41// Coins banker is the one govdao_test.gno's shared state leaves funded; both
42// are canonical, and only the canonicality gate is under test.
43func TestTreasuryPaymentRequestAcceptsCanonicalPayment(cur realm, t *testing.T) {
44	testing.SetOriginCaller(m1)
45	testing.SetRealm(testing.NewUserRealm(m1))
46
47	urequire.NotPanics(t, cur, func() {
48		NewTreasuryPaymentRequest(cur, trs_pkg.NewGRC20Payment("TOK", 1, m1), "a reason")
49	})
50}