From 7710d4fa5c87d2f8e7b1e32f77b15b08851720c8 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 7 Jun 2021 07:55:04 -0600 Subject: [PATCH] add a few more preset/config invariants --- .../unittests/test_config_invariants.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/unittests/test_config_invariants.py b/tests/core/pyspec/eth2spec/test/phase0/unittests/test_config_invariants.py index 078b48ea5..b39b011b4 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/unittests/test_config_invariants.py +++ b/tests/core/pyspec/eth2spec/test/phase0/unittests/test_config_invariants.py @@ -18,13 +18,28 @@ def test_validators(spec, state): check_bound(spec.MAX_COMMITTEES_PER_SLOT, 1, MAX_UINT_64) check_bound(spec.TARGET_COMMITTEE_SIZE, 1, MAX_UINT_64) - check_bound(spec.MAX_VALIDATORS_PER_COMMITTEE, 1, spec.VALIDATOR_REGISTRY_LIMIT) + # Note: can be less if you assume stricters bounds on validator set based on total ETH supply + maximum_validators_per_committee = ( + spec.VALIDATOR_REGISTRY_LIMIT + // spec.SLOTS_PER_EPOCH + // spec.MAX_COMMITTEES_PER_SLOT + ) + check_bound(spec.MAX_VALIDATORS_PER_COMMITTEE, 1, maximum_validators_per_committee) check_bound(spec.config.MIN_PER_EPOCH_CHURN_LIMIT, 1, spec.VALIDATOR_REGISTRY_LIMIT) check_bound(spec.config.CHURN_LIMIT_QUOTIENT, 1, spec.VALIDATOR_REGISTRY_LIMIT) check_bound(spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, spec.TARGET_COMMITTEE_SIZE, MAX_UINT_64) +@with_all_phases +@spec_state_test +def test_balances(spec, state): + assert spec.MAX_EFFECTIVE_BALANCE % spec.EFFECTIVE_BALANCE_INCREMENT == 0 + check_bound(spec.MIN_DEPOSIT_AMOUNT, 1, MAX_UINT_64) + check_bound(spec.MAX_EFFECTIVE_BALANCE, spec.MIN_DEPOSIT_AMOUNT, MAX_UINT_64) + check_bound(spec.MAX_EFFECTIVE_BALANCE, spec.EFFECTIVE_BALANCE_INCREMENT, MAX_UINT_64) + + @with_all_phases @spec_state_test def test_hysteresis_quotient(spec, state): @@ -47,6 +62,10 @@ def test_incentives(spec, state): @spec_state_test def test_time(spec, state): assert spec.SLOTS_PER_EPOCH <= spec.SLOTS_PER_HISTORICAL_ROOT + assert spec.MIN_SEED_LOOKAHEAD < spec.MAX_SEED_LOOKAHEAD + assert spec.SLOTS_PER_HISTORICAL_ROOT % spec.SLOTS_PER_EPOCH == 0 + check_bound(spec.SLOTS_PER_HISTORICAL_ROOT, spec.SLOTS_PER_EPOCH, MAX_UINT_64) + check_bound(spec.MIN_ATTESTATION_INCLUSION_DELAY, 1, spec.SLOTS_PER_EPOCH) @with_all_phases