From dde31f6a9884638cc4a0145cab7d36d49d1f65e3 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Sun, 18 Feb 2024 18:51:54 +0100 Subject: [PATCH 1/9] feat: make `AssertOriginCall` always panic with `MsgRun` Fix #1663 `AssertOriginCall` used to panic on `MsgRun` because it involves more than 2 frames. But we want to reinforce that property, with an additional check. Added an improved version of the unit and txtar tests from #1048. In particular, the txtar adds 2 more cases : 19) MsgCall invokes std.AssertOriginCall directly: pass 20) MsgRun invokes std.AssertOriginCall directly: PANIC Note that 19) involves a change in the AssertOriginCall algorithm, because in that situation there's only a single frame. Even if there's no reason to call `std.AssertOriginCall()` directly from the command line, I think it's logic to make it pass, because that's a origin call. --- .../r/demo/tests/subtests/subtests.gno | 8 + examples/gno.land/r/demo/tests/tests.gno | 12 +- examples/gno.land/r/demo/tests/tests_test.gno | 36 ++- .../gnoland/testdata/assertorigincall.txtar | 254 ++++++++++++++++++ gnovm/stdlibs/std/native.gno | 12 +- gnovm/stdlibs/std/native.go | 8 +- gnovm/stdlibs/std/native_test.go | 215 +++++++++++++++ 7 files changed, 528 insertions(+), 17 deletions(-) create mode 100644 gno.land/cmd/gnoland/testdata/assertorigincall.txtar create mode 100644 gnovm/stdlibs/std/native_test.go diff --git a/examples/gno.land/r/demo/tests/subtests/subtests.gno b/examples/gno.land/r/demo/tests/subtests/subtests.gno index e8796a73081..5cc4d1bea16 100644 --- a/examples/gno.land/r/demo/tests/subtests/subtests.gno +++ b/examples/gno.land/r/demo/tests/subtests/subtests.gno @@ -15,3 +15,11 @@ func GetPrevRealm() std.Realm { func Exec(fn func()) { fn() } + +func AssertOriginCall() { + std.AssertOriginCall() +} + +func IsOriginCall() bool { + return std.IsOriginCall() +} diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index 0094ad2ae35..34a564e17b3 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -20,14 +20,22 @@ func CurrentRealmPath() string { return std.CurrentRealmPath() } -func AssertOriginCall() { +func CallAssertOriginCall() { std.AssertOriginCall() } -func IsOriginCall() bool { +func CallIsOriginCall() bool { return std.IsOriginCall() } +func CallSubtestsAssertOriginCall() { + rsubtests.AssertOriginCall() +} + +func CallSubtestsIsOriginCall() bool { + return rsubtests.IsOriginCall() +} + //---------------------------------------- // Test structure to ensure cross-realm modification is prevented. diff --git a/examples/gno.land/r/demo/tests/tests_test.gno b/examples/gno.land/r/demo/tests/tests_test.gno index 3dcbeecf18c..41d89526a4b 100644 --- a/examples/gno.land/r/demo/tests/tests_test.gno +++ b/examples/gno.land/r/demo/tests/tests_test.gno @@ -8,28 +8,40 @@ import ( ) func TestAssertOriginCall(t *testing.T) { - // No-panic case - AssertOriginCall() - if !IsOriginCall() { + // CallAssertOriginCall(): no panic + CallAssertOriginCall() + if !CallIsOriginCall() { t.Errorf("expected IsOriginCall=true but got false") } - // Panic case + // CallAssertOriginCall() from a block: panic expectedReason := "invalid non-origin call" + func() { + defer func() { + r := recover() + if r == nil || r.(string) != expectedReason { + t.Errorf("expected panic with '%v', got '%v'", expectedReason, r) + } + }() + // if called inside a function literal, this is no longer an origin call + // because there's one additional frame (the function literal block). + if CallIsOriginCall() { + t.Errorf("expected IsOriginCall=false but got true") + } + CallAssertOriginCall() + }() + + // CallSubtestsAssertOriginCall(): panic defer func() { r := recover() if r == nil || r.(string) != expectedReason { t.Errorf("expected panic with '%v', got '%v'", expectedReason, r) } }() - func() { - // if called inside a function literal, this is no longer an origin call - // because there's one additional frame (the function literal). - if IsOriginCall() { - t.Errorf("expected IsOriginCall=false but got true") - } - AssertOriginCall() - }() + if CallSubtestsIsOriginCall() { + t.Errorf("expected IsOriginCall=false but got true") + } + CallSubtestsAssertOriginCall() } func TestPrevRealm(t *testing.T) { diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar new file mode 100644 index 00000000000..832724eea20 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -0,0 +1,254 @@ +# This test ensures the consistency of the std.AssertOriginCall function, in +# the following situations: +# +# | Num | Msg Type | Call from | Entry Point | Result | +# |-----|:--------:|:-------------------:|:----------------------:|:------:| +# | 1 | MsgCall | wallet direct | myrealm.A() | PANIC | +# | 2 | | | myrealm.B() | pass | +# | 3 | | | myrealm.C() | pass | +# | 4 | | through /r/foo | myrealm.A() | PANIC | +# | 5 | | | myrealm.B() | pass | +# | 6 | | | myrealm.C() | PANIC | +# | 7 | | through /p/demo/bar | myrealm.A() | PANIC | +# | 8 | | | myrealm.B() | pass | +# | 9 | | | myrealm.C() | PANIC | +# | 10 | MsgRun | wallet direct | myrealm.A() | PANIC | +# | 11 | | | myrealm.B() | pass | +# | 12 | | | myrealm.C() | PANIC | +# | 13 | | through /r/foo | myrealm.A() | PANIC | +# | 14 | | | myrealm.B() | pass | +# | 15 | | | myrealm.C() | PANIC | +# | 16 | | through /p/demo/bar | myrealm.A() | PANIC | +# | 17 | | | myrealm.B() | pass | +# | 18 | | | myrealm.C() | PANIC | +# | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | +# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | + +# Init +## start a new node +gnoland start + +## deploy myrlm +gnokey maketx addpkg -pkgdir $WORK/r/myrlm -pkgpath gno.land/r/myrlm -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout 'OK!' + +## deploy r/foo +gnokey maketx addpkg -pkgdir $WORK/r/foo -pkgpath gno.land/r/foo -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout 'OK!' + +## deploy p/demo/bar +gnokey maketx addpkg -pkgdir $WORK/p/demo/bar -pkgpath gno.land/p/demo/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout 'OK!' + +# Test cases +## 1. MsgCall -> myrlm.A: PANIC +! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' + +## 2. MsgCall -> myrlm.B: PASS +gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' + +## 3. MsgCall -> myrlm.C: PASS +gnokey maketx call -pkgpath gno.land/r/myrlm -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' + +## 4. MsgCall -> r/foo.A -> myrlm.A: PANIC +! gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' + +## 5. MsgCall -> r/foo.B -> myrlm.B: PASS +gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' + +## 6. MsgCall -> r/foo.C -> myrlm.C: PANIC +! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' + +## 7. MsgCall -> p/demo/bar.A -> myrlm.A: PANIC +! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' + +## 8. MsgCall -> p/demo/bar.B -> myrlm.B: PASS +gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' + +## 9. MsgCall -> p/demo/bar.C -> myrlm.C: PANIC +! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stderr 'invalid non-origin call' + +## 10. MsgRun -> run.main -> myrlm.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +stderr 'invalid non-origin call' + +## 11. MsgRun -> run.main -> myrlm.B: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno +stdout 'OK!' + +## 12. MsgRun -> run.main -> myrlm.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno +stderr 'invalid non-origin call' + +## 13. MsgRun -> run.main -> foo.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno +stderr 'invalid non-origin call' + +## 14. MsgRun -> run.main -> foo.B: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno +stdout 'OK!' + +## 15. MsgRun -> run.main -> foo.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno +stderr 'invalid non-origin call' + +## 16. MsgRun -> run.main -> bar.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +stderr 'invalid non-origin call' + +## 17. MsgRun -> run.main -> bar.B: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno +stdout 'OK!' + +## 18. MsgRun -> run.main -> bar.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +stderr 'invalid non-origin call' + +## 19. MsgCall -> std.AssertOriginCall: pass +gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +stdout 'OK!' + +## 20. MsgRun -> std.AssertOriginCall: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno +stderr 'invalid non-origin call' + + +-- r/myrlm/rlm.gno -- +package myrlm + +import "std" + +func A() { + C() +} + +func B() { + if false { + C() + } +} + +func C() { + std.AssertOriginCall() +} +-- r/foo/foo.gno -- +package foo + +import "gno.land/r/myrlm" + +func A() { + myrlm.A() +} + +func B() { + myrlm.B() +} + +func C() { + myrlm.C() +} +-- p/demo/bar/bar.gno -- +package bar + +import "gno.land/r/myrlm" + +func A() { + myrlm.A() +} + +func B() { + myrlm.B() +} + +func C() { + myrlm.C() +} +-- run/myrlmA.gno -- +package main + +import myrlm "gno.land/r/myrlm" + +func main() { + myrlm.A() +} +-- run/myrlmB.gno -- +package main + +import "gno.land/r/myrlm" + +func main() { + myrlm.B() +} +-- run/myrlmC.gno -- +package main + +import "gno.land/r/myrlm" + +func main() { + myrlm.C() +} +-- run/fooA.gno -- +package main + +import "gno.land/r/foo" + +func main() { + foo.A() +} +-- run/fooB.gno -- +package main + +import "gno.land/r/foo" + +func main() { + foo.B() +} +-- run/fooC.gno -- +package main + +import "gno.land/r/foo" + +func main() { + foo.C() +} +-- run/barA.gno -- +package main + +import "gno.land/p/demo/bar" + +func main() { + bar.A() +} +-- run/barB.gno -- +package main + +import "gno.land/p/demo/bar" + +func main() { + bar.B() +} +-- run/barC.gno -- +package main + +import "gno.land/p/demo/bar" + +func main() { + bar.C() +} +-- run/baz.gno -- +package main + +import "std" + +func main() { + std.AssertOriginCall() +} diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 8043df49882..f3d134ee3f2 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -1,7 +1,15 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected +// AssertOriginCall panics is [IsOriginCall] return false. +func AssertOriginCall() // injected + +// IsOriginCall return true only if the calling method is invoked via a direct +// MsgCall. It returns false for all other cases, like if the calling method +// is invoked by an other method (even from the same realm or package). +// It also returns false every time when the transaction is broadcasted via +// MsgRun. +func IsOriginCall() bool // injected + func CurrentRealmPath() string // injected func GetChainID() string // injected func GetHeight() int64 // injected diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index 26bfe433858..74008cdabca 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -14,7 +14,13 @@ func AssertOriginCall(m *gno.Machine) { } func IsOriginCall(m *gno.Machine) bool { - return len(m.Frames) == 2 + n := m.NumFrames() + if n == 0 { + return false + } + firstPkg := m.Frames[0].LastPackage + isMsgCall := firstPkg != nil && firstPkg.PkgPath == "main" + return n <= 2 && isMsgCall } func CurrentRealmPath(m *gno.Machine) string { diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go new file mode 100644 index 00000000000..4a34559fbfb --- /dev/null +++ b/gnovm/stdlibs/std/native_test.go @@ -0,0 +1,215 @@ +package std + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + gno "github.com/gnolang/gno/gnovm/pkg/gnolang" +) + +func TestPrevRealmIsOrigin(t *testing.T) { + var ( + user = gno.DerivePkgAddr("user1.gno").Bech32() + ctx = ExecContext{ + OrigCaller: user, + } + msgCallFrame = gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "main"}} + msgRunFrame = gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/user-realm"}} + ) + tests := []struct { + name string + machine *gno.Machine + expectedRealm Realm + expectedIsOriginCall bool + }{ + { + name: "no frames", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{}, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one frame w/o LastPackage", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + {LastPackage: nil}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one package frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one realm frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one msgCall frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgCallFrame, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: true, + }, + { + name: "one msgRun frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgRunFrame, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one package frame and one msgCall frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgCallFrame, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: true, + }, + { + name: "one realm frame and one msgCall frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgCallFrame, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: true, + }, + { + name: "one package frame and one msgRun frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgRunFrame, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "one realm frame and one msgRun frame", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + msgRunFrame, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "multiple frames with one realm", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: user, + pkgPath: "", + }, + expectedIsOriginCall: false, + }, + { + name: "multiple frames with multiple realms", + machine: &gno.Machine{ + Context: ctx, + Frames: []gno.Frame{ + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/yyy"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/yyy"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, + {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, + }, + }, + expectedRealm: Realm{ + addr: gno.DerivePkgAddr("gno.land/r/yyy").Bech32(), + pkgPath: "gno.land/r/yyy", + }, + expectedIsOriginCall: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert := assert.New(t) + + realm := PrevRealm(tt.machine) + isOrigin := IsOriginCall(tt.machine) + + assert.Equal(tt.expectedRealm, realm) + assert.Equal(tt.expectedIsOriginCall, isOrigin) + }) + } +} From 8a195d691a18e1fdb750808e46856dfe649495c3 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Sun, 18 Feb 2024 20:27:06 +0100 Subject: [PATCH 2/9] fix tests --- .../gno.land/r/demo/tests/z0_filetest.gno | 28 +++++++++---------- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/gno.land/r/demo/tests/z0_filetest.gno b/examples/gno.land/r/demo/tests/z0_filetest.gno index c4beb8e2005..ff625d4906f 100644 --- a/examples/gno.land/r/demo/tests/z0_filetest.gno +++ b/examples/gno.land/r/demo/tests/z0_filetest.gno @@ -5,24 +5,24 @@ import ( ) func main() { - println("IsOriginCall:", tests.IsOriginCall()) - tests.AssertOriginCall() - println("AssertOriginCall doesn't panic when called directly") + println("tests.CallIsOriginCall:", tests.CallIsOriginCall()) + tests.CallAssertOriginCall() + println("tests.CallAssertOriginCall doesn't panic when called directly") - func() { - // if called inside a function literal, this is no longer an origin call - // because there's one additional frame (the function literal). - println("IsOriginCall:", tests.IsOriginCall()) + { + // if called inside a block, this is no longer an origin call because + // there's one additional frame (the block). + println("tests.CallIsOriginCall:", tests.CallIsOriginCall()) defer func() { r := recover() - println("AssertOriginCall panics if when called inside a function literal:", r) + println("tests.AssertOriginCall panics if when called inside a function literal:", r) }() - tests.AssertOriginCall() - }() + tests.CallAssertOriginCall() + } } // Output: -// IsOriginCall: true -// AssertOriginCall doesn't panic when called directly -// IsOriginCall: false -// AssertOriginCall panics if when called inside a function literal: invalid non-origin call +// tests.CallIsOriginCall: true +// tests.CallAssertOriginCall doesn't panic when called directly +// tests.CallIsOriginCall: true +// tests.AssertOriginCall panics if when called inside a function literal: undefined diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 0d614f5e8a1..cdfeb75eefe 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -154,7 +154,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "native.gno", -// "Line": "5", +// "Line": "13", // "Nonce": "0", // "PkgPath": "std" // } From b39f0c3fa9ce0f462815af2c14a3db522baa9cf7 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 27 Feb 2024 14:19:25 +0100 Subject: [PATCH 3/9] Update gnovm/stdlibs/std/native.gno Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- gnovm/stdlibs/std/native.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index f3d134ee3f2..aded9c7e0b6 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -1,6 +1,6 @@ package std -// AssertOriginCall panics is [IsOriginCall] return false. +// AssertOriginCall panics if [IsOriginCall] returns false. func AssertOriginCall() // injected // IsOriginCall return true only if the calling method is invoked via a direct From 1b2e20cd4cfc396d1b088f742e0bc677ca07023b Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 27 Feb 2024 14:19:34 +0100 Subject: [PATCH 4/9] Update gnovm/stdlibs/std/native.gno Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- gnovm/stdlibs/std/native.gno | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index aded9c7e0b6..4340f3bf9f7 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -3,9 +3,9 @@ package std // AssertOriginCall panics if [IsOriginCall] returns false. func AssertOriginCall() // injected -// IsOriginCall return true only if the calling method is invoked via a direct +// IsOriginCall returns true only if the calling method is invoked via a direct // MsgCall. It returns false for all other cases, like if the calling method -// is invoked by an other method (even from the same realm or package). +// is invoked by another method (even from the same realm or package). // It also returns false every time when the transaction is broadcasted via // MsgRun. func IsOriginCall() bool // injected From f4f867e0e15bc18183c3860803aa142aaf1bd807 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Mon, 22 Apr 2024 21:09:46 +0200 Subject: [PATCH 5/9] fix tests --- .../r/demo/tests/subtests/subtests.gno | 4 +- examples/gno.land/r/demo/tests/tests.gno | 4 +- gnovm/tests/files/zrealm_tests0.gno | 112 ++++++++++++++++-- 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/examples/gno.land/r/demo/tests/subtests/subtests.gno b/examples/gno.land/r/demo/tests/subtests/subtests.gno index 5cc4d1bea16..6bf43cba5eb 100644 --- a/examples/gno.land/r/demo/tests/subtests/subtests.gno +++ b/examples/gno.land/r/demo/tests/subtests/subtests.gno @@ -16,10 +16,10 @@ func Exec(fn func()) { fn() } -func AssertOriginCall() { +func CallAssertOriginCall() { std.AssertOriginCall() } -func IsOriginCall() bool { +func CallIsOriginCall() bool { return std.IsOriginCall() } diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index 34a564e17b3..f010facc31c 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -29,11 +29,11 @@ func CallIsOriginCall() bool { } func CallSubtestsAssertOriginCall() { - rsubtests.AssertOriginCall() + rsubtests.CallAssertOriginCall() } func CallSubtestsIsOriginCall() bool { - return rsubtests.IsOriginCall() + return rsubtests.CallIsOriginCall() } //---------------------------------------- diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 73d07f726eb..0037a29bb88 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -247,7 +247,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "42", +// "Line": "50", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -614,7 +614,7 @@ func main() { // }, // "FileName": "tests.gno", // "IsMethod": false, -// "Name": "AssertOriginCall", +// "Name": "CallAssertOriginCall", // "NativeName": "", // "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", @@ -660,7 +660,7 @@ func main() { // }, // "FileName": "tests.gno", // "IsMethod": false, -// "Name": "IsOriginCall", +// "Name": "CallIsOriginCall", // "NativeName": "", // "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", @@ -694,6 +694,98 @@ func main() { // { // "T": { // "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// }, +// "FileName": "tests.gno", +// "IsMethod": false, +// "Name": "CallSubtestsAssertOriginCall", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "tests.gno", +// "Line": "31", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// }, +// "FileName": "tests.gno", +// "IsMethod": false, +// "Name": "CallSubtestsIsOriginCall", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "tests.gno", +// "Line": "35", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", // "Params": [ // { // "Embedded": false, @@ -728,7 +820,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "38", +// "Line": "46", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -777,7 +869,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "60", +// "Line": "68", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -813,7 +905,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "65", +// "Line": "73", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -849,7 +941,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "73", +// "Line": "81", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -895,7 +987,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "77", +// "Line": "85", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -951,7 +1043,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "81", +// "Line": "89", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -1008,7 +1100,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "85", +// "Line": "93", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } From 88b4a27236919b9cba1e22113c57ef913d3da180 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 15 May 2024 15:09:44 +0200 Subject: [PATCH 6/9] fix conflicts --- examples/gno.land/r/demo/tests/tests.gno | 8 +-- gnovm/tests/files/zrealm_tests0.gno | 68 ++++-------------------- 2 files changed, 11 insertions(+), 65 deletions(-) diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index 15c6089d464..543a6001a01 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -20,19 +20,13 @@ func CurrentRealmPath() string { return std.CurrentRealmPath() } -<<<<<<< HEAD -func CallAssertOriginCall() { -||||||| 90f29c44 -func AssertOriginCall() { -======= var initOrigCaller = std.GetOrigCaller() func InitOrigCaller() std.Address { return initOrigCaller } -func AssertOriginCall() { ->>>>>>> master +func CallAssertOriginCall() { std.AssertOriginCall() } diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 78d661b5ef3..9542b5e8d1a 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -247,13 +247,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "50", -||||||| 90f29c44 -// "Line": "42", -======= -// "Line": "48", ->>>>>>> master +// "Line": "56", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -777,7 +771,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "31", +// "Line": "37", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -823,7 +817,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -// "Line": "35", +// "Line": "41", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -882,13 +876,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "46", -||||||| 90f29c44 -// "Line": "38", -======= -// "Line": "44", ->>>>>>> master +// "Line": "52", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -937,13 +925,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "68", -||||||| 90f29c44 -// "Line": "60", -======= -// "Line": "66", ->>>>>>> master +// "Line": "74", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -979,13 +961,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "73", -||||||| 90f29c44 -// "Line": "65", -======= -// "Line": "71", ->>>>>>> master +// "Line": "79", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -1021,13 +997,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "81", -||||||| 90f29c44 -// "Line": "73", -======= -// "Line": "79", ->>>>>>> master +// "Line": "87", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -1073,13 +1043,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "85", -||||||| 90f29c44 -// "Line": "77", -======= -// "Line": "83", ->>>>>>> master +// "Line": "91", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -1135,13 +1099,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "89", -||||||| 90f29c44 -// "Line": "81", -======= -// "Line": "87", ->>>>>>> master +// "Line": "95", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } @@ -1198,13 +1156,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "tests.gno", -<<<<<<< HEAD -// "Line": "93", -||||||| 90f29c44 -// "Line": "85", -======= -// "Line": "91", ->>>>>>> master +// "Line": "99", // "Nonce": "0", // "PkgPath": "gno.land/r/demo/tests" // } From 3e5839a9c66dc660a7cb06b2fa6f790b625b0018 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 15 May 2024 15:27:02 +0200 Subject: [PATCH 7/9] fix tests --- .../gnoland/testdata/assertorigincall.txtar | 2 +- gnovm/stdlibs/std/native_test.go | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index 832724eea20..b3f4b7d29d9 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -29,7 +29,7 @@ gnoland start ## deploy myrlm -gnokey maketx addpkg -pkgdir $WORK/r/myrlm -pkgpath gno.land/r/myrlm -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx addpkg -pkgdir $WORK/r/myrlm -pkgpath gno.land/r/myrlm -gas-fee 1000000ugnot -gas-wanted 2100000 -broadcast -chainid=tendermint_test test1 stdout 'OK!' ## deploy r/foo diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go index 4a34559fbfb..27cf0066811 100644 --- a/gnovm/stdlibs/std/native_test.go +++ b/gnovm/stdlibs/std/native_test.go @@ -14,8 +14,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { ctx = ExecContext{ OrigCaller: user, } - msgCallFrame = gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "main"}} - msgRunFrame = gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/user-realm"}} + msgCallFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "main"}} + msgRunFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/user-realm"}} ) tests := []struct { name string @@ -27,7 +27,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "no frames", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{}, + Frames: []*gno.Frame{}, }, expectedRealm: Realm{ addr: user, @@ -39,7 +39,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one frame w/o LastPackage", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ {LastPackage: nil}, }, }, @@ -53,7 +53,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one package frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, }, @@ -67,7 +67,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one realm frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, @@ -81,7 +81,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one msgCall frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgCallFrame, }, }, @@ -95,7 +95,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one msgRun frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgRunFrame, }, }, @@ -109,7 +109,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one package frame and one msgCall frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgCallFrame, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, @@ -124,7 +124,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one realm frame and one msgCall frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgCallFrame, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, @@ -139,7 +139,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one package frame and one msgRun frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgRunFrame, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, @@ -154,7 +154,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "one realm frame and one msgRun frame", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ msgRunFrame, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, @@ -169,7 +169,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "multiple frames with one realm", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, @@ -185,7 +185,7 @@ func TestPrevRealmIsOrigin(t *testing.T) { name: "multiple frames with multiple realms", machine: &gno.Machine{ Context: ctx, - Frames: []gno.Frame{ + Frames: []*gno.Frame{ {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/zzz"}}, {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/yyy"}}, From 33f691c3d17713da1fed2c5e91b4becaea2782b8 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Mon, 27 May 2024 22:32:35 +0200 Subject: [PATCH 8/9] use loadpkg --- .../cmd/gnoland/testdata/assertorigincall.txtar | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index b3f4b7d29d9..fdbfebeef4a 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -25,21 +25,12 @@ # | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | # Init -## start a new node +## set up and start a new node +loadpkg gno.land/r/myrlm $WORK/r/myrlm +loadpkg gno.land/r/foo $WORK/r/foo +loadpkg gno.land/p/demo/bar $WORK/p/demo/bar gnoland start -## deploy myrlm -gnokey maketx addpkg -pkgdir $WORK/r/myrlm -pkgpath gno.land/r/myrlm -gas-fee 1000000ugnot -gas-wanted 2100000 -broadcast -chainid=tendermint_test test1 -stdout 'OK!' - -## deploy r/foo -gnokey maketx addpkg -pkgdir $WORK/r/foo -pkgpath gno.land/r/foo -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stdout 'OK!' - -## deploy p/demo/bar -gnokey maketx addpkg -pkgdir $WORK/p/demo/bar -pkgpath gno.land/p/demo/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stdout 'OK!' - # Test cases ## 1. MsgCall -> myrlm.A: PANIC ! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 From 31a6ef4b3f769f643cf30595538af46fb477b404 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Mon, 27 May 2024 22:36:29 +0200 Subject: [PATCH 9/9] fix tests --- gnovm/stdlibs/std/native_test.go | 81 ++++++++++++-------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go index 27cf0066811..9af87174bda 100644 --- a/gnovm/stdlibs/std/native_test.go +++ b/gnovm/stdlibs/std/native_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/tm2/pkg/crypto" ) func TestPrevRealmIsOrigin(t *testing.T) { @@ -20,7 +21,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { tests := []struct { name string machine *gno.Machine - expectedRealm Realm + expectedAddr crypto.Bech32Address + expectedPkgPath string expectedIsOriginCall bool }{ { @@ -29,10 +31,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { Context: ctx, Frames: []*gno.Frame{}, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -43,10 +43,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: nil}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -57,10 +55,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -71,10 +67,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -85,10 +79,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { msgCallFrame, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: true, }, { @@ -99,10 +91,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { msgRunFrame, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -114,10 +104,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: true, }, { @@ -129,10 +117,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: true, }, { @@ -144,10 +130,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/p/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -159,10 +143,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -175,10 +157,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, - expectedRealm: Realm{ - addr: user, - pkgPath: "", - }, + expectedAddr: user, + expectedPkgPath: "", expectedIsOriginCall: false, }, { @@ -194,10 +174,8 @@ func TestPrevRealmIsOrigin(t *testing.T) { {LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/xxx"}}, }, }, - expectedRealm: Realm{ - addr: gno.DerivePkgAddr("gno.land/r/yyy").Bech32(), - pkgPath: "gno.land/r/yyy", - }, + expectedAddr: gno.DerivePkgAddr("gno.land/r/yyy").Bech32(), + expectedPkgPath: "gno.land/r/yyy", expectedIsOriginCall: false, }, } @@ -205,10 +183,11 @@ func TestPrevRealmIsOrigin(t *testing.T) { t.Run(tt.name, func(t *testing.T) { assert := assert.New(t) - realm := PrevRealm(tt.machine) + addr, pkgPath := X_getRealm(tt.machine, 1) isOrigin := IsOriginCall(tt.machine) - assert.Equal(tt.expectedRealm, realm) + assert.Equal(string(tt.expectedAddr), addr) + assert.Equal(tt.expectedPkgPath, pkgPath) assert.Equal(tt.expectedIsOriginCall, isOrigin) }) }