Skip to content

Commit

Permalink
misc test fixes for new config approach
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed May 18, 2021
1 parent 0894125 commit e8b0c46
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def sundry_functions(cls) -> str:
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:
Expand Down Expand Up @@ -620,8 +621,8 @@ def format_constant(name: str, vardef: VariableDefinition) -> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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,
)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/core/pyspec/eth2spec/test/conftest.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/core/pyspec/eth2spec/test/helpers/rewards.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,8 +17,8 @@


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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ 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

# 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
Expand Down Expand Up @@ -83,15 +83,15 @@ 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

# 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit e8b0c46

Please sign in to comment.