Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage improvements #1206

Merged
merged 49 commits into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b133ded
Eth1 data test
protolambda Jun 26, 2019
f54d1a5
eth1 voting no consensus test
protolambda Jun 21, 2019
13b67b4
sign blocks in eth1 vote tests
protolambda Jun 21, 2019
3279538
test invalid shard in attestation
protolambda Jun 21, 2019
f75e3dc
test old and future target epoch in attestation
protolambda Jun 22, 2019
64e15c5
improve intersection test, just 1 index is enough. And add invalid at…
protolambda Jun 22, 2019
1d6b1ca
expected deposit count test
protolambda Jun 22, 2019
55d86b4
effective balance testing in deposits
protolambda Jun 22, 2019
063d94b
Bugfix transfer tests
protolambda Jun 25, 2019
e79b47e
non-existent transfer participants tests
protolambda Jun 22, 2019
6266133
rename test methods based on suggestion
protolambda Jun 25, 2019
c4b88e6
different new-deposit tests
protolambda Jun 25, 2019
b4b4e95
test activation queue
protolambda Jun 25, 2019
0e3c2ce
fix transfer tests, add 2 new tests
protolambda Jun 25, 2019
b2034a5
generalize epoch processing testing, add final-processing tests
protolambda Jun 25, 2019
c4c9bd3
test_eth1_vote_no_reset
protolambda Jun 25, 2019
aedd281
clean up epoch processing testing
protolambda Jun 25, 2019
c66031f
fix crosslink tests, fix generalization of epoch processing
protolambda Jun 25, 2019
46dc3f3
detach crosslink tests from extra block
protolambda Jun 25, 2019
24aa064
new process-slashings tests, and epoch processing bugfix with transit…
protolambda Jun 26, 2019
7a418ed
test messed up indices in attester slashings
protolambda Jun 26, 2019
ff2d711
test block application on same and on previous slot state
protolambda Jun 26, 2019
8445d1d
fix formatting for lint
protolambda Jun 26, 2019
f7b3c87
check invalid state root
protolambda Jun 26, 2019
235c3d6
re-enable test_empty_epoch_transition_not_finalizing for minimal config
protolambda Jun 26, 2019
e49519a
wrong end epoch test
protolambda Jun 27, 2019
384fa88
justification/finalization testing groundwork
protolambda Jun 27, 2019
3a60f64
refactor finalization test helper func
protolambda Jun 28, 2019
d31f1b2
Merge branch 'dev' into cov-hunt
protolambda Jun 29, 2019
518db42
fix attestation tests to work with checkpoints
protolambda Jun 29, 2019
efd9d17
update attester slashings processing tests
protolambda Jun 29, 2019
afb34c7
fix broken block test for checkpoint use
protolambda Jun 29, 2019
cfbdee7
finalization testing
protolambda Jun 29, 2019
f484b1e
some fixes to finality_12
djrtwo Jun 29, 2019
1885e28
fix source/target epochs in test_12
djrtwo Jun 29, 2019
bc5e947
aggregation_bitfield - bits
djrtwo Jun 29, 2019
022f1e7
fix source/target
djrtwo Jun 29, 2019
129fd62
add shard to mock crosslink to separate attestations from eachother
djrtwo Jun 29, 2019
b05bebf
Fix list slicing
CarlBeek Jun 29, 2019
f9ca7c9
Fix 123 finalisation
CarlBeek Jun 29, 2019
2eca6ef
Corrects justification comments
CarlBeek Jun 29, 2019
0680d8c
Makes justification ratios more marginal
CarlBeek Jun 29, 2019
4ed7af7
mock attestation refactor
CarlBeek Jun 29, 2019
0c29c51
Finnish refactor
CarlBeek Jun 29, 2019
5d633bf
bugfix attestation creation so that it works on mainnet with multiple…
protolambda Jun 29, 2019
b0510fe
Merge pull request #1228 from ethereum/cov-hunt-fix-ish
protolambda Jun 29, 2019
302b3af
rename/fix roots in justification tests for consistency
protolambda Jun 29, 2019
afb33dd
fix typo in justification wording
protolambda Jun 29, 2019
36dd977
fix finalize on double justification in 123 rule
protolambda Jun 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test_libs/pyspec/eth2spec/test/helpers/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from eth2spec.utils.ssz.ssz_impl import signing_root


def get_valid_transfer(spec, state, slot=None, sender_index=None, amount=None, fee=None, signed=False):
def get_valid_transfer(spec, state, slot=None, sender_index=None,
recipient_index=None, amount=None, fee=None, signed=False):
if slot is None:
slot = state.slot
current_epoch = spec.get_current_epoch(state)
if sender_index is None:
sender_index = spec.get_active_validator_indices(state, current_epoch)[-1]
recipient_index = spec.get_active_validator_indices(state, current_epoch)[0]
if recipient_index is None:
recipient_index = spec.get_active_validator_indices(state, current_epoch)[0]
transfer_pubkey = pubkeys[-1]
transfer_privkey = privkeys[-1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def test_success_since_max_epochs_per_crosslink(spec, state):
yield from run_attestation_processing(spec, state, attestation)


@with_all_phases
@spec_state_test
def test_wrong_end_epoch_with_max_epochs_per_crosslink(spec, state):
for _ in range(spec.MAX_EPOCHS_PER_CROSSLINK + 2):
next_epoch(spec, state)
apply_empty_block(spec, state)

attestation = get_valid_attestation(spec, state)
data = attestation.data
# test logic sanity check: make sure the attestation only includes MAX_EPOCHS_PER_CROSSLINK epochs
assert data.crosslink.end_epoch - data.crosslink.start_epoch == spec.MAX_EPOCHS_PER_CROSSLINK
# Now change it to be different
data.crosslink.end_epoch += 1

sign_attestation(spec, state, attestation)

for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(spec, state)
apply_empty_block(spec, state)

yield from run_attestation_processing(spec, state, attestation, False)


@with_all_phases
@always_bls
@spec_state_test
Expand Down Expand Up @@ -147,6 +170,47 @@ def test_wrong_shard(spec, state):
yield from run_attestation_processing(spec, state, attestation, False)


@with_all_phases
@spec_state_test
def test_invalid_shard(spec, state):
attestation = get_valid_attestation(spec, state)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

# off by one (with respect to valid range) on purpose
attestation.data.crosslink.shard = spec.SHARD_COUNT

sign_attestation(spec, state, attestation)

yield from run_attestation_processing(spec, state, attestation, False)


@with_all_phases
@spec_state_test
def test_old_target_epoch(spec, state):
assert spec.MIN_ATTESTATION_INCLUSION_DELAY < spec.SLOTS_PER_EPOCH * 2

attestation = get_valid_attestation(spec, state, signed=True)

state.slot = spec.SLOTS_PER_EPOCH * 2 # target epoch will be too old to handle

yield from run_attestation_processing(spec, state, attestation, False)


@with_all_phases
@spec_state_test
def test_future_target_epoch(spec, state):
assert spec.MIN_ATTESTATION_INCLUSION_DELAY < spec.SLOTS_PER_EPOCH * 2

attestation = get_valid_attestation(spec, state)

state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.target.epoch = spec.get_current_epoch(state) + 1 # target epoch will be too new to handle
sign_attestation(spec, state, attestation)

yield from run_attestation_processing(spec, state, attestation, False)


@with_all_phases
@spec_state_test
def test_new_source_epoch(spec, state):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,106 @@ def test_participants_already_slashed(spec, state):

@with_all_phases
@spec_state_test
def test_custody_bit_0_and_1(spec, state):
def test_custody_bit_0_and_1_intersect(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=True)

attester_slashing.attestation_1.custody_bit_1_indices = (
attester_slashing.attestation_1.custody_bit_0_indices
attester_slashing.attestation_1.custody_bit_1_indices.append(
attester_slashing.attestation_1.custody_bit_0_indices[0]
)

sign_indexed_attestation(spec, state, attester_slashing.attestation_1)

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@always_bls
@with_all_phases
@spec_state_test
def test_att1_bad_extra_index(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True)

indices = attester_slashing.attestation_1.custody_bit_0_indices
options = list(set(range(len(state.validators))) - set(indices))
indices.append(options[len(options) // 2]) # add random index, not previously in attestation.
attester_slashing.attestation_1.custody_bit_0_indices = sorted(indices)
# Do not sign the modified attestation (it's ok to slash if attester signed, not if they did not),
# see if the bad extra index is spotted, and slashing is aborted.

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@always_bls
@with_all_phases
@spec_state_test
def test_att1_bad_replaced_index(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True)

indices = attester_slashing.attestation_1.custody_bit_0_indices
options = list(set(range(len(state.validators))) - set(indices))
indices[3] = options[len(options) // 2] # replace with random index, not previously in attestation.
attester_slashing.attestation_1.custody_bit_0_indices = sorted(indices)
# Do not sign the modified attestation (it's ok to slash if attester signed, not if they did not),
# see if the bad replaced index is spotted, and slashing is aborted.

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@always_bls
@with_all_phases
@spec_state_test
def test_att2_bad_extra_index(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True)

indices = attester_slashing.attestation_2.custody_bit_0_indices
options = list(set(range(len(state.validators))) - set(indices))
indices.append(options[len(options) // 2]) # add random index, not previously in attestation.
attester_slashing.attestation_2.custody_bit_0_indices = sorted(indices)
# Do not sign the modified attestation (it's ok to slash if attester signed, not if they did not),
# see if the bad extra index is spotted, and slashing is aborted.

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@always_bls
@with_all_phases
@spec_state_test
def test_att2_bad_replaced_index(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True)

indices = attester_slashing.attestation_2.custody_bit_0_indices
options = list(set(range(len(state.validators))) - set(indices))
indices[3] = options[len(options) // 2] # replace with random index, not previously in attestation.
attester_slashing.attestation_2.custody_bit_0_indices = sorted(indices)
# Do not sign the modified attestation (it's ok to slash if attester signed, not if they did not),
# see if the bad replaced index is spotted, and slashing is aborted.

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@with_all_phases
@spec_state_test
def test_unsorted_att_1_bit0(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=True)

indices = attester_slashing.attestation_1.custody_bit_0_indices
assert len(indices) >= 3
indices[1], indices[2] = indices[2], indices[1] # unsort second and third index
sign_indexed_attestation(spec, state, attester_slashing.attestation_1)

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


@with_all_phases
@spec_state_test
def test_unsorted_att_2_bit0(spec, state):
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=False)

indices = attester_slashing.attestation_2.custody_bit_0_indices
assert len(indices) >= 3
indices[1], indices[2] = indices[2], indices[1] # unsort second and third index
sign_indexed_attestation(spec, state, attester_slashing.attestation_2)

yield from run_attester_slashing_processing(spec, state, attester_slashing, False)


# note: unsorted indices for custody bit 0 are to be introduced in phase 1 testing.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,50 @@ def run_deposit_processing(spec, state, deposit, validator_index, valid=True, ef
assert len(state.balances) == pre_validator_count + 1
assert get_balance(state, validator_index) == pre_balance + deposit.data.amount

effective = min(spec.MAX_EFFECTIVE_BALANCE,
pre_balance + deposit.data.amount)
effective -= effective % spec.EFFECTIVE_BALANCE_INCREMENT
assert state.validators[validator_index].effective_balance == effective

assert state.eth1_deposit_index == state.eth1_data.deposit_count


@with_all_phases
@spec_state_test
def test_new_deposit(spec, state):
def test_new_deposit_under_max(spec, state):
# fresh deposit = next validator index = validator appended to registry
validator_index = len(state.validators)
# effective balance will be 1 EFFECTIVE_BALANCE_INCREMENT smaller because of this small decrement.
amount = spec.MAX_EFFECTIVE_BALANCE - 1
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)

yield from run_deposit_processing(spec, state, deposit, validator_index)


@with_all_phases
@spec_state_test
def test_new_deposit_max(spec, state):
# fresh deposit = next validator index = validator appended to registry
validator_index = len(state.validators)
# effective balance will be exactly the same as balance.
amount = spec.MAX_EFFECTIVE_BALANCE
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)

yield from run_deposit_processing(spec, state, deposit, validator_index)


@with_all_phases
@spec_state_test
def test_new_deposit_over_max(spec, state):
# fresh deposit = next validator index = validator appended to registry
validator_index = len(state.validators)
# just 1 over the limit, effective balance should be set MAX_EFFECTIVE_BALANCE during processing
amount = spec.MAX_EFFECTIVE_BALANCE + 1
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)

yield from run_deposit_processing(spec, state, deposit, validator_index)


@with_all_phases
@always_bls
@spec_state_test
Expand Down
Loading