add rewards/penalties test for full epoch of attestations

This commit is contained in:
Danny Ryan 2019-09-22 09:35:18 -05:00
parent b3f7dd9dae
commit cf1323b79e
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 31 additions and 0 deletions

View File

@ -51,12 +51,37 @@ def test_genesis_epoch_full_attestations_no_rewards(spec, state):
assert state.balances[index] == pre_state.balances[index] assert state.balances[index] == pre_state.balances[index]
@with_all_phases
@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)
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
pre_state = deepcopy(state)
yield from run_process_rewards_and_penalties(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]
@with_all_phases @with_all_phases
@spec_state_test @spec_state_test
def test_no_attestations_all_penalties(spec, state): def test_no_attestations_all_penalties(spec, state):
next_epoch(spec, state) next_epoch(spec, state)
pre_state = deepcopy(state) pre_state = deepcopy(state)
assert spec.compute_epoch_of_slot(state.slot) == spec.GENESIS_EPOCH + 1
yield from run_process_rewards_and_penalties(spec, state) yield from run_process_rewards_and_penalties(spec, state)
for index in range(len(pre_state.validators)): for index in range(len(pre_state.validators)):
@ -66,6 +91,12 @@ 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):
"""
Although duplicate attestations can be included on-chain, they should only
be rewarded for once.
This test addresses this issue found at Interop
https://github.com/djrtwo/interop-test-cases/tree/master/tests/prysm_16_duplicate_attestation_rewards
"""
attestation = get_valid_attestation(spec, state) attestation = get_valid_attestation(spec, state)
fill_aggregate_attestation(spec, state, attestation, signed=True) fill_aggregate_attestation(spec, state, attestation, signed=True)