-
Notifications
You must be signed in to change notification settings - Fork 1.1k
JMcK sample tests for review #4147
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
Changes from 2 commits
35380dc
e1ca8f1
b84cfc8
bb26606
e209c35
02af1b1
a3ce0bc
47b598a
9d8c876
a6c70d9
eaf057f
05f921c
5553849
d38be4a
1781459
a6fcc3c
87ee8fe
c468088
20f40b6
9bcae21
c9cca56
9225047
d95f784
34fe888
6c413dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from eth2spec.test.context import ( | ||
spec_state_test, | ||
with_capella_and_later, | ||
) | ||
|
||
|
||
@with_capella_and_later | ||
@spec_state_test | ||
def test_validator_appears_only_once_in_attestation(spec, state): | ||
""" | ||
A test to confirm that the validator_index of the validators in an attestation committee are unique and there | ||
are no duplicate validators | ||
""" | ||
slot = state.slot | ||
epoch = slot // spec.SLOTS_PER_EPOCH | ||
|
||
# Get the number of committees assigned per slot in the current epoch | ||
slot_committee_count = spec.get_committee_count_per_slot(state, epoch) | ||
|
||
# Get the list of validators for each committee in the slot | ||
validators = [] | ||
for committee in range(slot_committee_count): | ||
validator_index = spec.get_committee_assignment(state, epoch, committee) | ||
|
||
# There are tuples and individual validators in the list, so they need to be extracted | ||
if isinstance(validator_index, tuple): | ||
validators.extend(validator_index[0]) | ||
elif isinstance(validator_index, list): | ||
validators.extend(validator_index) | ||
else: | ||
validators.append(validator_index) | ||
|
||
# Check that the assigned_validators list is not empty | ||
assert len(validators) > 0 | ||
|
||
# Confirm that the same validator does not appear more than once in the list of validators | ||
validator_ids = set() | ||
for validator_id in validators: | ||
assert validator_id not in validator_ids | ||
validator_ids.add(validator_id) | ||
|
||
yield "committee_assignments", validator_ids | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,31 @@ def test_success_top_up_to_withdrawn_validator(spec, state): | |
assert has_execution_withdrawal and is_withdrawable and has_non_zero_balance | ||
else: | ||
assert spec.is_fully_withdrawable_validator(validator, balance, current_epoch) | ||
|
||
|
||
@with_capella_and_later | ||
@spec_state_test | ||
def test_validator_invalid_high_funding_after_withdrawal(spec, state): | ||
""" | ||
Simple extension of the previous test_success_top_up_to_withdrawn_validator in order to add a negative scenario | ||
where a user deposits 2x MAX_EFFECTIVE_BALANCE. | ||
""" | ||
validator_index = 5 # Example validator index | ||
|
||
# Fully withdraw the validator | ||
set_validator_fully_withdrawable(spec, state, validator_index) | ||
assert state.balances[validator_index] > 0 | ||
|
||
next_epoch_via_block(spec, state) | ||
assert state.balances[validator_index] == 0 | ||
assert state.validators[validator_index].effective_balance > 0 | ||
|
||
next_epoch_via_block(spec, state) | ||
assert state.validators[validator_index].effective_balance == 0 | ||
|
||
# Make a top-up balance to validator - attempt to deposit double the max deposit) | ||
deposit = spec.MAX_EFFECTIVE_BALANCE * 2 | ||
|
||
# Handle the negative test based on the readme - no post state | ||
if deposit > spec.MAX_EFFECTIVE_BALANCE: | ||
yield 'post', None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is flawed for a few reasons.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey again. No worries, this stuff is pretty complicated. I would suggest updating this test to check that a top up deposit greater than MAX_EFFECTIVE_BALANCE (before and after electra) still works. And that the validator's balance (not its effective balance) is not limited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is interesting. I have a few questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll submit an updated version for both tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey James. Yes, it would go into the phase0 directory with
@with_all_phases
. And I see. Unfortunately, we cannot yield committee assignments here as there's a standard format that clients expect. Please refer to othertest_process_attestation.py
files to see the way things are done. For example:consensus-specs/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attestation.py
Lines 55 to 62 in 36d80ad
I believe this is the relevant format file.