From 1aa12034e55867554739b0f941aecb65b83edf27 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 22 Sep 2019 09:51:12 -0500 Subject: [PATCH] make full_attestation reward test better --- .../test_process_rewards_and_penalties.py | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_rewards_and_penalties.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_rewards_and_penalties.py index f0cde1a73..114898abf 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_rewards_and_penalties.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_rewards_and_penalties.py @@ -55,14 +55,20 @@ def test_genesis_epoch_full_attestations_no_rewards(spec, state): @spec_state_test def test_full_attestations(spec, state): attestations = [] - for slot in range(spec.SLOTS_PER_EPOCH - spec.MIN_ATTESTATION_INCLUSION_DELAY): - attestation = get_valid_attestation(spec, state) - fill_aggregate_attestation(spec, state, attestation, signed=True) - attestations.append(attestation) + for slot in range(spec.SLOTS_PER_EPOCH + spec.MIN_ATTESTATION_INCLUSION_DELAY): + # create an attestation for each slot in epoch + if slot < spec.SLOTS_PER_EPOCH: + attestation = get_valid_attestation(spec, state) + fill_aggregate_attestation(spec, state, attestation, signed=True) + attestations.append(attestation) + # fill each created slot in state after inclusion delay + if slot - spec.MIN_ATTESTATION_INCLUSION_DELAY >= 0: + include_att = attestations[slot - spec.MIN_ATTESTATION_INCLUSION_DELAY] + add_attestations_to_state(spec, state, [include_att], state.slot) next_slot(spec, state) - add_attestations_to_state(spec, state, attestations, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) assert spec.compute_epoch_of_slot(state.slot) == spec.GENESIS_EPOCH + 1 + assert len(state.previous_epoch_attestations) == spec.SLOTS_PER_EPOCH pre_state = deepcopy(state) @@ -70,8 +76,11 @@ def test_full_attestations(spec, state): attesting_indices = spec.get_unslashed_attesting_indices(state, attestations) assert len(attesting_indices) > 0 - for index in attesting_indices: - assert state.balances[index] > pre_state.balances[index] + for index in range(len(pre_state.validators)): + if index in attesting_indices: + assert state.balances[index] > pre_state.balances[index] + else: + assert state.balances[index] < pre_state.balances[index] @with_all_phases