Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Villaquiranm committed Jun 1, 2024
1 parent e7ade2c commit 6e9ceab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,10 @@ func isUnsaved(oo Object) bool {
// be realms and as such to have their state persisted. This is used by [IsRealmPath].
const realmPathPrefix = "gno.land/r/"

// pkgPathPrefix is the prefix used to identify pkgpaths which are meant to
// be pure packages. This is used by [IsPkgPath].
const pkgPathPrefix = "gno.land/p/"

var ReGnoRunPath = regexp.MustCompile(`^gno\.land/r/g[a-z0-9]+/run$`)

// IsRealmPath determines whether the given pkgpath is for a realm, and as such
Expand All @@ -1528,6 +1532,10 @@ func IsRealmPath(pkgPath string) bool {
!ReGnoRunPath.MatchString(pkgPath)
}

func IsPkgPath(pkgPath string) bool {
return strings.HasPrefix(pkgPath, pkgPathPrefix)
}

func prettyJSON(jstr []byte) []byte {
var c interface{}
err := json.Unmarshal(jstr, &c)
Expand Down
5 changes: 5 additions & 0 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,11 @@ func (pv *PackageValue) IsRealm() bool {
return IsRealmPath(pv.PkgPath)
}

// IsPkgPath returns true if pv represents a package path.
func (pv *PackageValue) IsPkgPath() bool {
return IsPkgPath(pv.PkgPath)
}

func (pv *PackageValue) getFBlocksMap() map[Name]*Block {
if pv.fBlocksMap == nil {
pv.fBlocksMap = make(map[Name]*Block, len(pv.FNames))
Expand Down
2 changes: 1 addition & 1 deletion gnovm/stdlibs/std/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func X_decodeBech32(addr string) (prefix string, bytes [20]byte, ok bool) {

func X_assertCallerIsRealm(m *gno.Machine) {
frame := m.Frames[m.NumFrames()-2]
if !frame.LastPackage.IsRealm() {
if frame.LastPackage.IsPkgPath() {
m.Panic(typedString("caller is not a realm"))
}
}
Expand Down

0 comments on commit 6e9ceab

Please sign in to comment.