go-algorand
go-algorand copied to clipboard
SPIKE Add ability to advance time when network is in devmode
Problem
It is very difficult to test smart contracts that rely on time / block number. The current workaround I use is to add global state variables to smart contracts for the timestamp and block number. Instead of reading from the blockchain, you read them from state instead.
Solution
Solution would be to expose functionality to advance time / block number. Something like goal node advance -t <TIME> -b <BLOCK>
. This would only be available when devMode
is set to true
in the network template JSON file.
Dependencies
None
Urgency
Medium - this would speed up development significantly and avoid the workaround overhead (which may not even be possible when there is limitted storage space + smart contract size).
I think this is really important. As a solidity dev, I can use hardhat to fast forward time, which is super helpful for testing my smart contracts. Having the same feature in dev mode on algorand would be super helpful for my smart contract debugging with pytest, and would enable me to use dev mode when testing my time-gating smart contract functionality
I would bump this up to a high level of urgency. It is critical for testing any smart contracts that rely on time.
Indeed, at Algofi we run a suite of tests that rely on time for calculating lending an borrowing interest. I would second that this should be promoted to a high level of urgency.
This is a huge pain point for us
ideas to solve this problem (needs to be explored)
in devmode:
- remove/relax the constraint about the timestamp of consecutive blocks. (the 20secs max increment)
- add an endpoint for fake time that algod uses. And algod needs to remember the offset for following blocks.
alternatively, have devmode add artificial time each block (pretend that 4 seconds went by). This might be slightly more realistic. But this also requires submitting lots of txns to get time to move forward.
how does this relate to latest timestamp? how does this interact with dryrun and our new simulation endpoint?
are there time mocking libraries in go?
All the smart contracts I write depend on timestamps. Which ends up making my tests last 20-30 minutes. This would save an incredible amount of time