From 6da2c7a91671868b6c3bdcc0daf1482d07a1b153 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 21 Aug 2021 16:59:54 -0700 Subject: [PATCH] ensure all validators in randomized test are active --- tests/core/pyspec/eth2spec/test/context.py | 15 +++++++++++++++ .../test/phase0/sanity/test_blocks_random.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/context.py b/tests/core/pyspec/eth2spec/test/context.py index 7fddc0762..a6828f7e0 100644 --- a/tests/core/pyspec/eth2spec/test/context.py +++ b/tests/core/pyspec/eth2spec/test/context.py @@ -152,6 +152,21 @@ def misc_balances(spec): return balances +def misc_balances_in_default_range(spec): + """ + Helper method to create a series of balances that includes some misc. balances but + none that are below the ``EJECTION_BALANCE``. + """ + num_validators = spec.SLOTS_PER_EPOCH * 8 + floor = spec.config.EJECTION_BALANCE + spec.EFFECTIVE_BALANCE_INCREMENT + balances = [ + max(spec.MAX_EFFECTIVE_BALANCE * 2 * i // num_validators, floor) for i in range(num_validators) + ] + rng = Random(1234) + rng.shuffle(balances) + return balances + + def low_single_balance(spec): """ Helper method to create a single of balance of 1 Gwei. diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 8767ad12c..f015362ac 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -1,7 +1,7 @@ import itertools from random import Random from typing import Callable -from tests.core.pyspec.eth2spec.test.context import default_activation_threshold +from tests.core.pyspec.eth2spec.test.context import default_activation_threshold, misc_balances_in_default_range from eth2spec.test.helpers.multi_operations import ( build_random_block_from_state, ) @@ -272,7 +272,7 @@ def _iter_temporal(spec, callable_or_int): @pytest_generate_tests_adapter @with_all_phases -@with_custom_state(balances_fn=misc_balances, threshold_fn=default_activation_threshold) +@with_custom_state(balances_fn=misc_balances_in_default_range, threshold_fn=default_activation_threshold) @spec_test @single_phase @always_bls