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

API design for std.TestSetPrevRealm #1345

Open
thehowl opened this issue Nov 8, 2023 · 0 comments
Open

API design for std.TestSetPrevRealm #1345

thehowl opened this issue Nov 8, 2023 · 0 comments
Labels
📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Nov 8, 2023

Creating this issue following a discussion with @albttx on how to best implement what was started by @r3v4s in #891, std.TestSetPrevRealm.

What Albert and r3v4s are working on a is a TestSetPrevRealm function which would work similarly to the existing TestSetOrigCaller. However, since PrevRealm works on stack frames, for clarity and implementation simplicity, a system like the following might be better:

std.TestWithPrevRealm("gno.land/r/demo/1234", func() {
   // ... 
})

// for instance:

func TestX(t *testing.T) {
	for _, pr := range [...]string{
		"gno.land/r/demo/x",
		"gno.land/r/demo/y",
	} {
		std.TestWithPrevRealm(pr, doXTest(t, pr))
	}
}

const allowedRealm = "gno.land/r/demo/x"

func doXTest(t *testing.T, prev string) func() {
	return func() {
		defer func() {
			r := recover() 
			if (prev == allowedRealm && r != nil) ||
				(prev != allowedRealm && r == nil) {
				t.Errorf("invalid panic %v when calling myrealm.X with caller %q", r, prev)
			}
		}()
		myrealm.X()
	}
}
@thehowl thehowl added the 📦 🤖 gnovm Issues or PRs gnovm related label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

No branches or pull requests

1 participant