From b3f7dd9dae4cb3bd7a5e004ebe64b44427e8bf8c Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 20 Sep 2019 16:05:10 -0500 Subject: [PATCH] fix up rewards/penalties test signatures --- .../eth2spec/test/helpers/attestations.py | 5 +++- .../test_process_crosslinks.py | 24 ++++++++----------- .../test_process_rewards_and_penalties.py | 9 ++++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/helpers/attestations.py b/test_libs/pyspec/eth2spec/test/helpers/attestations.py index 43d9bf44f..394579413 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/attestations.py +++ b/test_libs/pyspec/eth2spec/test/helpers/attestations.py @@ -128,7 +128,7 @@ def get_attestation_signature(spec, state, attestation_data, privkey, custody_bi ) -def fill_aggregate_attestation(spec, state, attestation): +def fill_aggregate_attestation(spec, state, attestation, signed=False): crosslink_committee = spec.get_crosslink_committee( state, attestation.data.target.epoch, @@ -137,6 +137,9 @@ def fill_aggregate_attestation(spec, state, attestation): for i in range(len(crosslink_committee)): attestation.aggregation_bits[i] = True + if signed: + sign_attestation(spec, state, attestation) + def add_attestations_to_state(spec, state, attestations, slot): block = build_empty_block_for_next_slot(spec, state) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_crosslinks.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_crosslinks.py index a335896df..83e2bb017 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_crosslinks.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_crosslinks.py @@ -10,7 +10,6 @@ from eth2spec.test.helpers.attestations import ( add_attestations_to_state, fill_aggregate_attestation, get_valid_attestation, - sign_attestation, ) from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with @@ -33,9 +32,9 @@ def test_no_attestations(spec, state): def test_single_crosslink_update_from_current_epoch(spec, state): next_epoch(spec, state) - attestation = get_valid_attestation(spec, state, signed=True) + attestation = get_valid_attestation(spec, state) - fill_aggregate_attestation(spec, state, attestation) + fill_aggregate_attestation(spec, state, attestation, signed=True) add_attestations_to_state(spec, state, [attestation], state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) assert len(state.current_epoch_attestations) == 1 @@ -54,9 +53,9 @@ def test_single_crosslink_update_from_current_epoch(spec, state): def test_single_crosslink_update_from_previous_epoch(spec, state): next_epoch(spec, state) - attestation = get_valid_attestation(spec, state, signed=True) + attestation = get_valid_attestation(spec, state) - fill_aggregate_attestation(spec, state, attestation) + fill_aggregate_attestation(spec, state, attestation, signed=True) add_attestations_to_state(spec, state, [attestation], state.slot + spec.SLOTS_PER_EPOCH) assert len(state.previous_epoch_attestations) == 1 @@ -90,8 +89,8 @@ def test_double_late_crosslink(spec, state): next_epoch(spec, state) state.slot += 4 - attestation_1 = get_valid_attestation(spec, state, signed=True) - fill_aggregate_attestation(spec, state, attestation_1) + attestation_1 = get_valid_attestation(spec, state) + fill_aggregate_attestation(spec, state, attestation_1, signed=True) # add attestation_1 to next epoch next_epoch(spec, state) @@ -100,13 +99,11 @@ def test_double_late_crosslink(spec, state): for _ in range(spec.SLOTS_PER_EPOCH): attestation_2 = get_valid_attestation(spec, state) if attestation_2.data.crosslink.shard == attestation_1.data.crosslink.shard: - sign_attestation(spec, state, attestation_2) + fill_aggregate_attestation(spec, state, attestation_2, signed=True) break next_slot(spec, state) apply_empty_block(spec, state) - fill_aggregate_attestation(spec, state, attestation_2) - # add attestation_2 in the next epoch after attestation_1 has # already updated the relevant crosslink next_epoch(spec, state) @@ -141,8 +138,8 @@ def test_tied_crosslink_between_epochs(spec, state): Ensure that ties on crosslinks between epochs are broken by previous epoch. """ - prev_attestation = get_valid_attestation(spec, state, signed=True) - fill_aggregate_attestation(spec, state, prev_attestation) + prev_attestation = get_valid_attestation(spec, state) + fill_aggregate_attestation(spec, state, prev_attestation, signed=True) # add attestation at start of next epoch next_epoch(spec, state) @@ -152,10 +149,9 @@ def test_tied_crosslink_between_epochs(spec, state): for _ in range(spec.SLOTS_PER_EPOCH): cur_attestation = get_valid_attestation(spec, state) if cur_attestation.data.crosslink.shard == prev_attestation.data.crosslink.shard: - sign_attestation(spec, state, cur_attestation) + fill_aggregate_attestation(spec, state, cur_attestation, signed=True) break next_slot(spec, state) - fill_aggregate_attestation(spec, state, cur_attestation) add_attestations_to_state(spec, state, [cur_attestation], state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) 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 8b79e8d68..e42092941 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 @@ -9,7 +9,6 @@ from eth2spec.test.helpers.attestations import ( add_attestations_to_state, fill_aggregate_attestation, get_valid_attestation, - sign_attestation, ) from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with @@ -36,8 +35,8 @@ def test_genesis_epoch_no_attestations_no_penalties(spec, state): def test_genesis_epoch_full_attestations_no_rewards(spec, state): attestations = [] for slot in range(spec.SLOTS_PER_EPOCH - spec.MIN_ATTESTATION_INCLUSION_DELAY - 1): - attestation = get_valid_attestation(spec, state, signed=True) - fill_aggregate_attestation(spec, state, attestation) + attestation = get_valid_attestation(spec, state) + fill_aggregate_attestation(spec, state, attestation, signed=True) attestations.append(attestation) next_slot(spec, state) add_attestations_to_state(spec, state, attestations, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) @@ -67,8 +66,8 @@ def test_no_attestations_all_penalties(spec, state): @with_all_phases @spec_state_test def test_duplicate_attestation(spec, state): - attestation = get_valid_attestation(spec, state, signed=True) - fill_aggregate_attestation(spec, state, attestation) + attestation = get_valid_attestation(spec, state) + fill_aggregate_attestation(spec, state, attestation, signed=True) indexed_attestation = spec.get_indexed_attestation(state, attestation) participants = indexed_attestation.custody_bit_0_indices + indexed_attestation.custody_bit_1_indices