-
Notifications
You must be signed in to change notification settings - Fork 385
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 #891
Conversation
Thanks for raising this, I checked on my side and I noticed an other issue related to
func IsRealmPath(pkgPath string) bool {
// TODO: make it more distinct to distinguish from normal paths.
if strings.HasPrefix(pkgPath, "gno.land/r/") {
return true
} else {
return false
}
} The problem is that realms under I'll try to provide a fix and see if that solves also the problem you raised. |
@tbruyelle Thanks for response. I found other issue in this pr maybe related your If I pass weird string to Would be nice if your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 💯
I've left some comments that should be addressed, and pinged a few people to take another look.
Please check out @tbruyelle's recent comment 🙏
Just removed logic for setting caller to PrevRealm, looks like |
e5ac89a
to
3faaf96
Compare
|
c798bca
to
82c2cb6
Compare
update: remove nested testcase, and made simple one in |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #891 +/- ##
=======================================
Coverage 47.51% 47.51%
=======================================
Files 388 388
Lines 61331 61331
=======================================
Hits 29144 29144
Misses 29747 29747
Partials 2440 2440 ☔ View full report in Codecov by Sentry. |
See comment #891 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to inject a TestSetPrevRealm as a native method for testing.
We will need a separate RFC for the reasons outlined below:
Given the numerous incidents on other chains where millions were mistakenly sent to contract addresses instead of user addresses, it's crucial that we distinguish between contract entities (represented by package paths) and EOA (Externally Owned Account) entities (represented by addresses) in gno contract.
-
Instead of returning an address for PrevRealm, we should return the realm package.
-
Furthermore, we need to address the ambiguity between returning user account addresses and realm identity from PrevRealm. We might want to explicitly check the returned value to determine whether we are validating an EOA or a contract for entry method we try guard.
-
Not sure we have enough strong use cases where we had to pass contract addresses instead of realm package paths between contracts in gno.
here is short briefing for why I implemented it. let's say... certain contact want to receive grc20 token from user(wallet, address). # gno.mod ( gno.land/r/demo/receive )
# contract_test.gno
import (
"std"
"testing"
foo "gno.land/r/demo/foo20"
)
const sender = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
func TestFunc(t *testing.T) {
std.TestSetOrigCaller(sender)
foo.Transfer(std.GetOrigPkgAddr(), "12345")
} because
actual caller will be same with |
Keeping the comment for the edit history, but I'll need to take another look at this, nevermind what I just said |
So, I did a second review and agreed that the approach here is not correct.
I have been discussing about this with @albttx on how to best do this and he's working on a PR to iterate and improve on your work, @r3v4s. I also have some ideas on a different API we could have for the For @piux2's concerns,
We should, (or at least have a similar mechanism), otherwise the only way to test a realm when being called from other realms is through filetests, which I personally think is inflexible (ie. can't create table tests, trying to call from different realms) and creates pollution in a realm's directory as a realm grows in complexity.
This is still one of the design goals in the implementation of
PrevRealms should have addresses, as realms have addresses with funds, and a caller may be looking for that information. |
So I though I fixed that last week but I probably forgot to click the button... This comment from me mentions the wrong PR, I wanted to mention this PR #896, which is merged since a long time ago. IMO, this PR mitigates the needs of The way this works is the following, if there's a gno.mod file, the realm is the one from the gno.mod, so the _test shares the same realm as the tested realm. If there's no gno.mod file, the realm of the _test is generated randomly, so it's different from the tested realm. Looks weird when read like that but anyway I don't think _test files should be used to test _filtest on the other hand are goods for PrevRealm testing, and for them the solution exists from the beginning, you just need to add a |
I don't think it's a good idea to manually manipulate the frames. The thing is complex enough, let's not add other way to confuse ourselves. |
@tbruyelle my comment goes in a direction of removing filetests which I kind of had subconsciously but hadn't written/talked about it yet 😛 . I've created an issue so we can discuss that and understand if it is a common feeling / my proposal makes sense: #1346 |
49929f2
to
4764a84
Compare
057a7a9
to
201a27f
Compare
Comments not replied to since October, even though Blake resolved and pinged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revisiting this - We should definitely have TestSetPrevRealm
, just like we do with other ctx
variables.
@r3v4s, can you please write txtar tests for this, and possibly simplify them to not use a separate package)? 🙏
@leohhhn I don't think with |
Merged |
<!-- Please provide a brief summary of your changes in the Title above --> # Description Thanks to @albttx, we now have `std.PrevRealm` gnolang#667 However it seems like doesn't work on testcase(that can be run by `gno test` command) as what we expected. > `gno test` uses its own Context which makes few other functions (like GetRealmPath) doesn't work neither. So I made little helper very similar to `std.TestSetOrigCaller` --- ## Discussion Need `std.TestSetOrigCaller` takes single parameter and two different type can be passed 1. If `std.Address` type is passed, -> TestSetPrevRealm will take it as user address => return user address not realm. 2. If `string` type is passed, -> TestSetPrevRealm will take it as pkg_path => return pkg address(using bech32) and pkg_path > Since string parameter is being used without any verification in this pr, How about reusing verification logic from here ??https://github.com/gnolang/gno/blob/408fc68d4b3c189dbc6a608c590a86c661ae232a/tm2/pkg/std/memfile.go#L33-L68 ## Contributors Checklist - [x] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests ## Maintainers Checklist - [x] Checked that the author followed the guidelines in `CONTRIBUTING.md` - [x] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body) - [x] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change
<!-- Please provide a brief summary of your changes in the Title above --> # Description Thanks to @albttx, we now have `std.PrevRealm` gnolang#667 However it seems like doesn't work on testcase(that can be run by `gno test` command) as what we expected. > `gno test` uses its own Context which makes few other functions (like GetRealmPath) doesn't work neither. So I made little helper very similar to `std.TestSetOrigCaller` --- ## Discussion Need `std.TestSetOrigCaller` takes single parameter and two different type can be passed 1. If `std.Address` type is passed, -> TestSetPrevRealm will take it as user address => return user address not realm. 2. If `string` type is passed, -> TestSetPrevRealm will take it as pkg_path => return pkg address(using bech32) and pkg_path > Since string parameter is being used without any verification in this pr, How about reusing verification logic from here ??https://github.com/gnolang/gno/blob/408fc68d4b3c189dbc6a608c590a86c661ae232a/tm2/pkg/std/memfile.go#L33-L68 ## Contributors Checklist - [x] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests ## Maintainers Checklist - [x] Checked that the author followed the guidelines in `CONTRIBUTING.md` - [x] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body) - [x] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change
Description
Thanks to @albttx, we now have
std.PrevRealm
#667However it seems like doesn't work on testcase(that can be run by
gno test
command) as what we expected.So I made little helper very similar to
std.TestSetOrigCaller
Discussion Need
std.TestSetOrigCaller
takes single parameter and two different type can be passedstd.Address
type is passed, -> TestSetPrevRealm will take it as user address => return user address not realm.string
type is passed, -> TestSetPrevRealm will take it as pkg_path => return pkg address(using bech32) and pkg_pathContributors Checklist
BREAKING CHANGE: xxx
message was included in the descriptionMaintainers Checklist
CONTRIBUTING.md
BREAKING CHANGE:
in the body)