Skip to content

Commit

Permalink
TestSetPrevRealm/TestSetPrevAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Mar 15, 2024
1 parent 01e91be commit 0453cf8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
40 changes: 40 additions & 0 deletions gnovm/tests/stdlibs/native.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gnovm/tests/stdlibs/std/std.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ func TestCurrentRealm() string // injected
func TestSkipHeights(count int64) // injected
func ClearStoreCache() // injected
func GetCallerAt(n int) Address // injected
func TestSetPrevRealm(pkgPath string) // injected
func TestSetPrevAddr(addr Address) // injected
func TestSetOrigCaller(addr Address) // injected
func TestSetOrigPkgAddr(addr Address) // injected
func TestSetOrigSend(sent, spent Coins) // injected
Expand Down
15 changes: 15 additions & 0 deletions gnovm/tests/stdlibs/std/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ func GetCallerAt(m *gno.Machine, n int) crypto.Bech32Address {
return m.LastCallFrame(n).LastPackage.GetPkgAddr().Bech32()
}

func TestSetPrevRealm(m *gno.Machine, pkgPath string) {
m.Frames[m.NumFrames()-1].LastPackage = &gno.PackageValue{
PkgPath: pkgPath,
}
}

func TestSetPrevAddr(m *gno.Machine, addr crypto.Bech32Address) {
// clear prev realm in stack frame just in case
m.Frames[m.NumFrames()-1].LastPackage = nil

ctx := m.Context.(stdlibs.ExecContext)
ctx.OrigCaller = addr
m.Context = ctx
}

func TestSetOrigCaller(m *gno.Machine, addr crypto.Bech32Address) {
ctx := m.Context.(std.ExecContext)
ctx.OrigCaller = addr
Expand Down

0 comments on commit 0453cf8

Please sign in to comment.