1package escrow23import (4 "strings"5 "testing"67 "gno.land/p/nt/avl/v0"8 "gno.land/p/nt/testutils/v0"9 "gno.land/p/nt/uassert/v0"10)1112var (13 alice = testutils.TestAddress("alice")14 bob = testutils.TestAddress("bob")15 carol = testutils.TestAddress("carol")16)1718func resetState() {19 deals = avl.NewTree()20 nextID = 021}2223func TestCreateAndConfirmSettles(cur realm, t *testing.T) {24 resetState()2526 // Alice creates a deal with Bob.27 testing.SetRealm(testing.NewUserRealm(alice))28 id := Create(cross(cur), bob, "swap NFT for 100 GNOT")29 uassert.Equal(t, 0, id)3031 // Alice confirms (1/2, still open).32 Confirm(cross(cur), id)33 out := Render("0")34 uassert.True(t, strings.Contains(out, "State:** Open"), "expected still open after one confirm")3536 // Bob confirms -> settles.37 testing.SetRealm(testing.NewUserRealm(bob))38 Confirm(cross(cur), id)3940 out = Render("0")41 uassert.True(t, strings.Contains(out, "Settled"), "expected Settled state")42 uassert.True(t, strings.Contains(out, "swap NFT for 100 GNOT"), "expected terms")43}4445func TestCancelByCreator(cur realm, t *testing.T) {46 resetState()4748 testing.SetRealm(testing.NewUserRealm(alice))49 id := Create(cross(cur), bob, "rent payment")5051 Cancel(cross(cur), id)5253 out := Render("")54 uassert.True(t, strings.Contains(out, "Canceled"), "expected Canceled state")55}5657func TestNonPartyCannotConfirm(cur realm, t *testing.T) {58 resetState()5960 testing.SetRealm(testing.NewUserRealm(alice))61 id := Create(cross(cur), bob, "consulting")6263 // Carol is not a party.64 testing.SetRealm(testing.NewUserRealm(carol))65 uassert.AbortsWithMessage(t, cur, "escrow: caller is not a party to this deal", func() {66 Confirm(cross(cur), id)67 })68}6970func TestOnlyCreatorCancels(cur realm, t *testing.T) {71 resetState()7273 testing.SetRealm(testing.NewUserRealm(alice))74 id := Create(cross(cur), bob, "loan")7576 testing.SetRealm(testing.NewUserRealm(bob))77 uassert.AbortsWithMessage(t, cur, "escrow: only the creator can cancel", func() {78 Cancel(cross(cur), id)79 })80}81Cancel(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id int)
Confirm(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id int)
Create(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, counterparty string, terms string) int
Render(path string) string
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.