Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlibs/std)!: remove std.CurrentRealmPath #2087

Merged
merged 45 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7f16c88
deprecate & remove std.CurrentRealmPath()
linhpn99 May 13, 2024
996eacc
rebase master
linhpn99 May 13, 2024
7b38041
remove go function CurrentRealmPath
linhpn99 May 13, 2024
5bd2bbe
rename func
linhpn99 May 13, 2024
39a776d
update
linhpn99 May 13, 2024
a602c46
update
linhpn99 May 13, 2024
685b622
update
linhpn99 May 13, 2024
6939524
try ignore test
linhpn99 May 13, 2024
f7d9422
update
linhpn99 May 13, 2024
796eea2
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 13, 2024
8af9295
update
linhpn99 May 13, 2024
10b81a8
Merge branch 'removeCurrentRealmPath' of https://github.com/linhpn99/…
linhpn99 May 13, 2024
8a5e0b2
update test
linhpn99 May 13, 2024
5353c64
update
linhpn99 May 13, 2024
05ec225
update
linhpn99 May 13, 2024
7e53736
add deprecated old function
linhpn99 May 14, 2024
919f749
Revert "update"
linhpn99 May 14, 2024
79e94d1
update
linhpn99 May 14, 2024
d285504
just pass empty context
linhpn99 May 14, 2024
576c494
leave with ---
linhpn99 May 14, 2024
97afe9c
remove TestCurrentRealmPath
linhpn99 May 14, 2024
3fb43ce
update
linhpn99 May 14, 2024
0f2a4b6
comment old testcase
linhpn99 May 14, 2024
ab4da63
update
linhpn99 May 14, 2024
41b9d12
update
linhpn99 May 14, 2024
62305ac
change to GetChainID
linhpn99 May 14, 2024
81bd96b
update
linhpn99 May 14, 2024
a26864c
update
linhpn99 May 14, 2024
10177c1
update
linhpn99 May 14, 2024
556e4e7
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 14, 2024
267948d
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 15, 2024
ec21083
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 15, 2024
bb53827
remove from doc
linhpn99 May 15, 2024
003fdfb
Merge branch 'removeCurrentRealmPath' of https://github.com/linhpn99/…
linhpn99 May 15, 2024
3289c64
uncomment tests
linhpn99 May 15, 2024
072a2ee
import std
linhpn99 May 15, 2024
4a4a43d
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 15, 2024
e9839e8
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 15, 2024
f1a1021
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 17, 2024
887ae31
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 18, 2024
4d41ef2
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 22, 2024
5e7f411
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 22, 2024
623d95f
Merge branch 'master' into removeCurrentRealmPath
linhpn99 May 23, 2024
f9689f5
create currentRealm helper
thehowl May 23, 2024
e12da9c
Merge branch 'removeCurrentRealmPath' of github.com:linhpn99/gno into…
thehowl May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/concepts/stdlibs/gnopher-hole.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ std.Emit("MyEvent", "myKey1", "myValue1", "myKey2", "myValue2")
```
---

## 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
func GetChainID() string
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/stdlibs/std/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ id: testing
# Testing

```go
func TestCurrentRealm() string
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
func TestCurrentRealmPath() string
func TestSkipHeights(count int64)
func TestSetOrigCaller(addr Address)
func TestSetOrigPkgAddr(addr Address)
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()
```
---

Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/tests/tests.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func IncCounter() {
}

func CurrentRealmPath() string {
return std.CurrentRealmPath()
return std.CurrentRealm().PkgPath()
}

//----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/tests/tests.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Counter() int {
}

func CurrentRealmPath() string {
return std.CurrentRealmPath()
return std.CurrentRealm().PkgPath()
}

var initOrigCaller = std.GetOrigCaller()
Expand Down
19 changes: 0 additions & 19 deletions gnovm/stdlibs/native.go

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

2 changes: 1 addition & 1 deletion gnovm/stdlibs/std/emit_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion gnovm/stdlibs/std/emit_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (

func TestEmit(t *testing.T) {
m := gno.NewMachine("emit", nil)
pkgPath := CurrentRealmPath(m)

m.Context = ExecContext{}

_, pkgPath := X_getRealm(m, 0)
tests := []struct {
name string
eventType string
Expand Down
9 changes: 4 additions & 5 deletions gnovm/stdlibs/std/native.gno
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package std

func AssertOriginCall() // injected
func IsOriginCall() bool // injected
func CurrentRealmPath() string // injected
func GetChainID() string // injected
func GetHeight() int64 // injected
func AssertOriginCall() // injected
func IsOriginCall() bool // injected
func GetChainID() string // injected
func GetHeight() int64 // injected

func GetOrigSend() Coins {
den, amt := origSend()
Expand Down
7 changes: 0 additions & 7 deletions gnovm/stdlibs/std/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions gnovm/stdlibs/stdshim/stdshim.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ func Hash(bz []byte) (hash [20]byte) {
return
}

func CurrentRealmPath() string {
panic(shimWarn)
return ""
}

func GetChainID() string {
panic(shimWarn)
return ""
Expand Down
44 changes: 16 additions & 28 deletions gnovm/tests/files/zrealm12.gno
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
// PKGPATH: gno.land/r/test
package test

import (
"std"

"gno.land/r/demo/tests"
)

func main() {
if std.TestCurrentRealm() != "gno.land/r/test" {
panic("should not happen")
}
tests.InitTestNodes()
if std.TestCurrentRealm() != "gno.land/r/test" {
panic("should not happen")
}
tests.ModTestNodes()
if std.TestCurrentRealm() != "gno.land/r/test" {
panic("should not happen")
}
std.ClearStoreCache()
if std.TestCurrentRealm() != "gno.land/r/test" {
panic("should not happen")
}
tests.PrintTestNodes()
if std.TestCurrentRealm() != "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:
// second's child
10 changes: 5 additions & 5 deletions gnovm/tests/files/zrealm_natbind0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ func init() {
}

func main() {
// NOTE: this test uses GetHeight and CurrentRealmPath, 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.CurrentRealmPath
thehowl marked this conversation as resolved.
Show resolved Hide resolved
node = std.GetChainID
g := node.(func() string)
println(g())
}

// Output:
// 123
// gno.land/r/test
// dev

// Realm:
// switchrealm["gno.land/r/test"]
Expand Down Expand Up @@ -145,8 +145,8 @@ func main() {
// },
// "FileName": "native.gno",
// "IsMethod": false,
// "Name": "CurrentRealmPath",
// "NativeName": "CurrentRealmPath",
// "Name": "GetChainID",
// "NativeName": "GetChainID",
// "NativePkg": "std",
// "PkgPath": "std",
// "Source": {
Expand Down
18 changes: 5 additions & 13 deletions gnovm/tests/files/zrealm_std3.gno
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
// PKGPATH: gno.land/r/std_test
package std_test

import (
"std"
)

func foo() {
println("foo", std.CurrentRealmPath())
}
// func foo() {
// println("foo", std.TestCurrentRealmPath())
// }

func main() {
println("main", std.CurrentRealmPath())
foo()
// println("main", std.TestCurrentRealmPath())
// foo()
}

// Output:
// main gno.land/r/std_test
// foo gno.land/r/std_test
19 changes: 0 additions & 19 deletions gnovm/tests/stdlibs/native.go

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

2 changes: 1 addition & 1 deletion gnovm/tests/stdlibs/std/std.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package std

func AssertOriginCall() // injected
func IsOriginCall() bool // injected
func TestCurrentRealm() string // injected
func TestSkipHeights(count int64) // injected
func ClearStoreCache() // injected

Expand All @@ -13,6 +12,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)
Expand Down
4 changes: 0 additions & 4 deletions gnovm/tests/stdlibs/std/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func IsOriginCall(m *gno.Machine) bool {
panic("unable to determine if test is a _test or a _filetest")
}

func TestCurrentRealm(m *gno.Machine) string {
return m.Realm.Path
}

func TestSkipHeights(m *gno.Machine, count int64) {
ctx := m.Context.(std.ExecContext)
ctx.Height += count
Expand Down
Loading