1
+ import pytest
2
+
1
3
from eth2spec .phase0 import spec as spec_phase0
2
4
from eth2spec .phase1 import spec as spec_phase1
3
5
from eth2spec .utils import bls
4
6
7
+ from .exceptions import SkippedTest
5
8
from .helpers .genesis import create_genesis_state
6
-
7
9
from .utils import vector_test , with_meta_tags
8
10
9
11
from random import Random
@@ -22,11 +24,16 @@ def reload_specs():
22
24
# Some of the Spec module functionality is exposed here to deal with phase-specific changes.
23
25
24
26
SpecForkName = NewType ("SpecForkName" , str )
27
+ ConfigName = NewType ("ConfigName" , str )
25
28
26
29
PHASE0 = SpecForkName ('phase0' )
27
30
PHASE1 = SpecForkName ('phase1' )
28
31
ALL_PHASES = (PHASE0 , PHASE1 )
29
32
33
+ MAINNET = ConfigName ('mainnet' )
34
+ MINIMAL = ConfigName ('minimal' )
35
+
36
+
30
37
# TODO: currently phases are defined as python modules.
31
38
# It would be better if they would be more well-defined interfaces for stronger typing.
32
39
@@ -153,7 +160,7 @@ def low_single_balance(spec):
153
160
154
161
def large_validator_set (spec ):
155
162
"""
156
- Helper method to create a series of default balances.
163
+ Helper method to create a large series of default balances.
157
164
Usage: `@with_custom_state(balances_fn=default_balances, ...)`
158
165
"""
159
166
num_validators = 2 * spec .SLOTS_PER_EPOCH * spec .MAX_COMMITTEES_PER_SLOT * spec .TARGET_COMMITTEE_SIZE
@@ -184,6 +191,17 @@ def entry(*args, **kw):
184
191
DEFAULT_BLS_ACTIVE = True
185
192
186
193
194
+ is_pytest = True
195
+
196
+
197
+ def dump_skipping_message (reason : str ) -> None :
198
+ message = f"[Skipped test] { reason } "
199
+ if is_pytest :
200
+ pytest .skip (message )
201
+ else :
202
+ raise SkippedTest (message )
203
+
204
+
187
205
def spec_test (fn ):
188
206
# Bls switch must be wrapped by vector_test,
189
207
# to fully go through the yielded bls switch data, before setting back the BLS setting.
@@ -255,6 +273,24 @@ def entry(*args, **kw):
255
273
return entry
256
274
257
275
276
+ def disable_process_reveal_deadlines (fn ):
277
+ """
278
+ Decorator to make a function execute with `process_reveal_deadlines` OFF.
279
+ This is for testing long-range epochs transition without considering the reveal-deadline slashing effect.
280
+ """
281
+ def entry (* args , spec : Spec , ** kw ):
282
+ if hasattr (spec , 'process_reveal_deadlines' ):
283
+ old_state = spec .process_reveal_deadlines
284
+ spec .process_reveal_deadlines = lambda state : None
285
+
286
+ yield from fn (* args , spec = spec , ** kw )
287
+
288
+ if hasattr (spec , 'process_reveal_deadlines' ):
289
+ spec .process_reveal_deadlines = old_state
290
+
291
+ return with_meta_tags ({'reveal_deadlines_setting' : 1 })(entry )
292
+
293
+
258
294
def with_all_phases (fn ):
259
295
"""
260
296
A decorator for running a test with every phase
@@ -284,7 +320,8 @@ def wrapper(*args, **kw):
284
320
if 'phase' in kw :
285
321
phase = kw .pop ('phase' )
286
322
if phase not in phases :
287
- return
323
+ dump_skipping_message (f"doesn't support this fork: { phase } " )
324
+ return None
288
325
run_phases = [phase ]
289
326
290
327
available_phases = set (run_phases )
@@ -309,3 +346,33 @@ def wrapper(*args, **kw):
309
346
return ret
310
347
return wrapper
311
348
return decorator
349
+
350
+
351
+ def with_configs (configs , reason = None ):
352
+ def decorator (fn ):
353
+ def wrapper (* args , spec : Spec , ** kw ):
354
+ available_configs = set (configs )
355
+ if spec .CONFIG_NAME not in available_configs :
356
+ message = f"doesn't support this config: { spec .CONFIG_NAME } ."
357
+ if reason is not None :
358
+ message = f"{ message } Reason: { reason } "
359
+ dump_skipping_message (message )
360
+ return None
361
+
362
+ return fn (* args , spec = spec , ** kw )
363
+ return wrapper
364
+ return decorator
365
+
366
+
367
+ def only_full_crosslink (fn ):
368
+ def is_full_crosslink (spec , state ):
369
+ epoch = spec .compute_epoch_at_slot (state .slot )
370
+ return spec .get_committee_count_per_slot (state , epoch ) >= spec .get_active_shard_count (state )
371
+
372
+ def wrapper (* args , spec : Spec , state : Any , ** kw ):
373
+ # TODO: update condition to "phase1+" if we have phase2
374
+ if spec .fork == PHASE1 and not is_full_crosslink (spec , state ):
375
+ dump_skipping_message ("only for full crosslink" )
376
+ return None
377
+ return fn (* args , spec = spec , state = state , ** kw )
378
+ return wrapper
0 commit comments