2019-05-05 22:31:57 +00:00
|
|
|
from eth2spec.phase0 import spec
|
2019-05-13 21:15:02 +00:00
|
|
|
from eth2spec.utils import bls
|
2019-05-05 22:31:57 +00:00
|
|
|
|
2019-05-17 18:31:21 +00:00
|
|
|
from .helpers.genesis import create_genesis_state
|
2019-05-05 22:31:57 +00:00
|
|
|
|
2019-05-08 15:33:09 +00:00
|
|
|
from .utils import spectest, with_args
|
2019-05-06 15:10:43 +00:00
|
|
|
|
2019-05-05 22:31:57 +00:00
|
|
|
# Provides a genesis state as first argument to the function decorated with this
|
2019-05-17 19:26:18 +00:00
|
|
|
with_state = with_args(lambda: [create_genesis_state(spec.SLOTS_PER_EPOCH * 8)])
|
2019-05-06 15:10:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
# shorthand for decorating @with_state @spectest()
|
|
|
|
def spec_state_test(fn):
|
2019-05-13 21:15:02 +00:00
|
|
|
return with_state(bls_switch(spectest()(fn)))
|
2019-05-08 15:33:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def expect_assertion_error(fn):
|
2019-05-11 15:51:02 +00:00
|
|
|
bad = False
|
2019-05-08 15:33:09 +00:00
|
|
|
try:
|
|
|
|
fn()
|
2019-05-11 15:51:02 +00:00
|
|
|
bad = True
|
2019-05-08 15:33:09 +00:00
|
|
|
except AssertionError:
|
|
|
|
pass
|
2019-05-11 15:01:12 +00:00
|
|
|
except IndexError:
|
|
|
|
# Index errors are special; the spec is not explicit on bound checking, an IndexError is like a failed assert.
|
|
|
|
pass
|
2019-05-11 15:51:02 +00:00
|
|
|
if bad:
|
|
|
|
raise AssertionError('expected an assertion error, but got none.')
|
2019-05-13 21:15:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def always_bls(fn):
|
|
|
|
"""
|
|
|
|
Decorator to apply on ``bls_switch`` decorator to force BLS activation. Useful to mark tests as BLS-dependent.
|
|
|
|
"""
|
|
|
|
def entry(*args, **kw):
|
|
|
|
# override bls setting
|
|
|
|
kw['bls_active'] = True
|
|
|
|
fn(*args, **kw)
|
|
|
|
return entry
|
|
|
|
|
|
|
|
|
|
|
|
def bls_switch(fn):
|
|
|
|
"""
|
|
|
|
Decorator to make a function execute with BLS ON, or BLS off.
|
|
|
|
Based on an optional bool argument ``bls_active``, passed to the function at runtime.
|
|
|
|
"""
|
|
|
|
def entry(*args, **kw):
|
|
|
|
old_state = bls.bls_active
|
|
|
|
bls.bls_active = kw.pop('bls_active', False)
|
|
|
|
fn(*args, **kw)
|
|
|
|
bls.bls_active = old_state
|
|
|
|
return entry
|