Skip to content

Commit

Permalink
Fix time tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed May 17, 2024
1 parent 544d79c commit f844ea0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 4 additions & 3 deletions boa_zksync/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def fork_rpc(
self.sha3_trace: dict = {}
self.sstore_trace: dict = {}
self._rpc = EraTestNode(rpc, block_identifier)
self._reset_vm()

def register_contract(self, address, obj):
addr = Address(address)
Expand Down Expand Up @@ -275,9 +274,11 @@ def __set__(self, state: "_RPCState", value):


class _RPCState:
# Test node adds a virtual empty block at the end of the batch.
# When you use the RPC - you get the timestamp of the last actually committed block.
timestamp = _RPCProperty(
lambda rpc: to_int(rpc.fetch("eth_getBlockByNumber", ["latest", False])["timestamp"]),
lambda rpc, value: rpc.fetch("evm_setNextBlockTimestamp", [value]),
lambda rpc: to_int(rpc.fetch_uncached("eth_getBlockByNumber", ["pending", False])["timestamp"]) + 1,
lambda rpc, value: rpc.fetch_uncached("evm_setTime", [value - 1]),
)

def __init__(self, rpc):
Expand Down
10 changes: 2 additions & 8 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,7 @@ def test_time(zksync_env):
def get_time() -> uint256:
return block.timestamp
"""
# TODO: For some reason the RPC vs the VM timestamp is off by 1
contract = boa.loads(code)
env_timestamp = boa.env.vm.state.timestamp
assert contract.get_time() == env_timestamp + 1
assert contract.get_time() == boa.env.vm.state.timestamp
boa.env.vm.state.timestamp = 1234567890
assert contract.get_time() == 1234567890 + 1

# sanity check
block = boa.env._rpc.fetch("eth_getBlockByNumber", ["latest", False])
assert int(block["timestamp"], 16) == env_timestamp
assert contract.get_time() == 1234567890

0 comments on commit f844ea0

Please sign in to comment.