Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

cointest.gno

1.87 Kb · 58 lines
 1// Realm cointest is a throwaway deployment-validation helper for the
 2// vault realm. It creates the two out-of-band conditions the vault's
 3// surplus machinery must handle — a direct bank send of ugnot and a
 4// foreign denomination — and exercises the vault's realm-caller
 5// rejection. Not part of the product; safe to abandon after validation.
 6package cointest
 7
 8import (
 9	"chain"
10	"chain/banker"
11	"chain/runtime/unsafe"
12
13	vault "gno.land/r/g1ut6uspuh73e02yauxpmyt8g3wwddaq8utagvm3/vault"
14)
15
16var issued string // chain-qualified denom minted by MintAndSend
17
18// ForwardUgnot forwards the ugnot attached to this call to target via a
19// plain bank send — out-of-band relative to target's own deposit flow.
20func ForwardUgnot(cur realm, target address) {
21	if !cur.Previous().IsUserCall() {
22		panic("EOA only")
23	}
24	sent := unsafe.OriginSend()
25	if len(sent) == 0 {
26		panic("attach coins to forward")
27	}
28	bk := banker.NewBanker(banker.BankerTypeRealmSend, cur)
29	bk.SendCoins(cur.Address(), target, sent)
30}
31
32// MintAndSend issues amount of this realm's own denomination and
33// force-sends it to target, recording the chain-qualified denom.
34func MintAndSend(cur realm, target address, amount int64) {
35	if amount <= 0 {
36		panic("amount must be positive")
37	}
38	bk := banker.NewBanker(banker.BankerTypeRealmIssue, cur)
39	bk.IssueCoin(cur.Address(), "junk", amount)
40	for _, c := range bk.GetCoins(cur.Address()) {
41		if c.Denom != "ugnot" {
42			issued = c.Denom
43			bk.SendCoins(cur.Address(), target, chain.Coins{c})
44			return
45		}
46	}
47	panic("no issued denom found")
48}
49
50// Issued returns the denom minted by MintAndSend.
51func Issued() string { return issued }
52
53// TryDeposit attempts a realm-to-realm call of vault.Deposit. The vault
54// must reject it (IsUserCall guard), aborting this whole transaction —
55// success of this function would be a security regression.
56func TryDeposit(cur realm) {
57	vault.Deposit(cross(cur))
58}