Skip to content

Commit

Permalink
update tester chain to support spurious dragon
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Oct 18, 2017
1 parent f14cd12 commit c2238d5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
31 changes: 27 additions & 4 deletions evm/chains/tester/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FrontierVM as BaseFrontierVM,
HomesteadVM as BaseHomesteadVM,
EIP150VM as BaseEIP150VM,
SpuriousDragonVM as BaseSpuriousDragonVM,
)

from evm.utils.chain import (
Expand Down Expand Up @@ -44,6 +45,10 @@ class EIP150TesterVM(MaintainGasLimitMixin, BaseEIP150VM):
pass


class SpuriousDragonTesterVM(MaintainGasLimitMixin, BaseSpuriousDragonVM):
pass


INVALID_FORK_ACTIVATION_MSG = (
"The {0}-fork activation block may not be null if the {1}-fork block "
"is non null"
Expand All @@ -53,11 +58,27 @@ class EIP150TesterVM(MaintainGasLimitMixin, BaseEIP150VM):
@reversed_return
def _generate_vm_configuration(homestead_start_block=None,
dao_start_block=None,
eip150_start_block=None):
eip150_start_block=None,
spurious_dragon_block=None):
# If no explicit configuration has been passed, configure the vm to start
# with the latest fork rules at block 0
if eip150_start_block is None and homestead_start_block is None:
yield (0, EIP150TesterVM)
no_declared_blocks = (
spurious_dragon_block is None and
eip150_start_block is None and
homestead_start_block is None
)
if no_declared_blocks:
yield (0, SpuriousDragonTesterVM)

if spurious_dragon_block is not None:
yield (spurious_dragon_block, SpuriousDragonTesterVM)

remaining_blocks_not_declared = (
homestead_start_block is None and
eip150_start_block is None
)
if spurious_dragon_block > 0 and remaining_blocks_not_declared:
yield (0, EIP150TesterVM)

if eip150_start_block is not None:
yield (eip150_start_block, EIP150TesterVM)
Expand Down Expand Up @@ -111,13 +132,15 @@ def validate_seal(self, block):
def configure_forks(self,
homestead_start_block=None,
dao_start_block=None,
eip150_start_block=0):
eip150_start_block=None,
spurious_dragon_block=None):
"""
TODO: add support for state_cleanup
"""
vm_configuration = _generate_vm_configuration(
homestead_start_block=homestead_start_block,
dao_start_block=dao_start_block,
eip150_start_block=eip150_start_block,
spurious_dragon_block=spurious_dragon_block,
)
self.vms_by_range = generate_vms_by_range(vm_configuration)
30 changes: 29 additions & 1 deletion tests/core/tester/test_generate_vm_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,40 @@ class Forks(enum.Enum):
Frontier = 0
Homestead = 1
EIP150 = 2
SpuriousDragon = 3


@pytest.mark.parametrize(
"kwargs,expected",
(
(
dict(),
((0, Forks.EIP150),),
((0, Forks.SpuriousDragon),),
),
(
dict(spurious_dragon_block=1),
((0, Forks.EIP150), (1, Forks.SpuriousDragon)),
),
(
dict(eip150_start_block=1, spurious_dragon_block=2),
((0, Forks.Homestead), (1, Forks.EIP150), (2, Forks.SpuriousDragon)),
),
(
dict(homestead_start_block=1, eip150_start_block=2, spurious_dragon_block=3),
(
(0, Forks.Frontier),
(1, Forks.Homestead),
(2, Forks.EIP150),
(3, Forks.SpuriousDragon),
),
),
(
dict(homestead_start_block=1, spurious_dragon_block=3),
(
(0, Forks.Frontier),
(1, Forks.Homestead),
(3, Forks.SpuriousDragon),
),
),
(
dict(eip150_start_block=1),
Expand Down Expand Up @@ -67,5 +93,7 @@ def test_generate_vm_configuration(kwargs, expected):
assert left_vm.dao_fork_block_number == dao_start_block
elif right_vm == Forks.EIP150:
assert 'EIP150' in left_vm.__name__
elif right_vm == Forks.SpuriousDragon:
assert 'SpuriousDragon' in left_vm.__name__
else:
assert False, "Invariant"

0 comments on commit c2238d5

Please sign in to comment.