Say I have a contract that has a method that implements a time expiration via a function parameter set by the user, how can I test that the expiration works as expected in brownie by delaying the transmission and consequently execution of the transaction?

contract SimpleContract {

  function doSomething(uint256 exp) external {
    require(now < exp, 'Transaction Expired');
from brownie import SimpleContract, accounts
import time

def main():
  account = accounts[index]
  simpleContract = SimpleContract.deploy({'from': account})

  now = int(time.time())
  validFor = 20 # valid for 20 seconds
  simpleContract.doSomething(now + validFor, {'from': account})

Since brownie immediately submits the transaction by default it won't expire, so how do I get it to delay the submission and test that the transaction fails if its execution is attempted after the specified expiration time?

1 Answer 1


You can time travel in brownie to push the timer forward.

from brownie import chain
# some code here
chain.sleep(31337) # it's 31.3 seconds

This will shift the block timestamp in the blockchain.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.