misc test fixes for new config approach

This commit is contained in:
protolambda
2021-05-18 14:31:50 +02:00
parent 0894125bf7
commit e8b0c46138
8 changed files with 30 additions and 30 deletions

View File

@@ -508,7 +508,8 @@ ExecutionState = Any
def get_pow_block(hash: Bytes32) -> PowBlock:
return PowBlock(block_hash=hash, is_valid=True, is_processed=True, total_difficulty=config.TRANSITION_TOTAL_DIFFICULTY)
return PowBlock(block_hash=hash, is_valid=True, is_processed=True,
total_difficulty=config.TRANSITION_TOTAL_DIFFICULTY)
def get_execution_state(execution_state_root: Bytes32) -> ExecutionState:
@@ -620,8 +621,8 @@ def objects_to_spec(preset_name: str,
out += f' # {vardef.comment}'
return out
constant_vars_spec = '# Constant vars \n' + '\n'.join(format_constant(k, v) for k, v in spec_object.constant_vars.items())
preset_vars_spec = '# Preset vars \n' + '\n'.join(format_constant(k, v) for k, v in spec_object.preset_vars.items())
constant_vars_spec = '# Constant vars\n' + '\n'.join(format_constant(k, v) for k, v in spec_object.constant_vars.items())
preset_vars_spec = '# Preset vars\n' + '\n'.join(format_constant(k, v) for k, v in spec_object.preset_vars.items())
ordered_class_objects_spec = '\n\n\n'.join(ordered_class_objects.values())
ssz_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, builder.hardcoded_ssz_dep_constants()[x]), builder.hardcoded_ssz_dep_constants()))
ssz_dep_constants_verification = '\n'.join(map(lambda x: 'assert %s == %s' % (x, spec_object.ssz_dep_constants[x]), builder.hardcoded_ssz_dep_constants()))

View File

@@ -3,7 +3,7 @@ from random import Random
from eth2spec.test.context import (
with_phases,
with_custom_state,
with_configs,
with_presets,
spec_test, with_state,
low_balances, misc_balances, large_validator_set,
)
@@ -110,7 +110,7 @@ def test_altair_fork_random_misc_balances(spec, phases, state):
@with_phases(phases=[PHASE0], other_phases=[ALTAIR])
@with_configs([MINIMAL],
@with_presets([MINIMAL],
reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated")
@spec_test
@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.EJECTION_BALANCE)

View File

@@ -8,7 +8,7 @@ from eth2spec.utils import bls
from eth2spec.utils.bls import only_with_bls
from eth2spec.test.context import (
with_altair_and_later,
with_configs,
with_presets,
with_state,
)
from eth2spec.test.helpers.constants import (
@@ -95,7 +95,7 @@ def _get_sync_committee_signature(
@only_with_bls()
@with_altair_and_later
@with_configs([MINIMAL], reason="too slow")
@with_presets([MINIMAL], reason="too slow")
@with_state
def test_process_sync_committee_contributions(phases, spec, state):
# skip over slots at genesis
@@ -157,7 +157,7 @@ def _get_expected_subnets_by_pubkey(sync_committee_members):
@with_altair_and_later
@with_configs([MINIMAL], reason="too slow")
@with_presets([MINIMAL], reason="too slow")
@with_state
def test_compute_subnets_for_sync_committee(state, spec, phases):
# Transition to the head of the next period
@@ -186,7 +186,7 @@ def test_compute_subnets_for_sync_committee(state, spec, phases):
@with_altair_and_later
@with_configs([MINIMAL], reason="too slow")
@with_presets([MINIMAL], reason="too slow")
@with_state
def test_compute_subnets_for_sync_committee_slot_period_boundary(state, spec, phases):
# Transition to the end of the period

View File

@@ -1,5 +1,3 @@
from pathlib import Path
from eth2spec.config import config_util
from eth2spec.test import context
from eth2spec.utils import bls as bls_utils

View File

@@ -1,7 +1,7 @@
from random import Random
from lru import LRU
from eth2spec.phase0 import spec as spec_phase0
from eth2spec.phase0.mainnet import VALIDATOR_REGISTRY_LIMIT # equal everywhere, fine to import
from eth2spec.test.context import is_post_altair
from eth2spec.test.helpers.state import (
next_epoch,
@@ -17,8 +17,8 @@ from eth2spec.utils.ssz.ssz_typing import Container, uint64, List
class Deltas(Container):
rewards: List[uint64, spec_phase0.VALIDATOR_REGISTRY_LIMIT]
penalties: List[uint64, spec_phase0.VALIDATOR_REGISTRY_LIMIT]
rewards: List[uint64, VALIDATOR_REGISTRY_LIMIT]
penalties: List[uint64, VALIDATOR_REGISTRY_LIMIT]
def has_enough_for_reward(spec, state, index):

View File

@@ -40,7 +40,7 @@ def test_initialize_beacon_state_from_eth1(spec):
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
@@ -48,7 +48,7 @@ def test_initialize_beacon_state_from_eth1(spec):
# initialize beacon_state
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
assert state.genesis_time == eth1_timestamp + spec.GENESIS_DELAY
assert state.genesis_time == eth1_timestamp + spec.config.GENESIS_DELAY
assert len(state.validators) == deposit_count
assert state.eth1_data.deposit_root == deposit_root
assert state.eth1_data.deposit_count == deposit_count
@@ -83,7 +83,7 @@ def test_initialize_beacon_state_some_small_balances(spec):
deposits = main_deposits + small_deposits
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
@@ -91,7 +91,7 @@ def test_initialize_beacon_state_some_small_balances(spec):
# initialize beacon_state
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
assert state.genesis_time == eth1_timestamp + spec.GENESIS_DELAY
assert state.genesis_time == eth1_timestamp + spec.config.GENESIS_DELAY
assert len(state.validators) == small_deposit_count
assert state.eth1_data.deposit_root == deposit_root
assert state.eth1_data.deposit_count == len(deposits)
@@ -139,7 +139,7 @@ def test_initialize_beacon_state_one_topup_activation(spec):
deposits = main_deposits + partial_deposits + top_up_deposits
eth1_block_hash = b'\x13' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
@@ -167,7 +167,7 @@ def test_initialize_beacon_state_random_invalid_genesis(spec):
max_pubkey_index=10,
)
eth1_block_hash = b'\x14' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME + 1
eth1_timestamp = spec.config.MIN_GENESIS_TIME + 1
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
@@ -206,7 +206,7 @@ def test_initialize_beacon_state_random_valid_genesis(spec):
deposits = random_deposits + full_deposits
eth1_block_hash = b'\x15' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME + 2
eth1_timestamp = spec.config.MIN_GENESIS_TIME + 2
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits

View File

@@ -25,7 +25,7 @@ def create_valid_beacon_state(spec):
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
return spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
@@ -63,7 +63,7 @@ def test_is_valid_genesis_state_false_invalid_timestamp(spec):
yield 'description', 'meta', get_post_altair_description(spec)
state = create_valid_beacon_state(spec)
state.genesis_time = spec.MIN_GENESIS_TIME - 1
state.genesis_time = spec.config.MIN_GENESIS_TIME - 1
yield from run_is_valid_genesis_state(spec, state, valid=False)
@@ -99,7 +99,7 @@ def test_is_valid_genesis_state_true_one_more_validator(spec):
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
yield from run_is_valid_genesis_state(spec, state, valid=True)
@@ -122,7 +122,7 @@ def test_is_valid_genesis_state_false_not_enough_validator(spec):
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.MIN_GENESIS_TIME
eth1_timestamp = spec.config.MIN_GENESIS_TIME
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
yield from run_is_valid_genesis_state(spec, state, valid=False)

View File

@@ -140,28 +140,29 @@ def test_get_epoch_signature(spec, state):
@with_all_phases
@spec_state_test
def test_is_candidate_block(spec, state):
period_start = spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE * 2 + 1000
distance_duration = spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE
period_start = distance_duration * 2 + 1000
run_is_candidate_block(
spec,
spec.Eth1Block(timestamp=period_start - spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE),
spec.Eth1Block(timestamp=period_start - distance_duration),
period_start,
success=True,
)
run_is_candidate_block(
spec,
spec.Eth1Block(timestamp=period_start - spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE + 1),
spec.Eth1Block(timestamp=period_start - distance_duration + 1),
period_start,
success=False,
)
run_is_candidate_block(
spec,
spec.Eth1Block(timestamp=period_start - spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE * 2),
spec.Eth1Block(timestamp=period_start - distance_duration * 2),
period_start,
success=True,
)
run_is_candidate_block(
spec,
spec.Eth1Block(timestamp=period_start - spec.config.SECONDS_PER_ETH1_BLOCK * spec.config.ETH1_FOLLOW_DISTANCE * 2 - 1),
spec.Eth1Block(timestamp=period_start - distance_duration * 2 - 1),
period_start,
success=False,
)