probe_test.gno
1.39 Kb · 43 lines
1package probe
2
3import (
4 "chain"
5 "testing"
6
7 "gno.land/p/nt/testutils/v0"
8 "gno.land/p/nt/uassert/v0"
9)
10
11const selfPath = "gno.land/r/moul/x/framelab/probe/v0"
12
13func self() address { return chain.PackageAddress(selfPath) }
14
15// The claim: pure-package code called with a forwarded `cur` still runs in the
16// importing realm's frame, so it reports that realm's path and address and its
17// `cur` is still accepted as current by grc20's spoof check.
18func TestPureCodeKeepsImportingRealmFrame(cur realm, t *testing.T) {
19 alice := testutils.TestAddress("alice")
20 testing.SetRealm(testing.NewUserRealm(alice))
21
22 path, addr, isCurrent := Frame(cross(cur))
23 uassert.Equal(t, selfPath, path)
24 uassert.Equal(t, self().String(), addr.String())
25 uassert.True(t, isCurrent)
26}
27
28// The same claim, exercised through the operation that actually matters: a
29// GRC20 pull issued from inside the pure package must credit the instance
30// realm's own address.
31func TestPureCodePullsToImportingRealm(cur realm, t *testing.T) {
32 alice := testutils.TestAddress("alice")
33 ledger.Mint(alice, 1_000)
34 ledger.Approve(alice, self(), 500)
35
36 testing.SetRealm(testing.NewUserRealm(alice))
37 bound := Run(cross(cur), alice, 400)
38
39 uassert.Equal(t, self().String(), bound.String())
40 uassert.Equal(t, int64(400), Token.BalanceOf(self()))
41 uassert.Equal(t, int64(600), Token.BalanceOf(alice))
42 uassert.Equal(t, int64(100), Token.Allowance(alice, self()))
43}