-
Notifications
You must be signed in to change notification settings - Fork 364
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(test): support *OriginCall
funcs in _test
files
#703
feat(test): support *OriginCall
funcs in _test
files
#703
Conversation
Fix gnolang#481 `AssertOriginCall` and `IsOriginCall` functions can be used inside contracts to determine if the call comes directly from a tx (which is an *origin call*) or from an other contract (not an *origin call*). To do this those functions count the number of frames. In production environment, if there's exactly 2 frames, it is considered as an *origin call*. In test environment, the number of frames was 3, but it was working only for `_filetest`, and not for `_test`, where the setup is different and so the number of frames (7 instead of 3). To support `_test`, the change brings a way to identify if a test is a `_test` or `_filetest`, by checking the function name of the first frame. There's currently a pending discussion (gnolang#683) about how we should deal with frames, that's why I tried to keep this change minimal, but at least it fixes something and we can move forward. Ideally, `*OriginCall` functions should rely on something stronger that the number of frames, because for instance they could consider that a call is not an *origin call*, just because `std.IsOriginCall` is called by a sub-function of the same contract. But that's something we'll probably tackle with gnolang#683.
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.
LGTM. Agreed, let's proceed with the small updates as you suggested and focus on defining a more permanent solution in #683.
*OriginCall
funcs in _test
files*OriginCall
funcs in _test
files
Not usable right now because it imports `sort.Sort` which is disabled in tests.
Since p/demo/tests source code has been changed, some golden outputs have to be updated.
Finally fixed the tests, I had to remove the |
Fix #481
Description
AssertOriginCall
andIsOriginCall
functions can be used inside contracts to determine if the call comes directly from a tx (which is an origin call) or from an other contract (not an origin call).To do this those functions count the number of frames. In production environment, if there's exactly 2 frames, it is considered as an origin call. In test environment, the number of frames was 3, but it was working only for
_filetest
, and not for_test
, where the setup is different and so the number of frames (7 instead of 3).Change
To support
_test
, the change brings a way to identify if a test is a_test
or_filetest
, by checking the function name of the first frame.There's currently a pending discussion (#683) about how we should deal with frames, that's why I tried to keep this change minimal, but at least it fixes something and we can move forward.
This replaces the previous attempt #495 which was more complicated and actually was not correct.
Next steps
Ideally,
*OriginCall
functions should rely on something stronger that the number of frames, because for instance they could consider that a call is not an origin call, just becausestd.IsOriginCall
is called by a sub-function of the same contract. But that's something we'll probably tackle with #683.How has this been tested?
Some new tests have been added to
r/demo/tests
. Note that because we need to catch the panic inside the gno test,panic
has been replaced bym.Panic
(as explained in #663).