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: std.TestSetPrevRealm #890

Closed
wants to merge 1 commit into from
Closed

feat: std.TestSetPrevRealm #890

wants to merge 1 commit into from

Conversation

r3v4s
Copy link
Contributor

@r3v4s r3v4s commented Jun 13, 2023

@r3v4s r3v4s requested a review from a team as a code owner June 13, 2023 06:53
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages. labels Jun 13, 2023
@r3v4s r3v4s closed this Jun 13, 2023
thehowl added a commit that referenced this pull request May 29, 2024
This PR removes the `TestSetPrevRealm` and `TestSetPrevAddr`, added in
#890, in favour of a new API `TestSetRealm`, which is more flexible in
its behaviour.

The function works by setting the result of `CurrentRealm()` for the
frame in which the `TestSetRealm` function is called. Consequently,
calling `PrevRealm` in any function called within will yield the value
passed to `TestSetRealm`.

`TestSetRealm` allows to transparently set "user" and "code" realms, by
using two new costructors in the testing stdlibs, `std.NewUserRealm` and
`std.NewCodeRealm`, allowing emulation of both kinds of callers.

The call is not `TestSetPrevRealm` as it does not permanently "set" the
value returned by PrevRealm, as if in a mock; it simply changes the
Realm of the current frame, allowing "deep" calls to PrevRealm() to
correctly return the value of the previous realm.


<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
omarsy pushed a commit to TERITORI/gno that referenced this pull request Jun 3, 2024
…2164)

This PR removes the `TestSetPrevRealm` and `TestSetPrevAddr`, added in
gnolang#890, in favour of a new API `TestSetRealm`, which is more flexible in
its behaviour.

The function works by setting the result of `CurrentRealm()` for the
frame in which the `TestSetRealm` function is called. Consequently,
calling `PrevRealm` in any function called within will yield the value
passed to `TestSetRealm`.

`TestSetRealm` allows to transparently set "user" and "code" realms, by
using two new costructors in the testing stdlibs, `std.NewUserRealm` and
`std.NewCodeRealm`, allowing emulation of both kinds of callers.

The call is not `TestSetPrevRealm` as it does not permanently "set" the
value returned by PrevRealm, as if in a mock; it simply changes the
Realm of the current frame, allowing "deep" calls to PrevRealm() to
correctly return the value of the previous realm.


<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
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 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant