From f2fb5f7feccc5bf5573a8f81f18a0eda51dd9a8a Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 28 Oct 2024 21:51:49 +0100 Subject: [PATCH 01/48] fix: forbid importing realms from pure packages r/ from p/ --- gnovm/memfile.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index a37bba6ef3d..8e8d56eb820 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -2,6 +2,8 @@ package gnovm import ( "fmt" + "go/parser" + "go/token" "regexp" "sort" "strings" @@ -87,6 +89,26 @@ func (mempkg *MemPackage) Validate() error { prev = file.Name } + if strings.HasPrefix(mempkg.Path, "gno.land/p/") { + for _, file := range mempkg.Files { + // only check .gno files, can contains files like LICENSE or README that will cause parse error + if !strings.HasSuffix(file.Name, ".gno") { + continue + } + fset := token.NewFileSet() + astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) + if err != nil { + return fmt.Errorf("unable to parse %q", file.Name) + } + for _, imp := range astFile.Imports { + importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) + if strings.HasPrefix(importPath, "gno.land/r/") { + return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) + } + } + } + } + return nil } From 112daa1bb877b21b25811ea5ada1bec9ae871c50 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 28 Oct 2024 22:08:01 +0100 Subject: [PATCH 02/48] fix: handle different domain name --- gnovm/memfile.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index 8e8d56eb820..cbd756de3b3 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -89,7 +89,11 @@ func (mempkg *MemPackage) Validate() error { prev = file.Name } - if strings.HasPrefix(mempkg.Path, "gno.land/p/") { + if strings.Contains(mempkg.Path, "/p/") { + parts := strings.Split(mempkg.Path, "/") + if len(parts) < 3 || parts[1] != "p" { + return fmt.Errorf("invalid package path %q", mempkg.Path) + } for _, file := range mempkg.Files { // only check .gno files, can contains files like LICENSE or README that will cause parse error if !strings.HasSuffix(file.Name, ".gno") { @@ -102,9 +106,12 @@ func (mempkg *MemPackage) Validate() error { } for _, imp := range astFile.Imports { importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) - if strings.HasPrefix(importPath, "gno.land/r/") { + // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) + rIndex := strings.Index(importPath, "/r/") + if rIndex > 0 && strings.Count(importPath[:rIndex], "/") == 0 { return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) } + } } } From 144f4a2ebed2514b85149cf0b40ea14249191444 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 28 Oct 2024 22:19:28 +0100 Subject: [PATCH 03/48] fix: use index instead of splitting the path --- gnovm/memfile.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index cbd756de3b3..ca12a111004 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -90,9 +90,9 @@ func (mempkg *MemPackage) Validate() error { } if strings.Contains(mempkg.Path, "/p/") { - parts := strings.Split(mempkg.Path, "/") - if len(parts) < 3 || parts[1] != "p" { - return fmt.Errorf("invalid package path %q", mempkg.Path) + pIndex := strings.Index(mempkg.Path, "/p/") + if pIndex < 1 || strings.Count(mempkg.Path[:pIndex], "/") > 0 { + return fmt.Errorf("invalid pkg path %q", mempkg.Path) } for _, file := range mempkg.Files { // only check .gno files, can contains files like LICENSE or README that will cause parse error From 29d018ec759b5aa04851918f9e6f5ab6023e62be Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 28 Oct 2024 22:21:43 +0100 Subject: [PATCH 04/48] fix: remove redundant condition --- gnovm/memfile.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index ca12a111004..a622e9b72a9 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -89,11 +89,8 @@ func (mempkg *MemPackage) Validate() error { prev = file.Name } - if strings.Contains(mempkg.Path, "/p/") { - pIndex := strings.Index(mempkg.Path, "/p/") - if pIndex < 1 || strings.Count(mempkg.Path[:pIndex], "/") > 0 { - return fmt.Errorf("invalid pkg path %q", mempkg.Path) - } + pIndex := strings.Index(mempkg.Path, "/p/") + if pIndex > 0 && strings.Count(mempkg.Path[:pIndex], "/") > 0 { for _, file := range mempkg.Files { // only check .gno files, can contains files like LICENSE or README that will cause parse error if !strings.HasSuffix(file.Name, ".gno") { From 4b733e3c234be2ed2516371e4eb8e97118d697c3 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 28 Oct 2024 22:25:18 +0100 Subject: [PATCH 05/48] fix: check there is no slash before instead of looking for one --- gnovm/memfile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index a622e9b72a9..ef921455be9 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -90,7 +90,7 @@ func (mempkg *MemPackage) Validate() error { } pIndex := strings.Index(mempkg.Path, "/p/") - if pIndex > 0 && strings.Count(mempkg.Path[:pIndex], "/") > 0 { + if pIndex > 0 && strings.Count(mempkg.Path[:pIndex], "/") == 0 { for _, file := range mempkg.Files { // only check .gno files, can contains files like LICENSE or README that will cause parse error if !strings.HasSuffix(file.Name, ".gno") { @@ -102,8 +102,8 @@ func (mempkg *MemPackage) Validate() error { return fmt.Errorf("unable to parse %q", file.Name) } for _, imp := range astFile.Imports { - importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) + importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) rIndex := strings.Index(importPath, "/r/") if rIndex > 0 && strings.Count(importPath[:rIndex], "/") == 0 { return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) From 9f6f5cb34868839b366f840c0996d230d27fc036 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 14:20:09 +0100 Subject: [PATCH 06/48] fix: run golangci-lint --- gnovm/memfile.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index ef921455be9..8a1d95b0cba 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -108,7 +108,6 @@ func (mempkg *MemPackage) Validate() error { if rIndex > 0 && strings.Count(importPath[:rIndex], "/") == 0 { return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) } - } } } From 1f12e19d40ede454a367ded33111faa4a36b247f Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 15:07:11 +0100 Subject: [PATCH 07/48] test: adapt assert origin call txtar test --- .../gnoland/testdata/assertorigincall.txtar | 98 ++----------------- 1 file changed, 10 insertions(+), 88 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index 1315f23cc95..b31788a8e48 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -9,26 +9,18 @@ # | 4 | | through /r/foo | myrealm.A() | PANIC | # | 5 | | | myrealm.B() | pass | # | 6 | | | myrealm.C() | PANIC | -# | 7 | | through /p/demo/bar | myrealm.A() | PANIC | +# | 7 | MsgRun | wallet direct | myrealm.A() | PANIC | # | 8 | | | myrealm.B() | pass | # | 9 | | | myrealm.C() | PANIC | -# | 10 | MsgRun | wallet direct | myrealm.A() | PANIC | +# | 10 | | through /r/foo | 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 | +# | 13 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | # Init ## 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 # Test cases @@ -56,61 +48,31 @@ stdout 'OK!' ! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' -## remove due to update to maketx call can only call realm (case 7,8,9) -## 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 4000000 -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 4000000 -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 4000000 -broadcast -chainid tendermint_test test1 -## stderr 'invalid non-origin call' - -## 10. MsgRun -> run.main -> myrlm.A: PANIC +## 7. MsgRun -> run.main -> myrlm.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stderr 'invalid non-origin call' -## 11. MsgRun -> run.main -> myrlm.B: PASS +## 8. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' -## 12. MsgRun -> run.main -> myrlm.C: PANIC +## 9. MsgRun -> run.main -> myrlm.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno stderr 'invalid non-origin call' -## 13. MsgRun -> run.main -> foo.A: PANIC +## 10. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stderr 'invalid non-origin call' -## 14. MsgRun -> run.main -> foo.B: PASS +## 11. MsgRun -> run.main -> foo.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout 'OK!' -## 15. MsgRun -> run.main -> foo.C: PANIC +## 12. MsgRun -> run.main -> foo.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -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 4000000 -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 4000000 -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 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno -stderr 'invalid non-origin call' - -## remove testcase 19 due to maketx call forced to call a realm -## 19. MsgCall -> std.AssertOriginCall: pass -## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 -## stdout 'OK!' - -## 20. MsgRun -> std.AssertOriginCall: PANIC +## 13. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' @@ -146,22 +108,6 @@ 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() } @@ -213,30 +159,6 @@ 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 From aab9d5507c445bbe718351447f3cbe23ca975f1d Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 15:11:40 +0100 Subject: [PATCH 08/48] fix: skip unparsable file --- gnovm/memfile.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index 8a1d95b0cba..b23f162530a 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -92,14 +92,10 @@ func (mempkg *MemPackage) Validate() error { pIndex := strings.Index(mempkg.Path, "/p/") if pIndex > 0 && strings.Count(mempkg.Path[:pIndex], "/") == 0 { for _, file := range mempkg.Files { - // only check .gno files, can contains files like LICENSE or README that will cause parse error - if !strings.HasSuffix(file.Name, ".gno") { - continue - } fset := token.NewFileSet() astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) if err != nil { - return fmt.Errorf("unable to parse %q", file.Name) + continue // can be other files like LICENSE, README or empty gno files } for _, imp := range astFile.Imports { // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) From 4fbe93da5fa5fffaa528f2db1fde483ec5ac67a3 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 15:40:41 +0100 Subject: [PATCH 09/48] test: adapt prevrealm test txtar --- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 71 +++---------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 7a0d994a686..97622f910df 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -8,16 +8,12 @@ # | 2 | | | myrlm.B() | user address | # | 3 | | through /r/foo | myrlm.A() | r/foo | # | 4 | | | myrlm.B() | r/foo | -# | 5 | | through /p/demo/bar | myrlm.A() | user address | +# | 5 | MsgRun | wallet direct | myrlm.A() | user address | # | 6 | | | myrlm.B() | user address | -# | 7 | MsgRun | wallet direct | myrlm.A() | user address | -# | 8 | | | myrlm.B() | user address | -# | 9 | | through /r/foo | myrlm.A() | r/foo | -# | 10 | | | myrlm.B() | r/foo | -# | 11 | | through /p/demo/bar | myrlm.A() | user address | -# | 12 | | | myrlm.B() | user address | -# | 13 | MsgCall | wallet direct | std.PrevRealm() | user address | -# | 14 | MsgRun | wallet direct | std.PrevRealm() | user address | +# | 7 | | through /r/foo | myrlm.A() | r/foo | +# | 8 | | | myrlm.B() | r/foo | +# | 9 | MsgCall | wallet direct | std.PrevRealm() | user address | +# | 10 | MsgRun | wallet direct | std.PrevRealm() | user address | # Init ## deploy myrlm @@ -49,44 +45,27 @@ stdout ${RFOO_ADDR} gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} -## remove due to update to maketx call can only call realm (case 5, 6, 13) -## 5. MsgCall -> p/demo/bar.A -> myrlm.A: user address -## gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 -## stdout ${USER_ADDR_test1} - -## 6. MsgCall -> p/demo/bar.B -> myrlm.B -> r/foo.A: user address -## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 -## stdout ${USER_ADDR_test1} - -## 7. MsgRun -> myrlm.A: user address +## 5. MsgRun -> myrlm.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stdout ${USER_ADDR_test1} -## 8. MsgRun -> myrealm.B -> myrlm.A: user address +## 6. MsgRun -> myrealm.B -> myrlm.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout ${USER_ADDR_test1} -## 9. MsgRun -> r/foo.A -> myrlm.A: r/foo +## 7. MsgRun -> r/foo.A -> myrlm.A: r/foo gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stdout ${RFOO_ADDR} -## 10. MsgRun -> r/foo.B -> myrlm.B -> r/foo.A: r/foo +## 8. MsgRun -> r/foo.B -> myrlm.B -> r/foo.A: r/foo gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout ${RFOO_ADDR} -## 11. MsgRun -> p/demo/bar.A -> myrlm.A: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno -stdout ${USER_ADDR_test1} - -## 12. MsgRun -> p/demo/bar.B -> myrlm.B -> r/foo.A: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno -stdout ${USER_ADDR_test1} - -## 13. MsgCall -> std.PrevRealm(): user address +## 9. MsgCall -> std.PrevRealm(): user address ## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 ## stdout ${USER_ADDR_test1} -## 14. MsgRun -> std.PrevRealm(): user address +## 10. MsgRun -> std.PrevRealm(): user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stdout ${USER_ADDR_test1} @@ -111,18 +90,6 @@ func A() string { return myrlm.A() } -func B() string { - return myrlm.B() -} --- p/demo/bar/bar.gno -- -package bar - -import "gno.land/r/myrlm" - -func A() string { - return myrlm.A() -} - func B() string { return myrlm.B() } @@ -158,22 +125,6 @@ import "gno.land/r/foo" func main() { println(foo.B()) } --- run/barA.gno -- -package main - -import "gno.land/p/demo/bar" - -func main() { - println(bar.A()) -} --- run/barB.gno -- -package main - -import "gno.land/p/demo/bar" - -func main() { - println(bar.B()) -} -- run/baz.gno -- package main From 8f618257b6f955408267fb902d3340170cf2b2a1 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 16:20:04 +0100 Subject: [PATCH 10/48] fix: remove groups file in groups pkg since it's just a wrapper of boards --- examples/gno.land/p/demo/groups/groups.gno | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 examples/gno.land/p/demo/groups/groups.gno diff --git a/examples/gno.land/p/demo/groups/groups.gno b/examples/gno.land/p/demo/groups/groups.gno deleted file mode 100644 index fcf77dd2a74..00000000000 --- a/examples/gno.land/p/demo/groups/groups.gno +++ /dev/null @@ -1,8 +0,0 @@ -package groups - -import "gno.land/r/demo/boards" - -// TODO implement something and test. -type Group struct { - Board *boards.Board -} From d2f0200d10a0e7f0ccd84835b9d74bba3498025f Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 16:28:12 +0100 Subject: [PATCH 11/48] chore: run gno mod tidy --- examples/gno.land/p/demo/groups/gno.mod | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/gno.land/p/demo/groups/gno.mod b/examples/gno.land/p/demo/groups/gno.mod index f0749e3f411..cf33d0ce74b 100644 --- a/examples/gno.land/p/demo/groups/gno.mod +++ b/examples/gno.land/p/demo/groups/gno.mod @@ -1,6 +1,3 @@ module gno.land/p/demo/groups -require ( - gno.land/p/demo/rat v0.0.0-latest - gno.land/r/demo/boards v0.0.0-latest -) +require gno.land/p/demo/rat v0.0.0-latest From 7b026d162d42ae4c10a4bfcf0df0190fdf95cb67 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 16:39:41 +0100 Subject: [PATCH 12/48] fix: remove call from realm into pkg demo/test --- examples/gno.land/p/demo/tests/gno.mod | 1 - examples/gno.land/p/demo/tests/tests.gno | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/examples/gno.land/p/demo/tests/gno.mod b/examples/gno.land/p/demo/tests/gno.mod index d3d796f76f8..8a19acdbb18 100644 --- a/examples/gno.land/p/demo/tests/gno.mod +++ b/examples/gno.land/p/demo/tests/gno.mod @@ -3,5 +3,4 @@ module gno.land/p/demo/tests require ( gno.land/p/demo/tests/subtests v0.0.0-latest gno.land/p/demo/uassert v0.0.0-latest - gno.land/r/demo/tests v0.0.0-latest ) diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno index 43732d82dac..ffad5b8c8cd 100644 --- a/examples/gno.land/p/demo/tests/tests.gno +++ b/examples/gno.land/p/demo/tests/tests.gno @@ -4,19 +4,10 @@ import ( "std" psubtests "gno.land/p/demo/tests/subtests" - "gno.land/r/demo/tests" - rtests "gno.land/r/demo/tests" ) const World = "world" -// IncCounter demonstrates that it's possible to call a realm function from -// a package. So a package can potentially write into the store, by calling -// an other realm. -func IncCounter() { - tests.IncCounter() -} - func CurrentRealmPath() string { return std.CurrentRealm().PkgPath() } @@ -64,10 +55,6 @@ func GetPSubtestsPrevRealm() std.Realm { return psubtests.GetPrevRealm() } -func GetRTestsGetPrevRealm() std.Realm { - return rtests.GetPrevRealm() -} - // Warning: unsafe pattern. func Exec(fn func()) { fn() From e26a2932a82f53c6de19e2f5c6ea1a15ed0b3447 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 16:49:38 +0100 Subject: [PATCH 13/48] test: add txtar testfile to import realm into pkg --- .../gnoland/testdata/import_realm_pkg.txtar | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar diff --git a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar new file mode 100644 index 00000000000..c0263799e3f --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar @@ -0,0 +1,29 @@ +# This test ensures a package cannot import a realm +# the following situations: + +# Init +## set up and start a new node +loadpkg gno.land/r/myrlm $WORK/r/myrlm +loadpkg gno.land/p/demo/bar $WORK/p/demo/bar + +gnoland start +stderr 'invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' + + +-- r/myrlm/rlm.gno -- +package myrlm + +import "std" + +func A() { + println("hello world!) +} + +-- p/demo/bar/bar.gno -- +package foo + +import "gno.land/r/myrlm" + +func A() { + myrlm.A() +} From 91aa244ec424cd8b5b680db6bd11b80be3216525 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 16:51:45 +0100 Subject: [PATCH 14/48] fix: remove testfile about realm to pkg import --- examples/gno.land/p/demo/tests/z0_filetest.gno | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 examples/gno.land/p/demo/tests/z0_filetest.gno diff --git a/examples/gno.land/p/demo/tests/z0_filetest.gno b/examples/gno.land/p/demo/tests/z0_filetest.gno deleted file mode 100644 index b788eaf398f..00000000000 --- a/examples/gno.land/p/demo/tests/z0_filetest.gno +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - ptests "gno.land/p/demo/tests" - rtests "gno.land/r/demo/tests" -) - -func main() { - println(rtests.Counter()) - ptests.IncCounter() - println(rtests.Counter()) -} - -// Output: -// 0 -// 1 From 794b5a94d0929bedba8eedb2372f3d9f8b6a2d96 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 17:27:16 +0100 Subject: [PATCH 15/48] fix: adapt zrealm_crossrealm11 test to new import restriction --- gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno b/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno index e6f33c50654..5936743ddc6 100644 --- a/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno +++ b/gnovm/tests/files/zrealm_crossrealm11_stdlibs.gno @@ -2,10 +2,11 @@ package crossrealm_test import ( + "std" + ptests "gno.land/p/demo/tests" "gno.land/p/demo/ufmt" rtests "gno.land/r/demo/tests" - "std" ) func getPrevRealm() std.Realm { @@ -64,10 +65,6 @@ func main() { callStackAdd: " -> r/demo/tests -> r/demo/tests/subtests", callerFn: rtests.GetRSubtestsPrevRealm, }, - { - callStackAdd: " -> p/demo/tests -> r/demo/tests", - callerFn: ptests.GetRTestsGetPrevRealm, - }, } println("---") // needed to have space prefixes @@ -140,7 +137,3 @@ func printColumns(left, right string) { // user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests // user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests // user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/demo/tests -> r/demo/tests/subtests = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> p/demo/tests -> r/demo/tests = gno.land/r/crossrealm_test From a54975d112267449a577ad6fd5a116e2f7ee5956 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 17:47:15 +0100 Subject: [PATCH 16/48] fix: txtar prevrealm & import realm into pkg --- gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar | 2 +- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar index c0263799e3f..aca4f255e84 100644 --- a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar +++ b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar @@ -6,7 +6,7 @@ loadpkg gno.land/r/myrlm $WORK/r/myrlm loadpkg gno.land/p/demo/bar $WORK/p/demo/bar -gnoland start +!gnoland start stderr 'invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 97622f910df..c8eb7b61b52 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -20,8 +20,6 @@ loadpkg gno.land/r/myrlm $WORK/r/myrlm ## deploy r/foo loadpkg gno.land/r/foo $WORK/r/foo -## deploy p/demo/bar -loadpkg gno.land/p/demo/bar $WORK/p/demo/bar ## start a new node gnoland start From da0931329511930fc37c3b4a3bd118a77f7d0163 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 18:05:18 +0100 Subject: [PATCH 17/48] fix: txtat import realm pkg --- gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar index aca4f255e84..efe704b7439 100644 --- a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar +++ b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar @@ -6,7 +6,7 @@ loadpkg gno.land/r/myrlm $WORK/r/myrlm loadpkg gno.land/p/demo/bar $WORK/p/demo/bar -!gnoland start +! gnoland start stderr 'invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' From d52969ce56140112ea1ba8efab96ad5fea1d940b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 18:35:57 +0100 Subject: [PATCH 18/48] fix: trying to fix txtar test --- gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar index efe704b7439..41a712763ee 100644 --- a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar +++ b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar @@ -7,7 +7,7 @@ loadpkg gno.land/r/myrlm $WORK/r/myrlm loadpkg gno.land/p/demo/bar $WORK/p/demo/bar ! gnoland start -stderr 'invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' +stderr 'unable to load packages txs: unable to load pkg "gno.land/p/demo/bar": invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' -- r/myrlm/rlm.gno -- From eccc2e49e35ce2a5661a9bc431bd2c2e1c118dc4 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 18:38:08 +0100 Subject: [PATCH 19/48] fix: remove txtar not working test file --- .../gnoland/testdata/import_realm_pkg.txtar | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar diff --git a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar b/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar deleted file mode 100644 index 41a712763ee..00000000000 --- a/gno.land/cmd/gnoland/testdata/import_realm_pkg.txtar +++ /dev/null @@ -1,29 +0,0 @@ -# This test ensures a package cannot import a realm -# the following situations: - -# Init -## set up and start a new node -loadpkg gno.land/r/myrlm $WORK/r/myrlm -loadpkg gno.land/p/demo/bar $WORK/p/demo/bar - -! gnoland start -stderr 'unable to load packages txs: unable to load pkg "gno.land/p/demo/bar": invalid package: package "gno.land/p/demo/bar" imports realm "gno.land/r/myrlm"' - - --- r/myrlm/rlm.gno -- -package myrlm - -import "std" - -func A() { - println("hello world!) -} - --- p/demo/bar/bar.gno -- -package foo - -import "gno.land/r/myrlm" - -func A() { - myrlm.A() -} From a0fc9f6a410e78bfb42fe9007b539deabf8cfe89 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 18:41:34 +0100 Subject: [PATCH 20/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index c93c251b0e7..9ce59fb2a7c 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -256,6 +256,25 @@ func TestMemPackage_Validate(t *testing.T) { }, "invalid package/realm path", }, + { + "Pkg imports realm", + &MemPackage{ + Name: "hey", + Path: "gno.land/p/demo/hey", + Files: []*MemFile{ + {Name: "a.gno", Body: ` + package hey + + import "gno.land/r/demo/avl/avl.gno" + + func A() { + avl.A() + } + `}, + }, + }, + "invalid import realm from pkg", + }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { From 0fc525c776fd640de1c2855f68a29b1de081c24c Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:05:18 +0100 Subject: [PATCH 21/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index 9ce59fb2a7c..b4b67fe98f1 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -273,7 +273,7 @@ func TestMemPackage_Validate(t *testing.T) { `}, }, }, - "invalid import realm from pkg", + "package \"gno.land/p/demo/hey\" imports realm \"gnoland/r/demo/avl\"", }, } for _, tc := range tt { From 49828e80523a1290ea66b01920441cb57a28c054 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:06:43 +0100 Subject: [PATCH 22/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index b4b67fe98f1..429dfa9110d 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -260,7 +260,7 @@ func TestMemPackage_Validate(t *testing.T) { "Pkg imports realm", &MemPackage{ Name: "hey", - Path: "gno.land/p/demo/hey", + Path: "gno.land/p/demo/test", Files: []*MemFile{ {Name: "a.gno", Body: ` package hey @@ -273,7 +273,7 @@ func TestMemPackage_Validate(t *testing.T) { `}, }, }, - "package \"gno.land/p/demo/hey\" imports realm \"gnoland/r/demo/avl\"", + "package \"gno.land/p/demo/test\" imports realm \"gnoland/r/demo/avl\"", }, } for _, tc := range tt { From 9af0e68168db4e450e27d25e700a74b4f1083f51 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:06:53 +0100 Subject: [PATCH 23/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index 429dfa9110d..f1d05fc0b8e 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -263,7 +263,7 @@ func TestMemPackage_Validate(t *testing.T) { Path: "gno.land/p/demo/test", Files: []*MemFile{ {Name: "a.gno", Body: ` - package hey + package test import "gno.land/r/demo/avl/avl.gno" From 5459c2d2bd1e4ec085957872ed2543d8db78d212 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:06:59 +0100 Subject: [PATCH 24/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index f1d05fc0b8e..bfdf65800f6 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -259,7 +259,7 @@ func TestMemPackage_Validate(t *testing.T) { { "Pkg imports realm", &MemPackage{ - Name: "hey", + Name: "test", Path: "gno.land/p/demo/test", Files: []*MemFile{ {Name: "a.gno", Body: ` From c92d7142183035f85198867c36d1a4e2b7b539f3 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:09:45 +0100 Subject: [PATCH 25/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index bfdf65800f6..c07b4683fb8 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -265,7 +265,7 @@ func TestMemPackage_Validate(t *testing.T) { {Name: "a.gno", Body: ` package test - import "gno.land/r/demo/avl/avl.gno" + import "gno.land/r/demo/avl" func A() { avl.A() @@ -273,7 +273,7 @@ func TestMemPackage_Validate(t *testing.T) { `}, }, }, - "package \"gno.land/p/demo/test\" imports realm \"gnoland/r/demo/avl\"", + "package \"gno.land/p/demo/test\" imports realm \"gno.land/r/demo/avl\"", }, } for _, tc := range tt { From fde9ddd963724225241019b318e4dc6b47a2ceac Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 29 Oct 2024 19:10:52 +0100 Subject: [PATCH 26/48] fix: add test import about pkg importing realm not working --- gnovm/memfile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index c07b4683fb8..63480095f0b 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -257,7 +257,7 @@ func TestMemPackage_Validate(t *testing.T) { "invalid package/realm path", }, { - "Pkg imports realm", + "Invalid package imports realm", &MemPackage{ Name: "test", Path: "gno.land/p/demo/test", From 7116ef1e7d04b9fa45167139d07c7f1c06905eb5 Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Wed, 30 Oct 2024 14:42:30 +0100 Subject: [PATCH 27/48] chore: optimization Co-authored-by: n0izn0iz --- gnovm/memfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index b23f162530a..267a697a75a 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -90,7 +90,7 @@ func (mempkg *MemPackage) Validate() error { } pIndex := strings.Index(mempkg.Path, "/p/") - if pIndex > 0 && strings.Count(mempkg.Path[:pIndex], "/") == 0 { + if pIndex > 0 && !strings.ContainsRune(mempkg.Path[:pIndex], '/') { for _, file := range mempkg.Files { fset := token.NewFileSet() astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) From 90190a08116cccca9875418e71c5f72110b3babf Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Wed, 30 Oct 2024 14:43:03 +0100 Subject: [PATCH 28/48] chore: optimization Co-authored-by: n0izn0iz --- gnovm/memfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index 267a697a75a..8d67c1f1d6f 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -101,7 +101,7 @@ func (mempkg *MemPackage) Validate() error { // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) rIndex := strings.Index(importPath, "/r/") - if rIndex > 0 && strings.Count(importPath[:rIndex], "/") == 0 { + if rIndex > 0 && !strings.ContainsRune(importPath[:rIndex], '/') { return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) } } From 7b64799ff0ae307bd8bd17db2def05821e3f3cab Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Wed, 30 Oct 2024 14:49:33 +0100 Subject: [PATCH 29/48] fix: add test for handling /r/ as a realm name or namespace --- gnovm/memfile_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index 63480095f0b..af46a11e510 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -275,6 +275,25 @@ func TestMemPackage_Validate(t *testing.T) { }, "package \"gno.land/p/demo/test\" imports realm \"gno.land/r/demo/avl\"", }, + { + "Valid witr /r/ as a realm name", + &MemPackage{ + Name: "test", + Path: "gno.land/p/demo/test", + Files: []*MemFile{ + {Name: "a.gno", Body: ` + package test + + import "gno.land/p/r/r" + + func A() { + r.A() + } + `}, + }, + }, + "", + }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { From ad1c8df86eb315ace128b39b035d83d664105943 Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Thu, 31 Oct 2024 12:55:41 +0100 Subject: [PATCH 30/48] fix(gnovom): optimize Co-authored-by: n0izn0iz --- gnovm/memfile.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index 8d67c1f1d6f..a42c2870266 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -92,6 +92,9 @@ func (mempkg *MemPackage) Validate() error { pIndex := strings.Index(mempkg.Path, "/p/") if pIndex > 0 && !strings.ContainsRune(mempkg.Path[:pIndex], '/') { for _, file := range mempkg.Files { + if !strings.HasSuffix(file.Name, ".gno") { + continue + } fset := token.NewFileSet() astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) if err != nil { From cf90c37c1493c842d871b126282e100d68ed31da Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 12:56:43 +0100 Subject: [PATCH 31/48] fix(gnovm): return error on parsing error --- gnovm/memfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/memfile.go b/gnovm/memfile.go index a42c2870266..25024804a24 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -98,7 +98,7 @@ func (mempkg *MemPackage) Validate() error { fset := token.NewFileSet() astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) if err != nil { - continue // can be other files like LICENSE, README or empty gno files + return fmt.Errorf("failed to parse imports in file %q of package %q: %w", file.Name, mempkg.Path, err) } for _, imp := range astFile.Imports { // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) From dd1bd948932640eda5e93b2c0441c18cd8d569b4 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 14:01:23 +0100 Subject: [PATCH 32/48] fix(gnovm): add body to testfiles to avoid crash on test parsing --- gnovm/memfile_test.go | 63 ++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index af46a11e510..414cc4c92b1 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -7,6 +7,15 @@ import ( ) func TestMemPackage_Validate(t *testing.T) { + fileA := &MemFile{ + Name: "a.gno", + Body: "package test", + } + fileB := &MemFile{ + Name: "b.gno", + Body: "package test", + } + t.Parallel() tt := []struct { name string @@ -18,7 +27,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -27,7 +36,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{{Name: "b.gno"}, {Name: "a.gno"}}, + Files: []*MemFile{fileB, fileA}, }, "unsorted", }, @@ -36,7 +45,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{{Name: "a.gno"}, {Name: "a.gno"}}, + Files: []*MemFile{fileA, fileA}, }, "duplicate", }, @@ -45,7 +54,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/long/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "path length", }, @@ -54,7 +63,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -63,7 +72,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -72,7 +81,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -81,7 +90,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/path_", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -90,7 +99,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/p_ath", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -99,7 +108,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -108,7 +117,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_/_", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -117,7 +126,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/__/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -126,7 +135,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/pa-th", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -135,7 +144,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/x/path/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -144,7 +153,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -153,7 +162,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -162,7 +171,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "github.com/p/path/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -171,7 +180,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/p@th/abc/def", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -180,7 +189,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/p&th/abc/def", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -189,7 +198,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/1Path/abc/def", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -198,7 +207,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/PaTh/abc/def", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -207,7 +216,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path//def", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -216,7 +225,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path/abc/def/", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -225,7 +234,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/path", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "", }, @@ -234,7 +243,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/p@th", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -243,7 +252,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/path/", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, @@ -252,7 +261,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very//long/path/", - Files: []*MemFile{{Name: "a.gno"}}, + Files: []*MemFile{fileA}, }, "invalid package/realm path", }, From 21f15fe89a748b1aaec724680d56b2af874119fe Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 14:21:41 +0100 Subject: [PATCH 33/48] fix(gnovm): add pkg import in assertorigincall txtar --- .../gnoland/testdata/assertorigincall.txtar | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index b31788a8e48..dcaf7a78b6f 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -15,12 +15,16 @@ # | 10 | | through /r/foo | myrealm.A() | PANIC | # | 11 | | | myrealm.B() | pass | # | 12 | | | myrealm.C() | PANIC | -# | 13 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | +# | 13 | | through /p/demo/bar | bar.A() | PANIC | +# | 14 | | | bar.B() | pass | +# | 15 | | | bar.C() | PANIC | +# | 16 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | # Init ## 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 # Test cases @@ -72,7 +76,19 @@ stdout 'OK!' ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' -## 13. MsgRun -> std.AssertOriginCall: PANIC +## 13. MsgRun -> run.main -> bar.A: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +stderr 'invalid non-origin call' + +## 14. MsgRun -> run.main -> bar.B: PASS +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno +stdout 'OK!' + +## 15. MsgRun -> run.main -> bar.C: PANIC +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +stderr 'invalid non-origin call' + +## 16. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' @@ -92,6 +108,23 @@ func B() { } } +func C() { + std.AssertOriginCall() +} +-- p/demo/bar/bar.gno -- +package bar + +import "std" + +func A() { + C() +} + +func B() { + if false { + C() + } +} func C() { std.AssertOriginCall() } @@ -159,6 +192,30 @@ 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 From 128f7f46a8434cb1b6bb97d90352e9ba20fde81d Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 14:30:46 +0100 Subject: [PATCH 34/48] fix(gnovm): add pkg import from msgrun in prevrealm txtar --- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index c8eb7b61b52..5eab1ee63fc 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -12,6 +12,8 @@ # | 6 | | | myrlm.B() | user address | # | 7 | | through /r/foo | myrlm.A() | r/foo | # | 8 | | | myrlm.B() | r/foo | +# | 11 | | through /p/demo/bar | bar.A() | user address | +# | 12 | | | bar.B() | user address | # | 9 | MsgCall | wallet direct | std.PrevRealm() | user address | # | 10 | MsgRun | wallet direct | std.PrevRealm() | user address | @@ -20,6 +22,8 @@ loadpkg gno.land/r/myrlm $WORK/r/myrlm ## deploy r/foo loadpkg gno.land/r/foo $WORK/r/foo +## deploy p/demo/bar +loadpkg gno.land/p/demo/bar $WORK/p/demo/bar ## start a new node gnoland start @@ -59,6 +63,14 @@ stdout ${RFOO_ADDR} gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout ${RFOO_ADDR} +## 9. MsgRun -> p/demo/bar.A -> myrlm.A: user address +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +stdout ${USER_ADDR_test1} + +## 10. MsgRun -> p/demo/bar.B -> myrlm.B -> r/foo.A: user address +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno +stdout ${USER_ADDR_test1} + ## 9. MsgCall -> std.PrevRealm(): user address ## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 ## stdout ${USER_ADDR_test1} @@ -91,6 +103,18 @@ func A() string { func B() string { return myrlm.B() } +-- p/demo/bar/bar.gno -- +package bar + +import "std" + +func A() string { + return std.PrevRealm().Addr().String() +} + +func B() string { + return A() +} -- run/myrlmA.gno -- package main @@ -123,6 +147,22 @@ import "gno.land/r/foo" func main() { println(foo.B()) } +-- run/barA.gno -- +package main + +import "gno.land/p/demo/bar" + +func main() { + println(bar.A()) +} +-- run/barB.gno -- +package main + +import "gno.land/p/demo/bar" + +func main() { + println(bar.B()) +} -- run/baz.gno -- package main From 63be6b31345cc2821594ab47b6ce42105904ddee Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 22:00:12 +0100 Subject: [PATCH 35/48] fix(gnovm): re order index in prevrealm txtar --- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 5eab1ee63fc..dd2825e8d63 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -12,10 +12,10 @@ # | 6 | | | myrlm.B() | user address | # | 7 | | through /r/foo | myrlm.A() | r/foo | # | 8 | | | myrlm.B() | r/foo | -# | 11 | | through /p/demo/bar | bar.A() | user address | -# | 12 | | | bar.B() | user address | -# | 9 | MsgCall | wallet direct | std.PrevRealm() | user address | -# | 10 | MsgRun | wallet direct | std.PrevRealm() | user address | +# | 9 | | through /p/demo/bar | bar.A() | user address | +# | 10 | | | bar.B() | user address | +# | 11 | MsgCall | wallet direct | std.PrevRealm() | user address | +# | 12 | MsgRun | wallet direct | std.PrevRealm() | user address | # Init ## deploy myrlm From 6081a7bbae47d78734232b6c8c8d36b2109ba5cc Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 22:10:52 +0100 Subject: [PATCH 36/48] test(gnovm): add two test case file about empty gno file & non gno file skip --- gnovm/memfile_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index 414cc4c92b1..721d0550c97 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -303,6 +303,42 @@ func TestMemPackage_Validate(t *testing.T) { }, "", }, + { + "Valid package containing non gno file", + &MemPackage{ + Name: "test", + Path: "gno.land/p/demo/test", + Files: []*MemFile{ + { + Name: "README.md", + Body: ` + # Test + `, + }, + {Name: "a.gno", Body: ` + package test + + import "gno.land/p/r/r" + + func A() { + r.A() + } + `}, + }, + }, + "", + }, + { + "Invalid empty gno file", + &MemPackage{ + Name: "test", + Path: "gno.land/p/demo/test", + Files: []*MemFile{ + {Name: "a.gno"}, + }, + }, + "failed to parse imports in file \"a.gno\" of package \"gno.land/p/demo/test\"", + }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { From 8d97af3cb7b88c1c9c5826b32a30b5c3790abb4b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 31 Oct 2024 22:14:01 +0100 Subject: [PATCH 37/48] test(gnovm): fix order --- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index dd2825e8d63..7c1e5fd7c72 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -71,11 +71,11 @@ stdout ${USER_ADDR_test1} gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout ${USER_ADDR_test1} -## 9. MsgCall -> std.PrevRealm(): user address +## 11. MsgCall -> std.PrevRealm(): user address ## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 ## stdout ${USER_ADDR_test1} -## 10. MsgRun -> std.PrevRealm(): user address +## 12. MsgRun -> std.PrevRealm(): user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stdout ${USER_ADDR_test1} From 9ff76f7766ac62414f8f73af0105b9cd7e7ea68b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 1 Nov 2024 10:39:51 +0100 Subject: [PATCH 38/48] fix: keep commented tests --- .../gnoland/testdata/assertorigincall.txtar | 58 +++++++++++++------ gno.land/cmd/gnoland/testdata/prevrealm.txtar | 43 +++++++++----- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index dcaf7a78b6f..8346a98dce5 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -9,16 +9,20 @@ # | 4 | | through /r/foo | myrealm.A() | PANIC | # | 5 | | | myrealm.B() | pass | # | 6 | | | myrealm.C() | PANIC | -# | 7 | MsgRun | wallet direct | myrealm.A() | PANIC | -# | 8 | | | myrealm.B() | pass | -# | 9 | | | myrealm.C() | PANIC | -# | 10 | | through /r/foo | myrealm.A() | PANIC | +# | 7 | | through /p/demo/bar | bar.A() | PANIC | +# | 8 | | | bar.B() | pass | +# | 9 | | | bar.C() | PANIC | +# | 10 | MsgRun | wallet direct | myrealm.A() | PANIC | # | 11 | | | myrealm.B() | pass | # | 12 | | | myrealm.C() | PANIC | -# | 13 | | through /p/demo/bar | bar.A() | PANIC | -# | 14 | | | bar.B() | pass | -# | 15 | | | bar.C() | PANIC | -# | 16 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | +# | 13 | | through /r/foo | myrealm.A() | PANIC | +# | 14 | | | myrealm.B() | pass | +# | 15 | | | myrealm.C() | PANIC | +# | 16 | | through /p/demo/bar | bar.A() | PANIC | +# | 17 | | | bar.B() | pass | +# | 18 | | | bar.C() | PANIC | +# | 19 | MsgCall | wallet direct | std.AssertOriginCall() | pass | +# | 20 | MsgRun | wallet direct | std.AssertOriginCall() | PANIC | # Init ## set up and start a new node @@ -52,43 +56,61 @@ stdout 'OK!' ! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' -## 7. MsgRun -> run.main -> myrlm.A: PANIC +## remove due to update to maketx call can only call realm (case 7,8,9) +## 7. MsgCall -> p/demo/bar.A: PANIC +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## stderr 'invalid non-origin call' + +## 8. MsgCall -> p/demo/bar.B: PASS +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## stdout 'OK!' + +## 9. MsgCall -> p/demo/bar.C: PANIC +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 4000000 -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 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stderr 'invalid non-origin call' -## 8. MsgRun -> run.main -> myrlm.B: PASS +## 11. MsgRun -> run.main -> myrlm.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' -## 9. MsgRun -> run.main -> myrlm.C: PANIC +## 12. MsgRun -> run.main -> myrlm.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno stderr 'invalid non-origin call' -## 10. MsgRun -> run.main -> foo.A: PANIC +## 13. MsgRun -> run.main -> foo.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stderr 'invalid non-origin call' -## 11. MsgRun -> run.main -> foo.B: PASS +## 14. MsgRun -> run.main -> foo.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout 'OK!' -## 12. MsgRun -> run.main -> foo.C: PANIC +## 15. MsgRun -> run.main -> foo.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' -## 13. MsgRun -> run.main -> bar.A: PANIC +## 16. MsgRun -> run.main -> bar.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno stderr 'invalid non-origin call' -## 14. MsgRun -> run.main -> bar.B: PASS +## 17. MsgRun -> run.main -> bar.B: PASS gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout 'OK!' -## 15. MsgRun -> run.main -> bar.C: PANIC +## 18. MsgRun -> run.main -> bar.C: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno stderr 'invalid non-origin call' -## 16. MsgRun -> std.AssertOriginCall: PANIC +## remove testcase 19 due to maketx call forced to call a realm +## 19. MsgCall -> std.AssertOriginCall: pass +## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## stdout 'OK!' + +## 20. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 7c1e5fd7c72..4a7cece6d62 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -8,14 +8,16 @@ # | 2 | | | myrlm.B() | user address | # | 3 | | through /r/foo | myrlm.A() | r/foo | # | 4 | | | myrlm.B() | r/foo | -# | 5 | MsgRun | wallet direct | myrlm.A() | user address | -# | 6 | | | myrlm.B() | user address | -# | 7 | | through /r/foo | myrlm.A() | r/foo | -# | 8 | | | myrlm.B() | r/foo | -# | 9 | | through /p/demo/bar | bar.A() | user address | -# | 10 | | | bar.B() | user address | -# | 11 | MsgCall | wallet direct | std.PrevRealm() | user address | -# | 12 | MsgRun | wallet direct | std.PrevRealm() | user address | +# | 5 | | through /p/demo/bar | bar.A() | user address | +# | 6 | | | bar.B() | user address | +# | 7 | MsgRun | wallet direct | myrlm.A() | user address | +# | 8 | | | myrlm.B() | user address | +# | 9 | | through /r/foo | myrlm.A() | r/foo | +# | 10 | | | myrlm.B() | r/foo | +# | 11 | | through /p/demo/bar | bar.A() | user address | +# | 12 | | | bar.B() | user address | +# | 13 | MsgCall | wallet direct | std.PrevRealm() | user address | +# | 14 | MsgRun | wallet direct | std.PrevRealm() | user address | # Init ## deploy myrlm @@ -47,35 +49,44 @@ stdout ${RFOO_ADDR} gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} -## 5. MsgRun -> myrlm.A: user address +## remove due to update to maketx call can only call realm (case 5, 6, 13) +## 5. MsgCall -> p/demo/bar.A: user address +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## stdout ${USER_ADDR_test1} + +## 6. MsgCall -> p/demo/bar.B: user address +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## stdout ${USER_ADDR_test1} + +## 7. MsgRun -> myrlm.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stdout ${USER_ADDR_test1} -## 6. MsgRun -> myrealm.B -> myrlm.A: user address +## 8. MsgRun -> myrealm.B -> myrlm.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout ${USER_ADDR_test1} -## 7. MsgRun -> r/foo.A -> myrlm.A: r/foo +## 9. MsgRun -> r/foo.A -> myrlm.A: r/foo gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stdout ${RFOO_ADDR} -## 8. MsgRun -> r/foo.B -> myrlm.B -> r/foo.A: r/foo +## 10. MsgRun -> r/foo.B -> myrlm.B -> r/foo.A: r/foo gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout ${RFOO_ADDR} -## 9. MsgRun -> p/demo/bar.A -> myrlm.A: user address +## 11. MsgRun -> p/demo/bar.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno stdout ${USER_ADDR_test1} -## 10. MsgRun -> p/demo/bar.B -> myrlm.B -> r/foo.A: user address +## 12. MsgRun -> p/demo/bar.B: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout ${USER_ADDR_test1} -## 11. MsgCall -> std.PrevRealm(): user address +## 13. MsgCall -> std.PrevRealm(): user address ## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 ## stdout ${USER_ADDR_test1} -## 12. MsgRun -> std.PrevRealm(): user address +## 14. MsgRun -> std.PrevRealm(): user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stdout ${USER_ADDR_test1} From 3f61b3035afd3116d278d60dc13bb74249279f5b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 14:17:07 +0100 Subject: [PATCH 39/48] fix: move p/demo/bar/ below r/foo to fix mixed diff --- .../gnoland/testdata/assertorigincall.txtar | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index 8346a98dce5..62d660a9215 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -133,38 +133,38 @@ func B() { func C() { std.AssertOriginCall() } --- p/demo/bar/bar.gno -- -package bar +-- r/foo/foo.gno -- +package foo -import "std" +import "gno.land/r/myrlm" func A() { - C() + myrlm.A() } func B() { - if false { - C() - } + myrlm.B() } + func C() { - std.AssertOriginCall() + myrlm.C() } --- r/foo/foo.gno -- -package foo +-- p/demo/bar/bar.gno -- +package bar -import "gno.land/r/myrlm" +import "std" func A() { - myrlm.A() + C() } func B() { - myrlm.B() + if false { + C() + } } - func C() { - myrlm.C() + std.AssertOriginCall() } -- run/myrlmA.gno -- package main From 7c11108e09da541ef790a5ebb38d5ff18a5b36be Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 15:41:50 +0100 Subject: [PATCH 40/48] fix: forbid importing realms in a package in preprocess --- gnovm/memfile.go | 24 -------- gnovm/pkg/gnolang/helpers.go | 6 ++ gnovm/pkg/gnolang/preprocess.go | 4 ++ gnovm/test.txt | 98 +++++++++++++++++++++++++++++++++ gnovm/tests/files/import11.gno | 16 ++++++ 5 files changed, 124 insertions(+), 24 deletions(-) create mode 100644 gnovm/test.txt create mode 100644 gnovm/tests/files/import11.gno diff --git a/gnovm/memfile.go b/gnovm/memfile.go index 25024804a24..a37bba6ef3d 100644 --- a/gnovm/memfile.go +++ b/gnovm/memfile.go @@ -2,8 +2,6 @@ package gnovm import ( "fmt" - "go/parser" - "go/token" "regexp" "sort" "strings" @@ -89,28 +87,6 @@ func (mempkg *MemPackage) Validate() error { prev = file.Name } - pIndex := strings.Index(mempkg.Path, "/p/") - if pIndex > 0 && !strings.ContainsRune(mempkg.Path[:pIndex], '/') { - for _, file := range mempkg.Files { - if !strings.HasSuffix(file.Name, ".gno") { - continue - } - fset := token.NewFileSet() - astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) - if err != nil { - return fmt.Errorf("failed to parse imports in file %q of package %q: %w", file.Name, mempkg.Path, err) - } - for _, imp := range astFile.Imports { - // ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) - importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) - rIndex := strings.Index(importPath, "/r/") - if rIndex > 0 && !strings.ContainsRune(importPath[:rIndex], '/') { - return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) - } - } - } - } - return nil } diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index c6f7e696ea4..807274448c9 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -13,6 +13,7 @@ import ( // RealmPathPrefix is the prefix used to identify pkgpaths which are meant to // be realms and as such to have their state persisted. This is used by [IsRealmPath]. const RealmPathPrefix = "gno.land/r/" +const PackagePathPrefix = "gno.land/p/" // ReGnoRunPath is the path used for realms executed in maketx run. // These are not considered realms, as an exception to the RealmPathPrefix rule. @@ -26,6 +27,11 @@ func IsRealmPath(pkgPath string) bool { !ReGnoRunPath.MatchString(pkgPath) } +// IsPackagePath determines whether the given pkgpath is for a package. +func IsPackagePath(pkgPath string) bool { + return strings.HasPrefix(pkgPath, PackagePathPrefix) +} + // IsStdlib determines whether s is a pkgpath for a standard library. func IsStdlib(s string) bool { // NOTE(morgan): this is likely to change in the future as we add support for diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index a7a1e15bbf3..eaa72c501fe 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -174,6 +174,10 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { case *ImportDecl: nx := &n.NameExpr nn := nx.Name + loc := last.GetLocation() + if IsPackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { + panic(fmt.Sprintf("package path %s imports realm path %s", loc.PkgPath, n.PkgPath)) + } if nn == "." { panic("dot imports not allowed in gno") } diff --git a/gnovm/test.txt b/gnovm/test.txt new file mode 100644 index 00000000000..d433913bd3c --- /dev/null +++ b/gnovm/test.txt @@ -0,0 +1,98 @@ +=== RUN TestFilesNative + file_test.go:26: skipping test l2_long.gno in short mode. + file_test.go:26: skipping test l3_long.gno in short mode. + file_test.go:26: skipping test l4_long.gno in short mode. + file_test.go:26: skipping test l5_long.gno in short mode. + file_test.go:26: skipping test xfactor_long.gno in short mode. + file_test.go:26: skipping test xfib_long.gno in short mode. + file_test.go:26: skipping test zsolitaire_long.gno in short mode. +=== RUN TestFilesNative/import0.gno +=== RUN TestFilesNative/import1.gno +=== RUN TestFilesNative/import10.gno +OUTPUT: + +=== RUN TestFilesNative/import11.gno +OUTPUT: + +ERROR: +gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: +--- preprocess stack --- +stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } +stack 0: package(bar) +------------------------ +goroutine 15 [running]: +runtime/debug.Stack() + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/debug/stack.go:24 +0x5e +runtime/debug.PrintStack() + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/debug/stack.go:16 +0x13 +command-line-arguments.RunFileTest.func1.1() + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:170 +0x213 +panic({0xb2d320?, 0xc00058b380?}) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 +github.com/gnolang/gno/gnovm/pkg/gnolang.doRecover({0xc000573a00, 0x2, 0x20}, {0xe0f1a0, 0xc00017e120}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:379 +0x396 +panic({0xae0a20?, 0xc0002ea900?}) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 +github.com/gnolang/gno/gnovm/pkg/gnolang.initStaticBlocks.func1({0xc000573c00?, 0x4111ff?, 0xb75b20?}, 0xa0?, 0xc000586c08?, {0xe0f1a0, 0xc00017e120}, 0xd0?) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:179 +0x1414 +github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0xc0000dce90, {0xc000573c00, 0x1, 0x20}, 0x4f, 0x0, {0xe0f1a0, 0xc00017e120}, 0xc0000dcb67) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:143 +0x8a +github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0xc0000dce90, {0xc000573c00, 0x0, 0x20}, 0x0, 0x0, {0xe0f2a0, 0xc000586c08}, 0xc0000dce07) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:732 +0x33b9 +github.com/gnolang/gno/gnovm/pkg/gnolang.Transcribe({0xe0f2a0, 0xc000586c08}, 0xc0000dce90) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:136 +0xb6 +github.com/gnolang/gno/gnovm/pkg/gnolang.initStaticBlocks({0xe19910, 0xc000714640}, {0xe19a30, 0xc000586608}, {0xe19da8, 0xc000586c08}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:148 +0x185 +github.com/gnolang/gno/gnovm/pkg/gnolang.PredefineFileSet({0xe19910, 0xc000714640}, 0xc000586608, 0xc000584468) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:30 +0xea +github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).runFileDecls(0xc00058e488, {0xc000580108, 0x1, 0x1}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/machine.go:641 +0x275 +github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunFiles(0xc00058e488, {0xc000580108?, 0xc0003705a0?, 0x120?}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/machine.go:599 +0x2e +command-line-arguments.RunFileTest.func1(0x2?, 0x0?, {0x0?, 0x12?}, 0xc0005841b0, {0xc0005921e9, 0x13}, {0xc0005921f9, 0x3}, {0xe19910, ...}, ...) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:187 +0x837 +command-line-arguments.RunFileTest({0xc000590258, 0x5}, {0xc000412798, 0x12}, {0xc00058ad50, 0x4, 0x6?}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:262 +0x3cd +command-line-arguments.runFileTest(0xc000338680, {0xc000412798, 0x12}, {0xc0002ffa50, 0x2, 0x49d32f?}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:140 +0x225 +command-line-arguments.runFileTests.func1(0xc000338680?) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:64 +0x2d +testing.tRunner(0xc000338680, 0xc000584150) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1689 +0xfb +created by testing.(*T).Run in goroutine 19 + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1742 +0x390 +--- FAIL: TestFilesNative (0.01s) + --- PASS: TestFilesNative/import0.gno (0.00s) + --- PASS: TestFilesNative/import1.gno (0.00s) + --- PASS: TestFilesNative/import10.gno (0.00s) + --- FAIL: TestFilesNative/import11.gno (0.00s) +panic: fail on files/import11.gno: got unexpected error: gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: +--- preprocess stack --- +stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } +stack 0: package(bar) +------------------------ [recovered] + panic: fail on files/import11.gno: got unexpected error: gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: +--- preprocess stack --- +stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } +stack 0: package(bar) +------------------------ + +goroutine 15 [running]: +testing.tRunner.func1.2({0xae0a20, 0xc0002eac70}) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1631 +0x24a +testing.tRunner.func1() + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1634 +0x377 +panic({0xae0a20?, 0xc0002eac70?}) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 +command-line-arguments.RunFileTest({0xc000590258, 0x5}, {0xc000412798, 0x12}, {0xc00058ad50, 0x4, 0x6?}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:337 +0x1707 +command-line-arguments.runFileTest(0xc000338680, {0xc000412798, 0x12}, {0xc0002ffa50, 0x2, 0x49d32f?}) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:140 +0x225 +command-line-arguments.runFileTests.func1(0xc000338680?) + /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:64 +0x2d +testing.tRunner(0xc000338680, 0xc000584150) + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1689 +0xfb +created by testing.(*T).Run in goroutine 19 + /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1742 +0x390 +FAIL command-line-arguments 0.017s +FAIL diff --git a/gnovm/tests/files/import11.gno b/gnovm/tests/files/import11.gno new file mode 100644 index 00000000000..1890459ad86 --- /dev/null +++ b/gnovm/tests/files/import11.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/p/demo/bar +package bar + +import ( + "gno.land/r/demo/tests" +) + +// NOTE: it is valid to persist external realm types. +var somevalue tests.TestRealmObject + +func main() { + println(tests.Counter()) +} + +// Error: +// gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests From e805310e4f508304db290dda4b11db3ecec3f372 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 15:42:31 +0100 Subject: [PATCH 41/48] fix: forbid importing realms in a package in preprocess --- gnovm/tests/files/import11.gno | 3 --- 1 file changed, 3 deletions(-) diff --git a/gnovm/tests/files/import11.gno b/gnovm/tests/files/import11.gno index 1890459ad86..100076f264c 100644 --- a/gnovm/tests/files/import11.gno +++ b/gnovm/tests/files/import11.gno @@ -5,9 +5,6 @@ import ( "gno.land/r/demo/tests" ) -// NOTE: it is valid to persist external realm types. -var somevalue tests.TestRealmObject - func main() { println(tests.Counter()) } From 8bc6d34186fdc303127b710dcec9313ae1a967bb Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 15:42:53 +0100 Subject: [PATCH 42/48] fix: forbid importing realms in a package in preprocess --- gnovm/test.txt | 98 -------------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 gnovm/test.txt diff --git a/gnovm/test.txt b/gnovm/test.txt deleted file mode 100644 index d433913bd3c..00000000000 --- a/gnovm/test.txt +++ /dev/null @@ -1,98 +0,0 @@ -=== RUN TestFilesNative - file_test.go:26: skipping test l2_long.gno in short mode. - file_test.go:26: skipping test l3_long.gno in short mode. - file_test.go:26: skipping test l4_long.gno in short mode. - file_test.go:26: skipping test l5_long.gno in short mode. - file_test.go:26: skipping test xfactor_long.gno in short mode. - file_test.go:26: skipping test xfib_long.gno in short mode. - file_test.go:26: skipping test zsolitaire_long.gno in short mode. -=== RUN TestFilesNative/import0.gno -=== RUN TestFilesNative/import1.gno -=== RUN TestFilesNative/import10.gno -OUTPUT: - -=== RUN TestFilesNative/import11.gno -OUTPUT: - -ERROR: -gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: ---- preprocess stack --- -stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } -stack 0: package(bar) ------------------------- -goroutine 15 [running]: -runtime/debug.Stack() - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/debug/stack.go:24 +0x5e -runtime/debug.PrintStack() - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/debug/stack.go:16 +0x13 -command-line-arguments.RunFileTest.func1.1() - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:170 +0x213 -panic({0xb2d320?, 0xc00058b380?}) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 -github.com/gnolang/gno/gnovm/pkg/gnolang.doRecover({0xc000573a00, 0x2, 0x20}, {0xe0f1a0, 0xc00017e120}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:379 +0x396 -panic({0xae0a20?, 0xc0002ea900?}) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 -github.com/gnolang/gno/gnovm/pkg/gnolang.initStaticBlocks.func1({0xc000573c00?, 0x4111ff?, 0xb75b20?}, 0xa0?, 0xc000586c08?, {0xe0f1a0, 0xc00017e120}, 0xd0?) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:179 +0x1414 -github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0xc0000dce90, {0xc000573c00, 0x1, 0x20}, 0x4f, 0x0, {0xe0f1a0, 0xc00017e120}, 0xc0000dcb67) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:143 +0x8a -github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0xc0000dce90, {0xc000573c00, 0x0, 0x20}, 0x0, 0x0, {0xe0f2a0, 0xc000586c08}, 0xc0000dce07) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:732 +0x33b9 -github.com/gnolang/gno/gnovm/pkg/gnolang.Transcribe({0xe0f2a0, 0xc000586c08}, 0xc0000dce90) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/transcribe.go:136 +0xb6 -github.com/gnolang/gno/gnovm/pkg/gnolang.initStaticBlocks({0xe19910, 0xc000714640}, {0xe19a30, 0xc000586608}, {0xe19da8, 0xc000586c08}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:148 +0x185 -github.com/gnolang/gno/gnovm/pkg/gnolang.PredefineFileSet({0xe19910, 0xc000714640}, 0xc000586608, 0xc000584468) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/preprocess.go:30 +0xea -github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).runFileDecls(0xc00058e488, {0xc000580108, 0x1, 0x1}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/machine.go:641 +0x275 -github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunFiles(0xc00058e488, {0xc000580108?, 0xc0003705a0?, 0x120?}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/pkg/gnolang/machine.go:599 +0x2e -command-line-arguments.RunFileTest.func1(0x2?, 0x0?, {0x0?, 0x12?}, 0xc0005841b0, {0xc0005921e9, 0x13}, {0xc0005921f9, 0x3}, {0xe19910, ...}, ...) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:187 +0x837 -command-line-arguments.RunFileTest({0xc000590258, 0x5}, {0xc000412798, 0x12}, {0xc00058ad50, 0x4, 0x6?}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:262 +0x3cd -command-line-arguments.runFileTest(0xc000338680, {0xc000412798, 0x12}, {0xc0002ffa50, 0x2, 0x49d32f?}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:140 +0x225 -command-line-arguments.runFileTests.func1(0xc000338680?) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:64 +0x2d -testing.tRunner(0xc000338680, 0xc000584150) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1689 +0xfb -created by testing.(*T).Run in goroutine 19 - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1742 +0x390 ---- FAIL: TestFilesNative (0.01s) - --- PASS: TestFilesNative/import0.gno (0.00s) - --- PASS: TestFilesNative/import1.gno (0.00s) - --- PASS: TestFilesNative/import10.gno (0.00s) - --- FAIL: TestFilesNative/import11.gno (0.00s) -panic: fail on files/import11.gno: got unexpected error: gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: ---- preprocess stack --- -stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } -stack 0: package(bar) ------------------------- [recovered] - panic: fail on files/import11.gno: got unexpected error: gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests: ---- preprocess stack --- -stack 1: file{ package bar; import gno.land/r/demo/tests; var somevalue tests.TestRealmObject; func main() { println(tests.Counter()) } } -stack 0: package(bar) ------------------------- - -goroutine 15 [running]: -testing.tRunner.func1.2({0xae0a20, 0xc0002eac70}) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1631 +0x24a -testing.tRunner.func1() - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1634 +0x377 -panic({0xae0a20?, 0xc0002eac70?}) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/runtime/panic.go:770 +0x132 -command-line-arguments.RunFileTest({0xc000590258, 0x5}, {0xc000412798, 0x12}, {0xc00058ad50, 0x4, 0x6?}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file.go:337 +0x1707 -command-line-arguments.runFileTest(0xc000338680, {0xc000412798, 0x12}, {0xc0002ffa50, 0x2, 0x49d32f?}) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:140 +0x225 -command-line-arguments.runFileTests.func1(0xc000338680?) - /home/mikael-vallenet/go/src/github.com/gno/gnovm/tests/file_test.go:64 +0x2d -testing.tRunner(0xc000338680, 0xc000584150) - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1689 +0xfb -created by testing.(*T).Run in goroutine 19 - /home/mikael-vallenet/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.linux-amd64/src/testing/testing.go:1742 +0x390 -FAIL command-line-arguments 0.017s -FAIL From 46eadcca4fadf6ee8587d5032fe53f3486f1e026 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 15:45:33 +0100 Subject: [PATCH 43/48] fix: remove memfile test --- gnovm/memfile_test.go | 137 +++++++++--------------------------------- 1 file changed, 27 insertions(+), 110 deletions(-) diff --git a/gnovm/memfile_test.go b/gnovm/memfile_test.go index 721d0550c97..c93c251b0e7 100644 --- a/gnovm/memfile_test.go +++ b/gnovm/memfile_test.go @@ -7,15 +7,6 @@ import ( ) func TestMemPackage_Validate(t *testing.T) { - fileA := &MemFile{ - Name: "a.gno", - Body: "package test", - } - fileB := &MemFile{ - Name: "b.gno", - Body: "package test", - } - t.Parallel() tt := []struct { name string @@ -27,7 +18,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -36,7 +27,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{fileB, fileA}, + Files: []*MemFile{{Name: "b.gno"}, {Name: "a.gno"}}, }, "unsorted", }, @@ -45,7 +36,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/demo/hey", - Files: []*MemFile{fileA, fileA}, + Files: []*MemFile{{Name: "a.gno"}, {Name: "a.gno"}}, }, "duplicate", }, @@ -54,7 +45,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/long/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "path length", }, @@ -63,7 +54,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -72,7 +63,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -81,7 +72,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -90,7 +81,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/path_", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -99,7 +90,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/p_ath", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -108,7 +99,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -117,7 +108,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/_/_", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -126,7 +117,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/__/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -135,7 +126,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/path/pa-th", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -144,7 +135,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/x/path/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -153,7 +144,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -162,7 +153,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -171,7 +162,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "github.com/p/path/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -180,7 +171,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/p@th/abc/def", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -189,7 +180,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/p&th/abc/def", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -198,7 +189,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/1Path/abc/def", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -207,7 +198,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/PaTh/abc/def", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -216,7 +207,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path//def", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -225,7 +216,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/p/path/abc/def/", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -234,7 +225,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/path", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "", }, @@ -243,7 +234,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/p@th", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -252,7 +243,7 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very/long/path/", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, @@ -261,84 +252,10 @@ func TestMemPackage_Validate(t *testing.T) { &MemPackage{ Name: "hey", Path: "gno.land/r/very/very/very//long/path/", - Files: []*MemFile{fileA}, + Files: []*MemFile{{Name: "a.gno"}}, }, "invalid package/realm path", }, - { - "Invalid package imports realm", - &MemPackage{ - Name: "test", - Path: "gno.land/p/demo/test", - Files: []*MemFile{ - {Name: "a.gno", Body: ` - package test - - import "gno.land/r/demo/avl" - - func A() { - avl.A() - } - `}, - }, - }, - "package \"gno.land/p/demo/test\" imports realm \"gno.land/r/demo/avl\"", - }, - { - "Valid witr /r/ as a realm name", - &MemPackage{ - Name: "test", - Path: "gno.land/p/demo/test", - Files: []*MemFile{ - {Name: "a.gno", Body: ` - package test - - import "gno.land/p/r/r" - - func A() { - r.A() - } - `}, - }, - }, - "", - }, - { - "Valid package containing non gno file", - &MemPackage{ - Name: "test", - Path: "gno.land/p/demo/test", - Files: []*MemFile{ - { - Name: "README.md", - Body: ` - # Test - `, - }, - {Name: "a.gno", Body: ` - package test - - import "gno.land/p/r/r" - - func A() { - r.A() - } - `}, - }, - }, - "", - }, - { - "Invalid empty gno file", - &MemPackage{ - Name: "test", - Path: "gno.land/p/demo/test", - Files: []*MemFile{ - {Name: "a.gno"}, - }, - }, - "failed to parse imports in file \"a.gno\" of package \"gno.land/p/demo/test\"", - }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { From 7c57133821d09cc93c8d163b3ea2c3672df58ade Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 7 Nov 2024 15:56:56 +0100 Subject: [PATCH 44/48] chore: lint --- gnovm/pkg/gnolang/helpers.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index 807274448c9..63455c0dc2f 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -12,8 +12,10 @@ import ( // RealmPathPrefix is the prefix used to identify pkgpaths which are meant to // be realms and as such to have their state persisted. This is used by [IsRealmPath]. -const RealmPathPrefix = "gno.land/r/" -const PackagePathPrefix = "gno.land/p/" +const ( + RealmPathPrefix = "gno.land/r/" + PackagePathPrefix = "gno.land/p/" +) // ReGnoRunPath is the path used for realms executed in maketx run. // These are not considered realms, as an exception to the RealmPathPrefix rule. From 913e440d2635253039b94e3e1f153350ca29fe5b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 8 Nov 2024 11:07:51 +0100 Subject: [PATCH 45/48] chore(gno/dao): rename func isPackagePath -> isPurePackagePath --- gnovm/pkg/gnolang/helpers.go | 4 ++-- gnovm/pkg/gnolang/preprocess.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index 63455c0dc2f..29e24f708d2 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -29,8 +29,8 @@ func IsRealmPath(pkgPath string) bool { !ReGnoRunPath.MatchString(pkgPath) } -// IsPackagePath determines whether the given pkgpath is for a package. -func IsPackagePath(pkgPath string) bool { +// IsPurePackagePath determines whether the given pkgpath is for a gno package. +func IsPurePackagePath(pkgPath string) bool { return strings.HasPrefix(pkgPath, PackagePathPrefix) } diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index eaa72c501fe..6aff87c3230 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -175,7 +175,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { nx := &n.NameExpr nn := nx.Name loc := last.GetLocation() - if IsPackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { + if IsPurePackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { panic(fmt.Sprintf("package path %s imports realm path %s", loc.PkgPath, n.PkgPath)) } if nn == "." { From 43bc5995b2341b29465fdfb2b4e1c19922a0fe23 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Tue, 19 Nov 2024 12:50:51 +0100 Subject: [PATCH 46/48] chore(gnovm): enhance accuracy of error msg about p/ cannot import r/ --- gnovm/pkg/gnolang/preprocess.go | 2 +- gnovm/tests/files/import11.gno | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 028e569ffed..19e87b2efb6 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -176,7 +176,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { nn := nx.Name loc := last.GetLocation() if IsPurePackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { - panic(fmt.Sprintf("package path %s imports realm path %s", loc.PkgPath, n.PkgPath)) + panic(fmt.Sprintf("should not happen p/ cannot import r/: package path %s imports realm path %s", loc.PkgPath, n.PkgPath)) } if nn == "." { panic("dot imports not allowed in gno") diff --git a/gnovm/tests/files/import11.gno b/gnovm/tests/files/import11.gno index 100076f264c..a7ed070917d 100644 --- a/gnovm/tests/files/import11.gno +++ b/gnovm/tests/files/import11.gno @@ -10,4 +10,4 @@ func main() { } // Error: -// gno.land/p/demo/bar/files/import11.gno:5:2: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests +// gno.land/p/demo/bar/files/import11.gno:5:2: should not happen p/ cannot import r/: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests From af320def9b40d49e3ba5d2acbc4c4598389d4862 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Wed, 20 Nov 2024 14:30:12 +0100 Subject: [PATCH 47/48] chore(gnovm): enhance accuracy of error msg about p/ cannot import r/ --- gnovm/pkg/gnolang/preprocess.go | 2 +- gnovm/tests/files/import11.gno | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 19e87b2efb6..b3aacb5c19a 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -176,7 +176,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { nn := nx.Name loc := last.GetLocation() if IsPurePackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { - panic(fmt.Sprintf("should not happen p/ cannot import r/: package path %s imports realm path %s", loc.PkgPath, n.PkgPath)) + panic(fmt.Sprintf("pure package path %q cannot import realm path %q", loc.PkgPath, n.PkgPath)) } if nn == "." { panic("dot imports not allowed in gno") diff --git a/gnovm/tests/files/import11.gno b/gnovm/tests/files/import11.gno index a7ed070917d..594e9f10698 100644 --- a/gnovm/tests/files/import11.gno +++ b/gnovm/tests/files/import11.gno @@ -10,4 +10,4 @@ func main() { } // Error: -// gno.land/p/demo/bar/files/import11.gno:5:2: should not happen p/ cannot import r/: package path gno.land/p/demo/bar imports realm path gno.land/r/demo/tests +// gno.land/p/demo/bar/files/import11.gno:5:2: pure package path "gno.land/p/demo/bar" cannot import realm path "gno.land/r/demo/tests" From 13623871ba28d130d5b481eb1cbe762fa77b0880 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 26 Nov 2024 15:00:57 +0100 Subject: [PATCH 48/48] Apply suggestions from code review --- gnovm/pkg/gnolang/helpers.go | 4 +++- gnovm/pkg/gnolang/preprocess.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index 29e24f708d2..d3a8485ee17 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -29,7 +29,9 @@ func IsRealmPath(pkgPath string) bool { !ReGnoRunPath.MatchString(pkgPath) } -// IsPurePackagePath determines whether the given pkgpath is for a gno package. +// IsPurePackagePath determines whether the given pkgpath is for a published Gno package. +// It only considers "pure" those starting with gno.land/p/, so it returns false for +// stdlib packages and MsgRun paths. func IsPurePackagePath(pkgPath string) bool { return strings.HasPrefix(pkgPath, PackagePathPrefix) } diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 122ceba142a..5f1cbb38e3d 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -175,6 +175,9 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { nx := &n.NameExpr nn := nx.Name loc := last.GetLocation() + // NOTE: imports from "pure packages" are actually sometimes + // allowed, most notably in MsgRun and filetests; IsPurePackagePath + // returns false in these cases. if IsPurePackagePath(loc.PkgPath) && IsRealmPath(n.PkgPath) { panic(fmt.Sprintf("pure package path %q cannot import realm path %q", loc.PkgPath, n.PkgPath)) }