-
Notifications
You must be signed in to change notification settings - Fork 375
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
Time & block height manipulation in tests #1165
Comments
You might want to try using the helper We're also working on a similar helper for the block timestamp, which you can find in this pull request: #569. If reviewed and approved, this could be merged relatively quickly since it only affects the testing helpers. In the meantime, you might be able to implement your locking logic using height comparison. The fixed values you're seeing are used to ensure deterministic unit tests. We do plan to provide a system similar to Ethereum's local blockchain for testing, but for now, the current system is the only one supported and it's designed to be lighter (I prefer it over the Ethereum system). However, we do see the value in adding a test suite that can interact with blockchains, so feel free to open an issue to define the need and propose a usage for this. Regarding your issue with adding Edit: By the way, I encourage you to use |
This is the source code where the context is hardcoded. Adding this for future reference. |
I'll close #924 to try to centralise conversation on time/block manipulation in this issue. This might be a discussion for the next dev call; I think there's two questions which are still unanswered and are subjective IMO, before we merge #569:
In either case, I think (1) we should forego IMO, after some more experience working and testing on Gno code, I think it makes sense to have |
I recommend using either two independent helpers or a single helper with two arguments. However, I advise against trying to calculate the timestamp as Additionally, I suggest modifying |
In test contexts, or also in normal execution? If you suggest also in normal execution, then I think it's not a good idea. The opcode counter should not be exposed to the execution, otherwise people will depend on it and as such we will have to guarantee the same opcode count consistently. While we obviously have to do it for determining gas fees, etc., I think this should still be information the code within the VM is not aware of at execution, so we can potentially change it at one point (with a good migration strategy) without fearing breaking existing code in any way. |
I agree. It's easy to create a deterministic solution that becomes a long-term nightmare to be kept deterministic.
Edit: After discussing it during the public development call, we all agree that it is reasonable for |
I am looking to understand how the blockchain context works and can be manipulated within local (unit) tests.
This issue arose when I was looking for a way to set specific values to certain blockchain context variables, such as block timestamp, block height, etc. within tests for realms. In my case, I was stuck trying to set the block timestamp to a specific value.
Here is the specific scenario:
The simplified example realm function is defined as follows:
I wish to have a test with this flow:
Currently, running
gives
1234567890
, which seems to be a hardcoded value. Although this value is editable (i.e. you can use time.Add, time.Sub, etc), it is quite inconvenient to work with it:1
to it, you need to.Add(1000000000)
,A similar case can be found with
std.GetHeight()
- which returns123
upon being called within tests. I have no clue if this value can be manipulated, as it seems that the testing package is not fully complete, as per this comment.Coming from the Ethereum ecosystem, a local node is required to be running in the background in order to run Solidity tests, due to the nature of the EVM. Hardhat, an Ethereum development framework, opens an API to manage the blockchain context within its local node, and provides helpers to do it.
How do Gno & the GnoVM work regarding this issue? This will most likely be a common dApp developer question, which is why it makes sense to address it.
The text was updated successfully, but these errors were encountered: