mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-04 23:04:55 +00:00
Update tests
This commit is contained in:
parent
85adbfbc4d
commit
eb0cdc72e8
@ -24,6 +24,11 @@ from eth2spec.test.context import (
|
||||
with_presets,
|
||||
spec_state_test,
|
||||
always_bls,
|
||||
single_phase,
|
||||
with_custom_state,
|
||||
spec_test,
|
||||
default_balances_electra,
|
||||
default_activation_threshold,
|
||||
)
|
||||
|
||||
|
||||
@ -143,7 +148,9 @@ def is_duplicate_sync_committee(committee_indices):
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_sync_committee_rewards_nonduplicate_committee(spec, state):
|
||||
committee_indices = compute_committee_indices(state)
|
||||
|
||||
|
@ -24,6 +24,8 @@ from eth2spec.test.context import (
|
||||
with_custom_state,
|
||||
with_presets,
|
||||
spec_test,
|
||||
default_balances_electra,
|
||||
misc_balances_electra,
|
||||
)
|
||||
|
||||
|
||||
@ -132,7 +134,9 @@ def test_random_with_exits_with_duplicates(spec, state):
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_only_one_participant_without_duplicates(spec, state):
|
||||
rng = random.Random(501)
|
||||
yield from _test_harness_for_randomized_test_case(
|
||||
@ -144,7 +148,9 @@ def test_random_only_one_participant_without_duplicates(spec, state):
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_low_participation_without_duplicates(spec, state):
|
||||
rng = random.Random(601)
|
||||
yield from _test_harness_for_randomized_test_case(
|
||||
@ -156,7 +162,9 @@ def test_random_low_participation_without_duplicates(spec, state):
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_high_participation_without_duplicates(spec, state):
|
||||
rng = random.Random(701)
|
||||
yield from _test_harness_for_randomized_test_case(
|
||||
@ -168,7 +176,9 @@ def test_random_high_participation_without_duplicates(spec, state):
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_all_but_one_participating_without_duplicates(spec, state):
|
||||
rng = random.Random(801)
|
||||
yield from _test_harness_for_randomized_test_case(
|
||||
@ -181,7 +191,7 @@ def test_random_all_but_one_participating_without_duplicates(spec, state):
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold)
|
||||
@with_custom_state(balances_fn=misc_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_misc_balances_and_half_participation_without_duplicates(spec, state):
|
||||
rng = random.Random(1501)
|
||||
@ -194,7 +204,8 @@ def test_random_misc_balances_and_half_participation_without_duplicates(spec, st
|
||||
|
||||
@with_altair_and_later
|
||||
@with_presets([MINIMAL], reason="to create nonduplicate committee")
|
||||
@spec_state_test
|
||||
@spec_test
|
||||
@with_custom_state(balances_fn=default_balances_electra, threshold_fn=default_activation_threshold)
|
||||
@single_phase
|
||||
def test_random_with_exits_without_duplicates(spec, state):
|
||||
rng = random.Random(1502)
|
||||
|
@ -16,7 +16,7 @@ from .helpers.constants import (
|
||||
ALLOWED_TEST_RUNNER_FORKS,
|
||||
LIGHT_CLIENT_TESTING_FORKS,
|
||||
)
|
||||
from .helpers.forks import is_post_fork
|
||||
from .helpers.forks import is_post_fork, is_post_electra
|
||||
from .helpers.genesis import create_genesis_state
|
||||
from .helpers.typing import (
|
||||
Spec,
|
||||
@ -86,7 +86,10 @@ def default_activation_threshold(spec: Spec):
|
||||
Helper method to use the default balance activation threshold for state creation for tests.
|
||||
Usage: `@with_custom_state(threshold_fn=default_activation_threshold, ...)`
|
||||
"""
|
||||
return spec.MAX_EFFECTIVE_BALANCE
|
||||
if is_post_electra(spec):
|
||||
return spec.MIN_ACTIVATION_BALANCE
|
||||
else:
|
||||
return spec.MAX_EFFECTIVE_BALANCE
|
||||
|
||||
|
||||
def zero_activation_threshold(spec: Spec):
|
||||
@ -106,6 +109,18 @@ def default_balances(spec: Spec):
|
||||
return [spec.MAX_EFFECTIVE_BALANCE] * num_validators
|
||||
|
||||
|
||||
def default_balances_electra(spec: Spec):
|
||||
"""
|
||||
Helper method to create a series of default balances for Electra.
|
||||
Usage: `@with_custom_state(balances_fn=default_balances_electra, ...)`
|
||||
"""
|
||||
if not is_post_electra(spec):
|
||||
return default_balances(spec)
|
||||
|
||||
num_validators = spec.SLOTS_PER_EPOCH * 8
|
||||
return [spec.MAX_EFFECTIVE_BALANCE_ELECTRA] * num_validators
|
||||
|
||||
|
||||
def scaled_churn_balances_min_churn_limit(spec: Spec):
|
||||
"""
|
||||
Helper method to create enough validators to scale the churn limit.
|
||||
@ -175,6 +190,21 @@ def misc_balances(spec: Spec):
|
||||
return balances
|
||||
|
||||
|
||||
def misc_balances_electra(spec: Spec):
|
||||
"""
|
||||
Helper method to create a series of balances that includes some misc. balances for Electra.
|
||||
Usage: `@with_custom_state(balances_fn=misc_balances, ...)`
|
||||
"""
|
||||
if not is_post_electra(spec):
|
||||
return misc_balances(spec)
|
||||
|
||||
num_validators = spec.SLOTS_PER_EPOCH * 8
|
||||
balances = [spec.MAX_EFFECTIVE_BALANCE_ELECTRA * 2 * i // num_validators for i in range(num_validators)]
|
||||
rng = Random(1234)
|
||||
rng.shuffle(balances)
|
||||
return balances
|
||||
|
||||
|
||||
def misc_balances_in_default_range_with_many_validators(spec: Spec):
|
||||
"""
|
||||
Helper method to create a series of balances that includes some misc. balances but
|
||||
|
@ -15,8 +15,23 @@ from eth2spec.test.helpers.whisk import compute_whisk_initial_tracker_cached, co
|
||||
def build_mock_validator(spec, i: int, balance: int):
|
||||
active_pubkey = pubkeys[i]
|
||||
withdrawal_pubkey = pubkeys[-1 - i]
|
||||
# insecurely use pubkey as withdrawal key as well
|
||||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(withdrawal_pubkey)[1:]
|
||||
if is_post_electra(spec):
|
||||
if balance > spec.MIN_ACTIVATION_BALANCE:
|
||||
# use compounding withdrawal credentials if the balance is higher than MIN_ACTIVATION_BALANCE
|
||||
withdrawal_credentials = (
|
||||
spec.COMPOUNDING_WITHDRAWAL_PREFIX
|
||||
+ b'\x00' * 11
|
||||
+ spec.hash(withdrawal_pubkey)[12:]
|
||||
)
|
||||
else:
|
||||
# insecurely use pubkey as withdrawal key as well
|
||||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(withdrawal_pubkey)[1:]
|
||||
max_effective_balace = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
|
||||
else:
|
||||
# insecurely use pubkey as withdrawal key as well
|
||||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(withdrawal_pubkey)[1:]
|
||||
max_effective_balace = spec.MAX_EFFECTIVE_BALANCE
|
||||
|
||||
validator = spec.Validator(
|
||||
pubkey=active_pubkey,
|
||||
withdrawal_credentials=withdrawal_credentials,
|
||||
@ -24,7 +39,7 @@ def build_mock_validator(spec, i: int, balance: int):
|
||||
activation_epoch=spec.FAR_FUTURE_EPOCH,
|
||||
exit_epoch=spec.FAR_FUTURE_EPOCH,
|
||||
withdrawable_epoch=spec.FAR_FUTURE_EPOCH,
|
||||
effective_balance=min(balance - balance % spec.EFFECTIVE_BALANCE_INCREMENT, spec.MAX_EFFECTIVE_BALANCE)
|
||||
effective_balance=min(balance - balance % spec.EFFECTIVE_BALANCE_INCREMENT, max_effective_balace)
|
||||
)
|
||||
|
||||
return validator
|
||||
|
@ -11,6 +11,7 @@ from eth2spec.test.helpers.deposits import (
|
||||
)
|
||||
from eth2spec.test.helpers.forks import (
|
||||
is_post_altair,
|
||||
is_post_electra,
|
||||
)
|
||||
|
||||
|
||||
@ -69,9 +70,14 @@ def test_initialize_beacon_state_some_small_balances(spec):
|
||||
if is_post_altair(spec):
|
||||
yield 'description', 'meta', get_post_altair_description(spec)
|
||||
|
||||
if is_post_electra(spec):
|
||||
max_effective_balance = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
|
||||
else:
|
||||
max_effective_balance = spec.MAX_EFFECTIVE_BALANCE
|
||||
|
||||
main_deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||
main_deposits, _, deposit_data_list = prepare_full_genesis_deposits(
|
||||
spec, spec.MAX_EFFECTIVE_BALANCE,
|
||||
spec, max_effective_balance,
|
||||
deposit_count=main_deposit_count, signed=True,
|
||||
)
|
||||
# For deposits above, and for another deposit_count, add a balance of EFFECTIVE_BALANCE_INCREMENT
|
||||
@ -99,7 +105,7 @@ def test_initialize_beacon_state_some_small_balances(spec):
|
||||
assert state.eth1_data.deposit_count == len(deposits)
|
||||
assert state.eth1_data.block_hash == eth1_block_hash
|
||||
# only main deposits participate to the active balance
|
||||
assert spec.get_total_active_balance(state) == main_deposit_count * spec.MAX_EFFECTIVE_BALANCE
|
||||
assert spec.get_total_active_balance(state) == main_deposit_count * max_effective_balance
|
||||
|
||||
# yield state
|
||||
yield 'state', state
|
||||
|
Loading…
x
Reference in New Issue
Block a user