Skip to content

Commit

Permalink
add realmtest
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Oct 19, 2023
1 parent ec4d717 commit 75b1d10
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
24 changes: 24 additions & 0 deletions examples/gno.land/p/demo/tests/p_crossrealm/p_crossrealm.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package p_crossrealm

type Stringer interface {
String() string
}

type Container struct {
A int
B Stringer
}

func (c *Container) Touch() *Container {
c.A += 1
return c
}

func (c *Container) Print() {
println("A:", c.A)
if c.B == nil {
println("B: undefined")
} else {
println("B:", c.B.String())
}
}
29 changes: 29 additions & 0 deletions examples/gno.land/r/demo/tests/crossrealm/crossrealm.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package crossrealm

import (
"gno.land/p/demo/tests/p_crossrealm"
"gno.land/p/demo/ufmt"
)

type LocalStruct struct {
A int
}

func (ls *LocalStruct) String() string {
return ufmt.Sprintf("LocalStruct{%d}", ls.A)
}

// local is saved locally in this realm
var local *LocalStruct

func init() {
local = &LocalStruct{A: 123}
}

// Make1 returns a local object wrapped by a p struct
func Make1() *p_crossrealm.Container {
return &p_crossrealm.Container{
A: 1,
B: local,
}
}
6 changes: 5 additions & 1 deletion gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ func (m *Machine) RunMemPackage(memPkg *std.MemPackage, save bool) (*PackageNode
} else {
pn = NewPackageNode(Name(memPkg.Name), memPkg.Path, &FileSet{})
pv = pn.NewPackage()
m.Store.SetBlockNode(pn)
if true { // TODO finish SetBlockNode()
m.Store.SetBlockNode(pn)
} else {
// TODO m.Store.SetCacheBlockNode(pn)
}

Check warning on line 228 in gnovm/pkg/gnolang/machine.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L224-L228

Added lines #L224 - L228 were not covered by tests
m.Store.SetCachePackage(pv)
}
m.SetActivePackage(pv)
Expand Down
17 changes: 17 additions & 0 deletions gnovm/tests/files/zrealm_crossrealm13.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// PKGPATH: gno.land/r/crossrealm_test
package crossrealm_test

import (
crossrealm "gno.land/r/demo/tests/crossrealm"
)

func main() {
// even though we are running within a realm,
// we aren't storing the result of crossrealm.Make1(),
// so this should print fine.
crossrealm.Make1().Touch().Print()
}

// Output:
// A: 2
// B: LocalStruct{123}

0 comments on commit 75b1d10

Please sign in to comment.