Playground
gnomod.toml
module = "gno.land/r/nym-moultest123/x/framelab/probe/v0" gno = "0.9" private = true [addpkg] creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv" height = 186411 max_deposit = "5000000ugnot"
probe.gno
// Realm probe is shaped exactly like a generated instance realm: it owns the
// state, and every exported function is a one-line re-export that forwards
// `cur` into the shared pure package.
package probe
import (
"gno.land/p/nym-moultest123/x/framelab/v0"
"gno.land/p/nt/grc20/v0"
)
var (
Token *grc20.Token
ledger *grc20.PrivateLedger
)
func init(cur realm) {
Token, ledger = grc20.NewToken("Probe", "PRB", 6, 0, cur)
}
// Run is the instance-realm shape under test.
func Run(cur realm, from address, amount int64) address {
return framelab.Pull(0, cur, Token, from, amount)
}
// Frame reports what pure-package code sees as its own realm identity.
func Frame(cur realm) (string, address, bool) { return framelab.Who(0, cur) }
probe_test.gno
package probe
import (
"chain"
"testing"
"gno.land/p/nt/testutils/v0"
"gno.land/p/nt/uassert/v0"
)
const selfPath = "gno.land/r/nym-moultest123/x/framelab/probe/v0"
func self() address { return chain.PackageAddress(selfPath) }
// The claim: pure-package code called with a forwarded `cur` still runs in the
// importing realm's frame, so it reports that realm's path and address and its
// `cur` is still accepted as current by grc20's spoof check.
func TestPureCodeKeepsImportingRealmFrame(cur realm, t *testing.T) {
alice := testutils.TestAddress("alice")
testing.SetRealm(testing.NewUserRealm(alice))
path, addr, isCurrent := Frame(cross(cur))
uassert.Equal(t, selfPath, path)
uassert.Equal(t, self().String(), addr.String())
uassert.True(t, isCurrent)
}
// The same claim, exercised through the operation that actually matters: a
// GRC20 pull issued from inside the pure package must credit the instance
// realm's own address.
func TestPureCodePullsToImportingRealm(cur realm, t *testing.T) {
alice := testutils.TestAddress("alice")
ledger.Mint(alice, 1_000)
ledger.Approve(alice, self(), 500)
testing.SetRealm(testing.NewUserRealm(alice))
bound := Run(cross(cur), alice, 400)
uassert.Equal(t, self().String(), bound.String())
uassert.Equal(t, int64(400), Token.BalanceOf(self()))
uassert.Equal(t, int64(600), Token.BalanceOf(alice))
uassert.Equal(t, int64(100), Token.Allowance(alice, self()))
}