Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Using pyethereum.tester

vbuterin edited this page Jun 15, 2017 · 10 revisions

It will be documented as if you did:

from ethereum.tools import tester as t
from ethereum import utils as u
c = t.Chain()

Interacting with the blockchain

  • t.Chain() creates a new test-blockchain with a genesis block.
    • Returns the chain.
  • c.tx(private_key, to, value, data=b'') sends a transaction using the given private key to the given address with the given value and data.
    • Returns the return value of the transaction execution
  • c.contract(code, language='evm') creates a contract with the given code, in the given language. Acceptable arguments are 'evm', 'serpent', 'solidity' and 'viper'. If any of the latter three are used, returns an ABIContract object, of which you can then call functions.
  • s.mine(n=1, coinbase=a0) pretend-mines n times, with coinbase the blockmaker.
    • Returns nothing; (None)
  • s.snapshot() returns a snapshot object.
  • s.revert(snapshot) takes a snapshot as input and reverts to that snapshot.

Convenience accounts

The tester module generates ten keys and ten addresses: t.k0 ... t.k9 and their corresponding addresses t.a0 ... t.a9.

Getting data out of the state

  • c.head_state returns the State object at the head. You can then access various methods of this including get_code(addr), get_balance(addr), get_nonce(addr) and get_storage_at(addr, key).
  • c.block.transactions returns the transactions included in the block
  • c.head_state.receipts returns the receipts
Clone this wiki locally