Skip to content

Commit ff410c4

Browse files
Bhargavasomucburgdorf
authored andcommitted
Add fixture to get individual chain from vm separately
1 parent dfe43ae commit ff410c4

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

tests/conftest.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
MiningChain,
1616
)
1717
from eth.db.atomic import AtomicDB
18-
# TODO: tests should not be locked into one set of VM rules. Look at expanding
19-
# to all mainnet vms.
20-
from eth.vm.forks.spurious_dragon import SpuriousDragonVM
18+
from eth.vm.forks import (
19+
FrontierVM,
20+
HomesteadVM,
21+
TangerineWhistleVM,
22+
SpuriousDragonVM,
23+
ByzantiumVM,
24+
ConstantinopleVM,
25+
)
2126

2227

2328
# Uncomment this to have logs from tests written to a file. This is useful for
@@ -59,6 +64,30 @@ def _file_logging(request):
5964
"""
6065

6166

67+
@pytest.fixture(params=[
68+
FrontierVM,
69+
HomesteadVM.configure(
70+
support_dao_fork=False,
71+
),
72+
TangerineWhistleVM,
73+
SpuriousDragonVM,
74+
ByzantiumVM,
75+
ConstantinopleVM,
76+
])
77+
def VM(request):
78+
return request.param
79+
80+
81+
@pytest.fixture
82+
def block_reward(VM):
83+
if VM == ByzantiumVM:
84+
return 3 * (10**18)
85+
elif VM == ConstantinopleVM:
86+
return 2 * (10**18)
87+
else:
88+
return 5 * (10**18)
89+
90+
6291
@pytest.fixture
6392
def base_db():
6493
return AtomicDB()
@@ -81,7 +110,7 @@ def funded_address_initial_balance():
81110
return to_wei(1000, 'ether')
82111

83112

84-
def _chain_with_block_validation(base_db, genesis_state, chain_cls=Chain):
113+
def _chain_with_block_validation(VM, base_db, genesis_state, chain_cls=Chain):
85114
"""
86115
Return a Chain object containing just the genesis block.
87116
@@ -113,7 +142,7 @@ def _chain_with_block_validation(base_db, genesis_state, chain_cls=Chain):
113142
klass = chain_cls.configure(
114143
__name__='TestChain',
115144
vm_configuration=(
116-
(constants.GENESIS_BLOCK_NUMBER, SpuriousDragonVM),
145+
(constants.GENESIS_BLOCK_NUMBER, VM),
117146
),
118147
chain_id=1337,
119148
)
@@ -122,8 +151,20 @@ def _chain_with_block_validation(base_db, genesis_state, chain_cls=Chain):
122151

123152

124153
@pytest.fixture
125-
def chain_with_block_validation(base_db, genesis_state):
126-
return _chain_with_block_validation(base_db, genesis_state)
154+
def chain_with_block_validation(VM, base_db, genesis_state):
155+
return _chain_with_block_validation(VM, base_db, genesis_state)
156+
157+
158+
@pytest.fixture(scope='function')
159+
def chain_from_vm(request, base_db, genesis_state):
160+
"""
161+
This fixture is to be used only when the properties of the
162+
chains differ from one VM to another.
163+
For example, the block rewards change from one VM chain to another
164+
"""
165+
def get_chain_from_vm(vm):
166+
return _chain_with_block_validation(vm, base_db, genesis_state)
167+
return get_chain_from_vm
127168

128169

129170
def import_block_without_validation(chain, block):
@@ -150,6 +191,7 @@ def genesis_state(base_genesis_state):
150191
@pytest.fixture(params=[Chain, MiningChain])
151192
def chain_without_block_validation(
152193
request,
194+
VM,
153195
base_db,
154196
genesis_state):
155197
"""
@@ -166,12 +208,12 @@ def chain_without_block_validation(
166208
'import_block': import_block_without_validation,
167209
'validate_block': lambda self, block: None,
168210
}
169-
SpuriousDragonVMForTesting = SpuriousDragonVM.configure(validate_seal=lambda block: None)
211+
VMForTesting = VM.configure(validate_seal=lambda block: None)
170212
chain_class = request.param
171213
klass = chain_class.configure(
172214
__name__='TestChainWithoutBlockValidation',
173215
vm_configuration=(
174-
(constants.GENESIS_BLOCK_NUMBER, SpuriousDragonVMForTesting),
216+
(constants.GENESIS_BLOCK_NUMBER, VMForTesting),
175217
),
176218
chain_id=1337,
177219
**overrides,

0 commit comments

Comments
 (0)