fix up rewards/penalties test signatures

This commit is contained in:
Danny Ryan 2019-09-20 16:05:10 -05:00
parent ad4da4cd14
commit b3f7dd9dae
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 18 additions and 20 deletions

View File

@ -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( crosslink_committee = spec.get_crosslink_committee(
state, state,
attestation.data.target.epoch, attestation.data.target.epoch,
@ -137,6 +137,9 @@ def fill_aggregate_attestation(spec, state, attestation):
for i in range(len(crosslink_committee)): for i in range(len(crosslink_committee)):
attestation.aggregation_bits[i] = True attestation.aggregation_bits[i] = True
if signed:
sign_attestation(spec, state, attestation)
def add_attestations_to_state(spec, state, attestations, slot): def add_attestations_to_state(spec, state, attestations, slot):
block = build_empty_block_for_next_slot(spec, state) block = build_empty_block_for_next_slot(spec, state)

View File

@ -10,7 +10,6 @@ from eth2spec.test.helpers.attestations import (
add_attestations_to_state, add_attestations_to_state,
fill_aggregate_attestation, fill_aggregate_attestation,
get_valid_attestation, get_valid_attestation,
sign_attestation,
) )
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with 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): def test_single_crosslink_update_from_current_epoch(spec, state):
next_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) add_attestations_to_state(spec, state, [attestation], state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
assert len(state.current_epoch_attestations) == 1 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): def test_single_crosslink_update_from_previous_epoch(spec, state):
next_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) add_attestations_to_state(spec, state, [attestation], state.slot + spec.SLOTS_PER_EPOCH)
assert len(state.previous_epoch_attestations) == 1 assert len(state.previous_epoch_attestations) == 1
@ -90,8 +89,8 @@ def test_double_late_crosslink(spec, state):
next_epoch(spec, state) next_epoch(spec, state)
state.slot += 4 state.slot += 4
attestation_1 = get_valid_attestation(spec, state, signed=True) attestation_1 = get_valid_attestation(spec, state)
fill_aggregate_attestation(spec, state, attestation_1) fill_aggregate_attestation(spec, state, attestation_1, signed=True)
# add attestation_1 to next epoch # add attestation_1 to next epoch
next_epoch(spec, state) next_epoch(spec, state)
@ -100,13 +99,11 @@ def test_double_late_crosslink(spec, state):
for _ in range(spec.SLOTS_PER_EPOCH): for _ in range(spec.SLOTS_PER_EPOCH):
attestation_2 = get_valid_attestation(spec, state) attestation_2 = get_valid_attestation(spec, state)
if attestation_2.data.crosslink.shard == attestation_1.data.crosslink.shard: 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 break
next_slot(spec, state) next_slot(spec, state)
apply_empty_block(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 # add attestation_2 in the next epoch after attestation_1 has
# already updated the relevant crosslink # already updated the relevant crosslink
next_epoch(spec, state) 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. Ensure that ties on crosslinks between epochs are broken by previous epoch.
""" """
prev_attestation = get_valid_attestation(spec, state, signed=True) prev_attestation = get_valid_attestation(spec, state)
fill_aggregate_attestation(spec, state, prev_attestation) fill_aggregate_attestation(spec, state, prev_attestation, signed=True)
# add attestation at start of next epoch # add attestation at start of next epoch
next_epoch(spec, state) next_epoch(spec, state)
@ -152,10 +149,9 @@ def test_tied_crosslink_between_epochs(spec, state):
for _ in range(spec.SLOTS_PER_EPOCH): for _ in range(spec.SLOTS_PER_EPOCH):
cur_attestation = get_valid_attestation(spec, state) cur_attestation = get_valid_attestation(spec, state)
if cur_attestation.data.crosslink.shard == prev_attestation.data.crosslink.shard: 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 break
next_slot(spec, state) 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) add_attestations_to_state(spec, state, [cur_attestation], state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)

View File

@ -9,7 +9,6 @@ from eth2spec.test.helpers.attestations import (
add_attestations_to_state, add_attestations_to_state,
fill_aggregate_attestation, fill_aggregate_attestation,
get_valid_attestation, get_valid_attestation,
sign_attestation,
) )
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with 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): def test_genesis_epoch_full_attestations_no_rewards(spec, state):
attestations = [] attestations = []
for slot in range(spec.SLOTS_PER_EPOCH - spec.MIN_ATTESTATION_INCLUSION_DELAY - 1): for slot in range(spec.SLOTS_PER_EPOCH - spec.MIN_ATTESTATION_INCLUSION_DELAY - 1):
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)
attestations.append(attestation) attestations.append(attestation)
next_slot(spec, state) next_slot(spec, state)
add_attestations_to_state(spec, state, attestations, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) 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 @with_all_phases
@spec_state_test @spec_state_test
def test_duplicate_attestation(spec, state): def test_duplicate_attestation(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)
indexed_attestation = spec.get_indexed_attestation(state, attestation) indexed_attestation = spec.get_indexed_attestation(state, attestation)
participants = indexed_attestation.custody_bit_0_indices + indexed_attestation.custody_bit_1_indices participants = indexed_attestation.custody_bit_0_indices + indexed_attestation.custody_bit_1_indices