15
15
MiningChain ,
16
16
)
17
17
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
+ )
21
26
22
27
23
28
# Uncomment this to have logs from tests written to a file. This is useful for
@@ -59,6 +64,30 @@ def _file_logging(request):
59
64
"""
60
65
61
66
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
+
62
91
@pytest .fixture
63
92
def base_db ():
64
93
return AtomicDB ()
@@ -81,7 +110,7 @@ def funded_address_initial_balance():
81
110
return to_wei (1000 , 'ether' )
82
111
83
112
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 ):
85
114
"""
86
115
Return a Chain object containing just the genesis block.
87
116
@@ -113,7 +142,7 @@ def _chain_with_block_validation(base_db, genesis_state, chain_cls=Chain):
113
142
klass = chain_cls .configure (
114
143
__name__ = 'TestChain' ,
115
144
vm_configuration = (
116
- (constants .GENESIS_BLOCK_NUMBER , SpuriousDragonVM ),
145
+ (constants .GENESIS_BLOCK_NUMBER , VM ),
117
146
),
118
147
chain_id = 1337 ,
119
148
)
@@ -122,8 +151,20 @@ def _chain_with_block_validation(base_db, genesis_state, chain_cls=Chain):
122
151
123
152
124
153
@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
127
168
128
169
129
170
def import_block_without_validation (chain , block ):
@@ -150,6 +191,7 @@ def genesis_state(base_genesis_state):
150
191
@pytest .fixture (params = [Chain , MiningChain ])
151
192
def chain_without_block_validation (
152
193
request ,
194
+ VM ,
153
195
base_db ,
154
196
genesis_state ):
155
197
"""
@@ -166,12 +208,12 @@ def chain_without_block_validation(
166
208
'import_block' : import_block_without_validation ,
167
209
'validate_block' : lambda self , block : None ,
168
210
}
169
- SpuriousDragonVMForTesting = SpuriousDragonVM .configure (validate_seal = lambda block : None )
211
+ VMForTesting = VM .configure (validate_seal = lambda block : None )
170
212
chain_class = request .param
171
213
klass = chain_class .configure (
172
214
__name__ = 'TestChainWithoutBlockValidation' ,
173
215
vm_configuration = (
174
- (constants .GENESIS_BLOCK_NUMBER , SpuriousDragonVMForTesting ),
216
+ (constants .GENESIS_BLOCK_NUMBER , VMForTesting ),
175
217
),
176
218
chain_id = 1337 ,
177
219
** overrides ,
0 commit comments