Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ethereum/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
ANTI_DOS_FORK_BLKNUM=2457000,
CLEARING_FORK_BLKNUM=2 ** 98,
)

LATEST_APPLIED_FORK_BLKNUM = default_config.get('ANTI_DOS_FORK_BLKNUM')

assert default_config['NEPHEW_REWARD'] == \
default_config['BLOCK_REWARD'] // 32

Expand Down
24 changes: 23 additions & 1 deletion ethereum/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ethereum import blocks, db, opcodes, processblock, transactions
from ethereum.abi import ContractTranslator
from ethereum.config import Env
from ethereum.config import Env, LATEST_APPLIED_FORK_BLKNUM
from ethereum.slogging import LogRecorder
from ethereum._solidity import get_solidity
from ethereum.utils import to_string, sha3, privtoaddr, int_to_addr
Expand Down Expand Up @@ -416,3 +416,25 @@ def revert(self, data):
self.block.header._mutable = True
self.block._cached_rlp = None
self.block.header._cached_rlp = None


def latest_state(blknum=None, **kwargs):
"""Helper, that generates a `tester.state` instance with a block number
above all applied forks on the main net (depends on
`ethereum.config.LATEST_APPLIED_FORK_BLKNUM`).

If `blknum` is given, this number will be used as block number instead.

Returns:
`tester.state` instance with adjusted block number
"""
blockchain_state = state(**kwargs)

if blknum is None:
blockchain_state.block.number = LATEST_APPLIED_FORK_BLKNUM
else:
if not isinstance(blknum, int):
raise ValueError("blknum must be integer")
blockchain_state.block.number = blknum

return blockchain_state
11 changes: 10 additions & 1 deletion ethereum/tests/test_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@

import pytest

from ethereum.tester import state, ABIContract
from ethereum.tester import (state, ABIContract, latest_state,
LATEST_APPLIED_FORK_BLKNUM)
from ethereum._solidity import get_solidity, compile_file

SOLIDITY_AVAILABLE = get_solidity() is not None
CONTRACTS_DIR = path.join(path.dirname(__file__), 'contracts')


def test_latest_state():
assert latest_state().block.number == LATEST_APPLIED_FORK_BLKNUM
assert latest_state(blknum=42).block.number == 42
assert latest_state(blknum=0).block.number == 0
with pytest.raises(ValueError):
latest_state(blknum=[1])


@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
def test_abicontract_interface():
""" Test for issue #370. """
Expand Down