From 7f16c88dcf9edeebe505917c9c776c5930f9d6b8 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 22:04:18 +0700 Subject: [PATCH 01/30] deprecate & remove std.CurrentRealmPath() --- docs/concepts/stdlibs/gnopher-hole.md | 2 +- docs/reference/stdlibs/std/chain.md | 13 ------------- docs/reference/stdlibs/std/testing.md | 8 ++++---- examples/gno.land/p/demo/tests/tests.gno | 2 +- examples/gno.land/r/demo/tests/tests.gno | 2 +- gnovm/stdlibs/native.go | 19 ------------------- gnovm/stdlibs/std/emit_event.go | 2 +- gnovm/stdlibs/std/emit_event_test.go | 6 +++++- gnovm/stdlibs/std/native.gno | 10 ++++++---- gnovm/stdlibs/std/native.go | 7 ------- gnovm/stdlibs/stdshim/stdshim.gno | 5 ----- gnovm/tests/files/zrealm12.gno | 10 +++++----- gnovm/tests/files/zrealm_std3.gno | 4 ++-- gnovm/tests/stdlibs/native.go | 4 ++-- gnovm/tests/stdlibs/std/std.gno | 11 ++++++----- gnovm/tests/stdlibs/std/std.go | 2 +- 16 files changed, 35 insertions(+), 72 deletions(-) diff --git a/docs/concepts/stdlibs/gnopher-hole.md b/docs/concepts/stdlibs/gnopher-hole.md index b8795cc5af7..b9ce0c700af 100644 --- a/docs/concepts/stdlibs/gnopher-hole.md +++ b/docs/concepts/stdlibs/gnopher-hole.md @@ -12,7 +12,7 @@ in Go. There are generally three reasons why a function should be natively defined: 1. It relies on inspecting the Gno Virtual Machine itself, i.e. `std.AssertOriginCall` - or `std.CurrentRealmPath`. + or `std.CurrentRealm`. 2. It relies on `unsafe`, or other features which are not planned to be available in the GnoVM, i.e. `math.Float64frombits`. 3. Its native Go performance significantly outperforms the Gno counterpart by diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index bda09b2fe80..9de7bb161c3 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -26,19 +26,6 @@ Panics if caller of function is not an EOA. ```go std.AssertOriginCall() ``` ---- - -## CurrentRealmPath -```go -func CurrentRealmPath() string -``` -Returns the path of the realm it is called in. - -#### Usage -```go -realmPath := std.CurrentRealmPath() // gno.land/r/demo/users -``` ---- ## GetChainID ```go diff --git a/docs/reference/stdlibs/std/testing.md b/docs/reference/stdlibs/std/testing.md index 8c9146c81a1..10c5016e0b9 100644 --- a/docs/reference/stdlibs/std/testing.md +++ b/docs/reference/stdlibs/std/testing.md @@ -5,7 +5,7 @@ id: testing # Testing ```go -func TestCurrentRealm() string +func TestCurrentRealmPath() string func TestSkipHeights(count int64) func TestSetOrigCaller(addr Address) func TestSetOrigPkgAddr(addr Address) @@ -13,15 +13,15 @@ func TestSetOrigSend(sent, spent Coins) func TestIssueCoins(addr Address, coins Coins) ``` -## TestCurrentRealm +## TestCurrentRealmPath ```go -func TestCurrentRealm() string +func TestCurrentRealmPath() string ``` Returns the current realm path. #### Usage ```go -currentRealmPath := std.TestCurrentRealm() +currentRealmPath := std.TestCurrentRealmPath() ``` --- diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno index 1a2c2526d01..43732d82dac 100644 --- a/examples/gno.land/p/demo/tests/tests.gno +++ b/examples/gno.land/p/demo/tests/tests.gno @@ -18,7 +18,7 @@ func IncCounter() { } func CurrentRealmPath() string { - return std.CurrentRealmPath() + return std.CurrentRealm().PkgPath() } //---------------------------------------- diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index 2062df6903d..14adad7355c 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -17,7 +17,7 @@ func Counter() int { } func CurrentRealmPath() string { - return std.CurrentRealmPath() + return std.CurrentRealm().PkgPath() } var initOrigCaller = std.GetOrigCaller() diff --git a/gnovm/stdlibs/native.go b/gnovm/stdlibs/native.go index 3b1ab719e72..7319e393c35 100644 --- a/gnovm/stdlibs/native.go +++ b/gnovm/stdlibs/native.go @@ -425,25 +425,6 @@ var nativeFuncs = [...]nativeFunc{ )) }, }, - { - "std", - "CurrentRealmPath", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{ - {Name: gno.N("r0"), Type: gno.X("string")}, - }, - func(m *gno.Machine) { - r0 := libs_std.CurrentRealmPath( - m, - ) - - m.PushValue(gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(&r0).Elem(), - )) - }, - }, { "std", "GetChainID", diff --git a/gnovm/stdlibs/std/emit_event.go b/gnovm/stdlibs/std/emit_event.go index 46fea79d43c..9c591f61150 100644 --- a/gnovm/stdlibs/std/emit_event.go +++ b/gnovm/stdlibs/std/emit_event.go @@ -17,7 +17,7 @@ func X_emit(m *gno.Machine, typ string, attrs []string) { m.Panic(typedString(err.Error())) } - pkgPath := CurrentRealmPath(m) + _, pkgPath := X_getRealm(m, 0) fnIdent := getPrevFunctionNameFromTarget(m, "Emit") evt := gnoEvent{ diff --git a/gnovm/stdlibs/std/emit_event_test.go b/gnovm/stdlibs/std/emit_event_test.go index 10bd8ecacd9..df032536a51 100644 --- a/gnovm/stdlibs/std/emit_event_test.go +++ b/gnovm/stdlibs/std/emit_event_test.go @@ -13,7 +13,11 @@ import ( func TestEmit(t *testing.T) { m := gno.NewMachine("emit", nil) - pkgPath := CurrentRealmPath(m) + + elgs := sdk.NewEventLogger() + m.Context = ExecContext{EventLogger: elgs} + + _, pkgPath := X_getRealm(m, 0) tests := []struct { name string eventType string diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 8043df49882..1b3fb8cbaca 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -1,10 +1,12 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected +func AssertOriginCall() // injected +func IsOriginCall() bool // injected +func GetChainID() string // injected +func GetHeight() int64 // injected + +// Deprecated : use CurrentRealm().PkgPath() instead func CurrentRealmPath() string // injected -func GetChainID() string // injected -func GetHeight() int64 // injected func GetOrigSend() Coins { den, amt := origSend() diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index deb0f1268d2..963d90391c9 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -17,13 +17,6 @@ func IsOriginCall(m *gno.Machine) bool { return len(m.Frames) == 2 } -func CurrentRealmPath(m *gno.Machine) string { - if m.Realm != nil { - return m.Realm.Path - } - return "" -} - func GetChainID(m *gno.Machine) string { return m.Context.(ExecContext).ChainID } diff --git a/gnovm/stdlibs/stdshim/stdshim.gno b/gnovm/stdlibs/stdshim/stdshim.gno index 62e97088209..efffea59dae 100644 --- a/gnovm/stdlibs/stdshim/stdshim.gno +++ b/gnovm/stdlibs/stdshim/stdshim.gno @@ -16,11 +16,6 @@ func Hash(bz []byte) (hash [20]byte) { return } -func CurrentRealmPath() string { - panic(shimWarn) - return "" -} - func GetChainID() string { panic(shimWarn) return "" diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index 0049cba6073..62b96a29af3 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -8,23 +8,23 @@ import ( ) func main() { - if std.TestCurrentRealm() != "gno.land/r/test" { + if std.TestCurrentRealmPath() != "gno.land/r/test" { panic("should not happen") } tests.InitTestNodes() - if std.TestCurrentRealm() != "gno.land/r/test" { + if std.TestCurrentRealmPath() != "gno.land/r/test" { panic("should not happen") } tests.ModTestNodes() - if std.TestCurrentRealm() != "gno.land/r/test" { + if std.TestCurrentRealmPath() != "gno.land/r/test" { panic("should not happen") } std.ClearStoreCache() - if std.TestCurrentRealm() != "gno.land/r/test" { + if std.TestCurrentRealmPath() != "gno.land/r/test" { panic("should not happen") } tests.PrintTestNodes() - if std.TestCurrentRealm() != "gno.land/r/test" { + if std.TestCurrentRealmPath() != "gno.land/r/test" { panic("should not happen") } } diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index c13feffa42c..790098b74f7 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -6,11 +6,11 @@ import ( ) func foo() { - println("foo", std.CurrentRealmPath()) + println("foo", std.TestCurrentRealmPath()) } func main() { - println("main", std.CurrentRealmPath()) + println("main", std.TestCurrentRealmPath()) foo() } diff --git a/gnovm/tests/stdlibs/native.go b/gnovm/tests/stdlibs/native.go index 6964a003025..8e14c2dd796 100644 --- a/gnovm/tests/stdlibs/native.go +++ b/gnovm/tests/stdlibs/native.go @@ -52,13 +52,13 @@ var nativeFuncs = [...]nativeFunc{ }, { "std", - "TestCurrentRealm", + "TestCurrentRealmPath", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("string")}, }, func(m *gno.Machine) { - r0 := testlibs_std.TestCurrentRealm( + r0 := testlibs_std.TestCurrentRealmPath( m, ) diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index 2b142634740..1d3aad1285a 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,10 +1,10 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected -func TestCurrentRealm() string // injected -func TestSkipHeights(count int64) // injected -func ClearStoreCache() // injected +func AssertOriginCall() // injected +func IsOriginCall() bool // injected +func TestCurrentRealmPath() string // injected +func TestSkipHeights(count int64) // injected +func ClearStoreCache() // injected func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } @@ -13,6 +13,7 @@ func TestSetOrigSend(sent, spent Coins) { spentDenom, spentAmt := spent.expandNative() testSetOrigSend(sentDenom, sentAmt, spentDenom, spentAmt) } + func TestIssueCoins(addr Address, coins Coins) { denom, amt := coins.expandNative() testIssueCoins(string(addr), denom, amt) diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index f7bc001043e..f0d4eda7636 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -39,7 +39,7 @@ func IsOriginCall(m *gno.Machine) bool { panic("unable to determine if test is a _test or a _filetest") } -func TestCurrentRealm(m *gno.Machine) string { +func TestCurrentRealmPath(m *gno.Machine) string { return m.Realm.Path } From 7b38041c83687f4514b0a83c98ab0c26f2436858 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 22:35:13 +0700 Subject: [PATCH 02/30] remove go function CurrentRealmPath --- gnovm/stdlibs/std/native.gno | 3 --- 1 file changed, 3 deletions(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 1b3fb8cbaca..ef2601eeca3 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -5,9 +5,6 @@ func IsOriginCall() bool // injected func GetChainID() string // injected func GetHeight() int64 // injected -// Deprecated : use CurrentRealm().PkgPath() instead -func CurrentRealmPath() string // injected - func GetOrigSend() Coins { den, amt := origSend() coins := make(Coins, len(den)) From 5bd2bbe9ba52ffa434cf709f60b7b20da381c443 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 22:39:46 +0700 Subject: [PATCH 03/30] rename func --- gnovm/tests/files/zrealm_natbind0.gno | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 084ddd3d18f..41589404571 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,13 +12,13 @@ func init() { } func main() { - // NOTE: this test uses GetHeight and CurrentRealmPath, which are "pure" + // NOTE: this test uses GetHeight and CurrentRealm, which are "pure" // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). - f := node.(func() int64) + f := node.(func() Realm) println(f()) - node = std.CurrentRealmPath - g := node.(func() string) + node = std.CurrentRealm + g := node.(func() Realm) println(g()) } @@ -145,8 +145,8 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "CurrentRealmPath", -// "NativeName": "CurrentRealmPath", +// "Name": "CurrentRealm", +// "NativeName": "CurrentRealm", // "NativePkg": "std", // "PkgPath": "std", // "Source": { From 39a776db87897fd8361413b714a68e96449d7a7e Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 22:44:04 +0700 Subject: [PATCH 04/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 41589404571..c76b106010e 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,10 +12,10 @@ func init() { } func main() { - // NOTE: this test uses GetHeight and CurrentRealm, which are "pure" + // NOTE: this test uses GetHeight and CurrentRealmPath, which are "pure" // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). - f := node.(func() Realm) + f := node.(func() int64) println(f()) node = std.CurrentRealm g := node.(func() Realm) @@ -145,8 +145,8 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "CurrentRealm", -// "NativeName": "CurrentRealm", +// "Name": "CurrentRealmPath", +// "NativeName": "CurrentRealmPath", // "NativePkg": "std", // "PkgPath": "std", // "Source": { From a602c468a688a86bb261c74ad02ef2171f28fb84 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 22:46:45 +0700 Subject: [PATCH 05/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index c76b106010e..f3eabca0d17 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,14 +12,14 @@ func init() { } func main() { - // NOTE: this test uses GetHeight and CurrentRealmPath, which are "pure" + // NOTE: this test uses GetHeight, which are "pure" // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). f := node.(func() int64) println(f()) - node = std.CurrentRealm - g := node.(func() Realm) - println(g()) + // node = std.CurrentRealm + // g := node.(func() Realm) + // println(g()) } // Output: From 685b6223e9432d39d8b3b3d9c898995ff512a273 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:01:16 +0700 Subject: [PATCH 06/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index f3eabca0d17..7e051901140 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -13,18 +13,14 @@ func init() { func main() { // NOTE: this test uses GetHeight, which are "pure" - // natively bound functions (ie. not indirections through a wrapper fn, + // natively bound function (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). f := node.(func() int64) println(f()) - // node = std.CurrentRealm - // g := node.(func() Realm) - // println(g()) } // Output: // 123 -// gno.land/r/test // Realm: // switchrealm["gno.land/r/test"] @@ -145,8 +141,8 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "CurrentRealmPath", -// "NativeName": "CurrentRealmPath", +// "Name": "GetHeight", +// "NativeName": "GetHeight", // "NativePkg": "std", // "PkgPath": "std", // "Source": { From 6939524bf81e26a337d04e5f729a6337a7c95fa7 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:03:42 +0700 Subject: [PATCH 07/30] try ignore test --- gnovm/tests/files/zrealm_natbind0.gno | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 7e051901140..e3020f3fe59 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -15,8 +15,8 @@ func main() { // NOTE: this test uses GetHeight, which are "pure" // natively bound function (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). - f := node.(func() int64) - println(f()) + // f := node.(func() int64) + // println(f()) } // Output: From f7d94223d1456f189db8cf144ee679e7f515e4e4 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:20:37 +0700 Subject: [PATCH 08/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index e3020f3fe59..f5c7bd5294b 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,15 +12,19 @@ func init() { } func main() { - // NOTE: this test uses GetHeight, which are "pure" - // natively bound function (ie. not indirections through a wrapper fn, + // NOTE: this test uses GetHeight and CurrentRealmPath, which are "pure" + // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). - // f := node.(func() int64) - // println(f()) + f := node.(func() int64) + println(f()) + node = std.TestCurrentRealmPath + g := node.(func() string) + println(g()) } // Output: // 123 +// gno.land/r/test // Realm: // switchrealm["gno.land/r/test"] @@ -141,8 +145,8 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "GetHeight", -// "NativeName": "GetHeight", +// "Name": "CurrentRealmPath", +// "NativeName": "CurrentRealmPath", // "NativePkg": "std", // "PkgPath": "std", // "Source": { From 8af92954bd591dcc79b88d8b212b6567ed840183 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:28:17 +0700 Subject: [PATCH 09/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index f5c7bd5294b..c995ae868dd 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,14 +12,14 @@ func init() { } func main() { - // NOTE: this test uses GetHeight and CurrentRealmPath, which are "pure" + // NOTE: this test uses GetHeight and CurrentRealm, which are "pure" // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). f := node.(func() int64) println(f()) - node = std.TestCurrentRealmPath - g := node.(func() string) - println(g()) + node = std.CurrentRealm + g := node.(func() std.Realm) + println(g().PkgPath()) } // Output: From 8a5e0b2cd81456fefca797288dc387035a94fbaa Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:49:41 +0700 Subject: [PATCH 10/30] update test --- gnovm/tests/files/zrealm_natbind0.gno | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index c995ae868dd..581a9daed35 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -145,16 +145,16 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "CurrentRealmPath", -// "NativeName": "CurrentRealmPath", -// "NativePkg": "std", +// "Name": "CurrentRealm", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "std", // "Source": { // "@type": "/gno.RefNode", // "BlockNode": null, // "Location": { // "File": "native.gno", -// "Line": "5", +// "Line": "21", // "Nonce": "0", // "PkgPath": "std" // } @@ -168,8 +168,8 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" +// "@type": "/gno.RefType", +// "value": "std.Realm" // } // } // ] From 5353c64aed20171d30e299d3a2cad98caa17d96f Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Mon, 13 May 2024 23:57:06 +0700 Subject: [PATCH 11/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 581a9daed35..80a294993ab 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -130,8 +130,8 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.PrimitiveType", -// "value": "16" +// "@type": "/gno.ReqType", +// "ID": "std.Realm" // } // } // ] @@ -169,7 +169,7 @@ func main() { // "Tag": "", // "Type": { // "@type": "/gno.RefType", -// "value": "std.Realm" +// "ID": "std.Realm" // } // } // ] From 05ec2250bc2730404433e5157f87fdd2b3b014ed Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 00:01:50 +0700 Subject: [PATCH 12/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 80a294993ab..5c5ac9538fe 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -130,7 +130,7 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.ReqType", +// "@type": "/gno.RefType", // "ID": "std.Realm" // } // } From 7e53736978571968fd432ea2515309b99e11f42f Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 09:11:42 +0700 Subject: [PATCH 13/30] add deprecated old function --- gnovm/stdlibs/std/native.gno | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index ef2601eeca3..19b2c751218 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -5,6 +5,9 @@ func IsOriginCall() bool // injected func GetChainID() string // injected func GetHeight() int64 // injected +// Deprecated : use CurrentRealm().PkgPath() instead +func CurrentRealmPath() string + func GetOrigSend() Coins { den, amt := origSend() coins := make(Coins, len(den)) From 919f749c2ae4cf754ad7b867fcb6759a6a62f0e0 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 09:23:41 +0700 Subject: [PATCH 14/30] Revert "update" This reverts commit 05ec2250bc2730404433e5157f87fdd2b3b014ed. --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 5c5ac9538fe..80a294993ab 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -130,7 +130,7 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", +// "@type": "/gno.ReqType", // "ID": "std.Realm" // } // } From 79e94d17ffad2590b6f7cdbc2093cc2aa9ac8f62 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 09:29:00 +0700 Subject: [PATCH 15/30] update --- gnovm/stdlibs/std/native.gno | 3 --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 19b2c751218..ef2601eeca3 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -5,9 +5,6 @@ func IsOriginCall() bool // injected func GetChainID() string // injected func GetHeight() int64 // injected -// Deprecated : use CurrentRealm().PkgPath() instead -func CurrentRealmPath() string - func GetOrigSend() Coins { den, amt := origSend() coins := make(Coins, len(den)) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 80a294993ab..5c5ac9538fe 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -130,7 +130,7 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.ReqType", +// "@type": "/gno.RefType", // "ID": "std.Realm" // } // } From d28550425bcae68fbfda5cd303d47d47ed57a5a9 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 17:36:41 +0700 Subject: [PATCH 16/30] just pass empty context --- gnovm/stdlibs/std/emit_event_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gnovm/stdlibs/std/emit_event_test.go b/gnovm/stdlibs/std/emit_event_test.go index df032536a51..147ad75dbb5 100644 --- a/gnovm/stdlibs/std/emit_event_test.go +++ b/gnovm/stdlibs/std/emit_event_test.go @@ -14,8 +14,7 @@ import ( func TestEmit(t *testing.T) { m := gno.NewMachine("emit", nil) - elgs := sdk.NewEventLogger() - m.Context = ExecContext{EventLogger: elgs} + m.Context = ExecContext{} _, pkgPath := X_getRealm(m, 0) tests := []struct { From 576c49459e71126486e1eb3af8ee6c449f8c7569 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 17:38:03 +0700 Subject: [PATCH 17/30] leave with --- --- docs/reference/stdlibs/std/chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index d748ef9bba7..f3dddaba938 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -39,6 +39,7 @@ arguments acting as key-value pairs to be included in the emitted event. ```go std.Emit("MyEvent", "myKey1", "myValue1", "myKey2", "myValue2") ``` +--- ## GetChainID ```go From 97afe9cf0d60af96033a7962f29012f18cb82ea9 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 18:54:16 +0700 Subject: [PATCH 18/30] remove TestCurrentRealmPath --- gnovm/tests/stdlibs/native.go | 19 ------------------- gnovm/tests/stdlibs/std/std.gno | 9 ++++----- gnovm/tests/stdlibs/std/std.go | 10 ++++++---- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/gnovm/tests/stdlibs/native.go b/gnovm/tests/stdlibs/native.go index 8e14c2dd796..a2c14766dc4 100644 --- a/gnovm/tests/stdlibs/native.go +++ b/gnovm/tests/stdlibs/native.go @@ -50,25 +50,6 @@ var nativeFuncs = [...]nativeFunc{ )) }, }, - { - "std", - "TestCurrentRealmPath", - []gno.FieldTypeExpr{}, - []gno.FieldTypeExpr{ - {Name: gno.N("r0"), Type: gno.X("string")}, - }, - func(m *gno.Machine) { - r0 := testlibs_std.TestCurrentRealmPath( - m, - ) - - m.PushValue(gno.Go2GnoValue( - m.Alloc, - m.Store, - reflect.ValueOf(&r0).Elem(), - )) - }, - }, { "std", "TestSkipHeights", diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index 1d3aad1285a..41543d6497c 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,10 +1,9 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected -func TestCurrentRealmPath() string // injected -func TestSkipHeights(count int64) // injected -func ClearStoreCache() // injected +func AssertOriginCall() // injected +func IsOriginCall() bool // injected +func TestSkipHeights(count int64) // injected +func ClearStoreCache() // injected func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index f0d4eda7636..940603fa456 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -39,10 +39,6 @@ func IsOriginCall(m *gno.Machine) bool { panic("unable to determine if test is a _test or a _filetest") } -func TestCurrentRealmPath(m *gno.Machine) string { - return m.Realm.Path -} - func TestSkipHeights(m *gno.Machine, count int64) { ctx := m.Context.(std.ExecContext) ctx.Height += count @@ -118,3 +114,9 @@ func X_testIssueCoins(m *gno.Machine, addr string, denom []string, amt []int64) banker.IssueCoin(crypto.Bech32Address(addr), denom[i], amt[i]) } } + +func X_testCurrentRealm(m *gno.Machine) { + ctx := m.Context.(std.ExecContext) + ctx.OrigPkgAddr = crypto.Bech32Address(addr) + m.Context = ctx +} From 3fb43ce082747fa6dec0db120b1c2529bee79a03 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 18:58:41 +0700 Subject: [PATCH 19/30] update --- gnovm/tests/stdlibs/std/std.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index 940603fa456..0f120e929e3 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -114,9 +114,3 @@ func X_testIssueCoins(m *gno.Machine, addr string, denom []string, amt []int64) banker.IssueCoin(crypto.Bech32Address(addr), denom[i], amt[i]) } } - -func X_testCurrentRealm(m *gno.Machine) { - ctx := m.Context.(std.ExecContext) - ctx.OrigPkgAddr = crypto.Bech32Address(addr) - m.Context = ctx -} From 0f2a4b6aad3f9969ce02cb14236380c1efb3b3fc Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 19:00:50 +0700 Subject: [PATCH 20/30] comment old testcase --- gnovm/tests/files/zrealm12.gno | 35 ++++++++++++++----------------- gnovm/tests/files/zrealm_std3.gno | 10 ++++----- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index 62b96a29af3..e029a5eb2b4 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -8,25 +8,22 @@ import ( ) func main() { - if std.TestCurrentRealmPath() != "gno.land/r/test" { - panic("should not happen") - } - tests.InitTestNodes() - if std.TestCurrentRealmPath() != "gno.land/r/test" { - panic("should not happen") - } - tests.ModTestNodes() - if std.TestCurrentRealmPath() != "gno.land/r/test" { - panic("should not happen") - } - std.ClearStoreCache() - if std.TestCurrentRealmPath() != "gno.land/r/test" { - panic("should not happen") - } - tests.PrintTestNodes() - if std.TestCurrentRealmPath() != "gno.land/r/test" { - panic("should not happen") - } + // tests.InitTestNodes() + // if std.TestCurrentRealmPath() != "gno.land/r/test" { + // panic("should not happen") + // } + // tests.ModTestNodes() + // if std.TestCurrentRealmPath() != "gno.land/r/test" { + // panic("should not happen") + // } + // std.ClearStoreCache() + // if std.TestCurrentRealmPath() != "gno.land/r/test" { + // panic("should not happen") + // } + // tests.PrintTestNodes() + // if std.TestCurrentRealmPath() != "gno.land/r/test" { + // panic("should not happen") + // } } // Output: diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index 790098b74f7..4aa4122a1a6 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -5,13 +5,13 @@ import ( "std" ) -func foo() { - println("foo", std.TestCurrentRealmPath()) -} +// func foo() { +// println("foo", std.TestCurrentRealmPath()) +// } func main() { - println("main", std.TestCurrentRealmPath()) - foo() + // println("main", std.TestCurrentRealmPath()) + // foo() } // Output: From ab4da6308220876154f1797a29608b9d6d9bca25 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 19:03:56 +0700 Subject: [PATCH 21/30] update --- gnovm/tests/files/zrealm12.gno | 6 ------ gnovm/tests/files/zrealm_std3.gno | 4 ---- 2 files changed, 10 deletions(-) diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index e029a5eb2b4..101213f5636 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -1,12 +1,6 @@ // PKGPATH: gno.land/r/test package test -import ( - "std" - - "gno.land/r/demo/tests" -) - func main() { // tests.InitTestNodes() // if std.TestCurrentRealmPath() != "gno.land/r/test" { diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index 4aa4122a1a6..c37f4915650 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -1,10 +1,6 @@ // PKGPATH: gno.land/r/std_test package std_test -import ( - "std" -) - // func foo() { // println("foo", std.TestCurrentRealmPath()) // } From 41b9d122941dedd2db3b5e71de6ac1ebfe8bc1c5 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 19:07:52 +0700 Subject: [PATCH 22/30] update --- gnovm/tests/files/zrealm12.gno | 3 --- gnovm/tests/files/zrealm_std3.gno | 4 ---- 2 files changed, 7 deletions(-) diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index 101213f5636..b38bfbc9466 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -19,6 +19,3 @@ func main() { // panic("should not happen") // } } - -// Output: -// second's child diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index c37f4915650..6d6eff683de 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -9,7 +9,3 @@ func main() { // println("main", std.TestCurrentRealmPath()) // foo() } - -// Output: -// main gno.land/r/std_test -// foo gno.land/r/std_test From 62305ac66cca6a0a3a5981cb5d68501de47ce137 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 20:48:00 +0700 Subject: [PATCH 23/30] change to GetChainID --- gnovm/tests/files/zrealm_natbind0.gno | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 5c5ac9538fe..a99998e3bf7 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -12,19 +12,19 @@ func init() { } func main() { - // NOTE: this test uses GetHeight and CurrentRealm, which are "pure" + // NOTE: this test uses GetHeight and GetChainID, which are "pure" // natively bound functions (ie. not indirections through a wrapper fn, // to convert the types to builtin go/gno identifiers). f := node.(func() int64) println(f()) - node = std.CurrentRealm + node = std.GetChainID g := node.(func() std.Realm) - println(g().PkgPath()) + println(g()) } // Output: // 123 -// gno.land/r/test +// test // Realm: // switchrealm["gno.land/r/test"] @@ -130,7 +130,7 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", +// "@type": "/gno.PrimitiveType", // "ID": "std.Realm" // } // } @@ -145,7 +145,7 @@ func main() { // }, // "FileName": "native.gno", // "IsMethod": false, -// "Name": "CurrentRealm", +// "Name": "GetChainID", // "NativeName": "", // "NativePkg": "", // "PkgPath": "std", @@ -154,7 +154,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "native.gno", -// "Line": "21", +// "Line": "5", // "Nonce": "0", // "PkgPath": "std" // } From 81bd96b0edb4447e6c87460a9a306c0361ba50d1 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 20:48:22 +0700 Subject: [PATCH 24/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index a99998e3bf7..c69dbf4cc52 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -18,7 +18,7 @@ func main() { f := node.(func() int64) println(f()) node = std.GetChainID - g := node.(func() std.Realm) + g := node.(func() string) println(g()) } From a26864cd1255e949672b0a1cc7cd4a8c24abd0d6 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 20:53:41 +0700 Subject: [PATCH 25/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index c69dbf4cc52..fdb0d873f80 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -24,7 +24,7 @@ func main() { // Output: // 123 -// test +// dev // Realm: // switchrealm["gno.land/r/test"] From 10177c107799a2d1b6e5a5dc154bbf397147c9da Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 14 May 2024 20:59:41 +0700 Subject: [PATCH 26/30] update --- gnovm/tests/files/zrealm_natbind0.gno | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index fdb0d873f80..9cf0e809ece 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -131,7 +131,7 @@ func main() { // "Tag": "", // "Type": { // "@type": "/gno.PrimitiveType", -// "ID": "std.Realm" +// "value": "16" // } // } // ] @@ -146,8 +146,8 @@ func main() { // "FileName": "native.gno", // "IsMethod": false, // "Name": "GetChainID", -// "NativeName": "", -// "NativePkg": "", +// "NativeName": "GetChainID", +// "NativePkg": "std", // "PkgPath": "std", // "Source": { // "@type": "/gno.RefNode", @@ -168,8 +168,8 @@ func main() { // "Name": "", // "Tag": "", // "Type": { -// "@type": "/gno.RefType", -// "ID": "std.Realm" +// "@type": "/gno.PrimitiveType", +// "value": "16" // } // } // ] From bb53827ed80ef0d59119a61c7081605d50be6764 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Wed, 15 May 2024 13:32:52 +0700 Subject: [PATCH 27/30] remove from doc --- docs/reference/stdlibs/std/testing.md | 11 ----------- gnovm/tests/files/zrealm12.gno | 16 ---------------- gnovm/tests/files/zrealm_std3.gno | 6 ------ 3 files changed, 33 deletions(-) diff --git a/docs/reference/stdlibs/std/testing.md b/docs/reference/stdlibs/std/testing.md index 10c5016e0b9..102b9ed6d70 100644 --- a/docs/reference/stdlibs/std/testing.md +++ b/docs/reference/stdlibs/std/testing.md @@ -5,7 +5,6 @@ id: testing # Testing ```go -func TestCurrentRealmPath() string func TestSkipHeights(count int64) func TestSetOrigCaller(addr Address) func TestSetOrigPkgAddr(addr Address) @@ -13,16 +12,6 @@ func TestSetOrigSend(sent, spent Coins) func TestIssueCoins(addr Address, coins Coins) ``` -## TestCurrentRealmPath -```go -func TestCurrentRealmPath() string -``` -Returns the current realm path. - -#### Usage -```go -currentRealmPath := std.TestCurrentRealmPath() -``` --- ## TestSkipHeights diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index b38bfbc9466..d207e39094a 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -2,20 +2,4 @@ package test func main() { - // tests.InitTestNodes() - // if std.TestCurrentRealmPath() != "gno.land/r/test" { - // panic("should not happen") - // } - // tests.ModTestNodes() - // if std.TestCurrentRealmPath() != "gno.land/r/test" { - // panic("should not happen") - // } - // std.ClearStoreCache() - // if std.TestCurrentRealmPath() != "gno.land/r/test" { - // panic("should not happen") - // } - // tests.PrintTestNodes() - // if std.TestCurrentRealmPath() != "gno.land/r/test" { - // panic("should not happen") - // } } diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index 6d6eff683de..68dd6142c46 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -1,11 +1,5 @@ // PKGPATH: gno.land/r/std_test package std_test -// func foo() { -// println("foo", std.TestCurrentRealmPath()) -// } - func main() { - // println("main", std.TestCurrentRealmPath()) - // foo() } From 3289c64d12a1a893c74dc66112a25171a5a50581 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Wed, 15 May 2024 14:04:03 +0700 Subject: [PATCH 28/30] uncomment tests --- gnovm/tests/files/zrealm12.gno | 16 ++++++++++++++++ gnovm/tests/files/zrealm_std3.gno | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index d207e39094a..ee9a864f423 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -2,4 +2,20 @@ package test func main() { + tests.InitTestNodes() + if std.CurrentRealm().PkgPath() != "gno.land/r/test" { + panic("should not happen") + } + tests.ModTestNodes() + if std.CurrentRealm().PkgPath() != "gno.land/r/test" { + panic("should not happen") + } + std.ClearStoreCache() + if std.CurrentRealm().PkgPath() != "gno.land/r/test" { + panic("should not happen") + } + tests.PrintTestNodes() + if std.CurrentRealm().PkgPath() != "gno.land/r/test" { + panic("should not happen") + } } diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index 68dd6142c46..80d36db2545 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -1,5 +1,15 @@ // PKGPATH: gno.land/r/std_test package std_test +func foo() { + println("foo", std.CurrentRealm().PkgPath()) +} + func main() { + println("main", std.CurrentRealm().PkgPath()) + foo() } + +// Output: +// main gno.land/r/std_test +// foo gno.land/r/std_test From 072a2eec942b6e1eb78f692cf3b490ca14044466 Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Wed, 15 May 2024 14:11:01 +0700 Subject: [PATCH 29/30] import std --- gnovm/tests/files/zrealm12.gno | 4 ++++ gnovm/tests/files/zrealm_std3.gno | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/gnovm/tests/files/zrealm12.gno b/gnovm/tests/files/zrealm12.gno index ee9a864f423..ee9e85d827b 100644 --- a/gnovm/tests/files/zrealm12.gno +++ b/gnovm/tests/files/zrealm12.gno @@ -1,6 +1,10 @@ // PKGPATH: gno.land/r/test package test +import ( + "std" +) + func main() { tests.InitTestNodes() if std.CurrentRealm().PkgPath() != "gno.land/r/test" { diff --git a/gnovm/tests/files/zrealm_std3.gno b/gnovm/tests/files/zrealm_std3.gno index 80d36db2545..4f1d1bc827a 100644 --- a/gnovm/tests/files/zrealm_std3.gno +++ b/gnovm/tests/files/zrealm_std3.gno @@ -1,6 +1,10 @@ // PKGPATH: gno.land/r/std_test package std_test +import ( + "std" +) + func foo() { println("foo", std.CurrentRealm().PkgPath()) } From f9689f506116c3d7e5d561ecbbfc2494e8986082 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 23 May 2024 12:26:14 +0200 Subject: [PATCH 30/30] create currentRealm helper --- gnovm/stdlibs/std/emit_event.go | 2 +- gnovm/stdlibs/std/native.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gnovm/stdlibs/std/emit_event.go b/gnovm/stdlibs/std/emit_event.go index 9c591f61150..8e61f67d58a 100644 --- a/gnovm/stdlibs/std/emit_event.go +++ b/gnovm/stdlibs/std/emit_event.go @@ -17,7 +17,7 @@ func X_emit(m *gno.Machine, typ string, attrs []string) { m.Panic(typedString(err.Error())) } - _, pkgPath := X_getRealm(m, 0) + _, pkgPath := currentRealm(m) fnIdent := getPrevFunctionNameFromTarget(m, "Emit") evt := gnoEvent{ diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index 963d90391c9..7148a4ba4f4 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -91,7 +91,7 @@ func X_callerAt(m *gno.Machine, n int) string { return string(m.MustLastCallFrame(n).LastPackage.GetPkgAddr().Bech32()) } -func X_getRealm(m *gno.Machine, height int) (address string, pkgPath string) { +func X_getRealm(m *gno.Machine, height int) (address, pkgPath string) { var ( ctx = m.Context.(ExecContext) currentCaller crypto.Bech32Address @@ -123,6 +123,12 @@ func X_getRealm(m *gno.Machine, height int) (address string, pkgPath string) { return string(ctx.OrigCaller), "" } +// currentRealm retrieves the current realm's address and pkgPath. +// It's not a native binding; but is used within this package to clarify usage. +func currentRealm(m *gno.Machine) (address, pkgPath string) { + return X_getRealm(m, 0) +} + func X_derivePkgAddr(pkgPath string) string { return string(gno.DerivePkgAddr(pkgPath).Bech32()) }