-
Notifications
You must be signed in to change notification settings - Fork 374
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
Issues with std.TestXYZ
functions
#1521
Comments
In the std refactor, I'm making some changes in how these test functions could work. This would also change the functioning of Basically, the idea is to have test functions set up a context, then call That way, everything can be cleanly simulated without having to set up 10 different TestSetX calls first. gno/gnovm/stdlibs/testing/context.gno Lines 9 to 21 in ef3b264
To answer your points in the OP:
|
centralizing on #1475 |
While writing the concept & reference docs, I was playing around with many of the
std
functions, which in also include the functions to handle mocking of parameters within the test context used withgno test
. For more context on the issue,gno test
creates a test Gno Machine with a specific blockchain context here.Below is a compilation of issues, inconsistencies, and naming choices that I found unintuitive, and that I suggest we refactor.
All of the functions I mention below can be found in the following files:
gnovm/tests/stdlibs/native.go
gnovm/tests/stdlibs/std/std.go
gnovm/tests/stdlibs/std/std.gno
TestCurrentRealm
:std.CurrentRealm()
function, which returns aRealm
object with both an address and path,std.TestCurrentRealm()
only returns the string path of the realm./p/
package, the return value is nil. When reading the result, this causes anil pointer dereference
panic. This is because of how the function is implemented - it only fetches the Realm from the testing context, which in this case is non-existent as we're calling it in a package test. This is a design choice and it's fine, but we need more clear error messages on this - ie, the function could panic with"called in non-realm context"
in case of being called from a package.AssertOriginCall
:TestSkipHeights
:TestAddress
:std
package. It is part of thetestutils
on-chain package. This could be migrated to the same place as the other functions for consistency, as it is a commonly used function.TestSetOrigPkgAddr
:This function is super weird. It is supposed to set the address of the current realm. Currently there is no way to get the address of the current realm in the testing context, and the
std.GetCurrentRealm()
returns an address that differs from the one set withTestSetOrigPkgAddr
. Here's a test demonstrating this in the playground.IsOriginCall
:Minor, but it would be great if this function was refactored to remove the hardcoded frame values. Also, not sure we really need it, just like
AssertOriginCall
.I am currently making a couple more issues relating to some findings, and will also post a general renaming discussion that will suggest how we should refactor the
std
API for mocking (or if we should move it to a different namespace altogether).Can we also discuss changing how
gno test
works by implementing the testing through the VM Keeper? This would also enable us to use the Banker API without issues in tests.cc @moul @zivkovicmilos @thehowl @waymobetta
The text was updated successfully, but these errors were encountered: