Issues with std.TestXYZ
functions
#1521
Labels
🌟 must have 🌟
Mandatory work needed to complete a project
Milestone
std.TestXYZ
functions
#1521
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: