Skip to content

Commit

Permalink
refactor: use evm_setNextBlockTimestamp (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Aug 19, 2022
1 parent ddc5374 commit 994d8d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 1 addition & 3 deletions ape_hardhat/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ def set_block_gas_limit(self, gas_limit: int) -> bool:
return self._make_request("evm_setBlockGasLimit", [hex(gas_limit)]) is True

def set_timestamp(self, new_timestamp: int):
pending_timestamp = self.get_block("pending").timestamp
seconds_to_increase = new_timestamp - pending_timestamp
self._make_request("evm_increaseTime", [seconds_to_increase])
self._make_request("evm_setNextBlockTimestamp", [new_timestamp])

def mine(self, num_blocks: int = 1):
# NOTE: Request fails when given numbers with any left padded 0s.
Expand Down
7 changes: 3 additions & 4 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ def test_set_block_gas_limit(connected_provider):

def test_set_timestamp(connected_provider):
start_time = connected_provider.get_block("pending").timestamp
connected_provider.set_timestamp(start_time + 5) # Increase by 5 seconds
expected_timestamp = start_time + 5
connected_provider.set_timestamp(expected_timestamp)
new_time = connected_provider.get_block("pending").timestamp

# Adding 5 seconds but seconds can be weird so give it a 1 second margin.
assert 4 <= new_time - start_time <= 6
assert new_time == expected_timestamp


def test_mine(connected_provider):
Expand Down

0 comments on commit 994d8d6

Please sign in to comment.