From 19583b7d51a851d7c5fa23a7656d15e3b47029dc Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:56:05 -0800 Subject: [PATCH 1/2] Add blocks with several withdrawal requests --- .../test/electra/sanity/blocks/test_blocks.py | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py index 5a4b98c3c8..d85dbf5cee 100644 --- a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py @@ -19,6 +19,7 @@ ) from eth2spec.test.helpers.withdrawals import ( set_eth1_withdrawal_credential_with_balance, + set_compounding_withdrawal_credential_with_balance, ) @@ -172,3 +173,79 @@ def test_cl_exit_and_el_withdrawal_request_in_same_block(spec, state): yield 'post', state assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH + +@with_electra_and_later +@spec_state_test +def test_multiple_el_partial_withdrawal_requests_same_validator(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + validator_index = 0 + address = b'\x22' * 20 + balance = spec.MIN_ACTIVATION_BALANCE + 2000000000 + set_compounding_withdrawal_credential_with_balance(spec, state, validator_index, balance, balance, address) + + assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + + yield 'pre', state + + validator_pubkey = state.validators[validator_index].pubkey + withdrawal_request_1 = spec.WithdrawalRequest( + source_address=address, + validator_pubkey=validator_pubkey, + amount=spec.Gwei(1), + ) + withdrawal_request_2 = spec.WithdrawalRequest( + source_address=address, + validator_pubkey=validator_pubkey, + amount=spec.Gwei(2), + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.execution_requests.withdrawals = [withdrawal_request_1, withdrawal_request_2] + block.body.execution_payload.block_hash = compute_el_block_hash_for_block(spec, block) + signed_block = state_transition_and_sign_block(spec, state, block) + + yield 'blocks', [signed_block] + yield 'post', state + + assert len(state.pending_partial_withdrawals) == 2 + assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + +@with_electra_and_later +@spec_state_test +def test_multiple_el_partial_withdrawal_requests_different_validator(spec, state): + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + validator_indices = [1, 2] + addresses = [bytes([v * 0x11]) * 20 for v in validator_indices] + balances = [spec.MIN_ACTIVATION_BALANCE + v * 2000000000 for v in validator_indices] + + for validator_index, address, balance in zip(validator_indices, addresses, balances): + set_compounding_withdrawal_credential_with_balance(spec, state, validator_index, balance, balance, address) + assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + + yield 'pre', state + + withdrawal_requests = [] + + for validator_index, address in zip(validator_indices, addresses): + validator_pubkey = state.validators[validator_index].pubkey + withdrawal_request = spec.WithdrawalRequest( + source_address=address, + validator_pubkey=validator_pubkey, + amount=spec.Gwei(validator_index), + ) + withdrawal_requests.append(withdrawal_request) + + block = build_empty_block_for_next_slot(spec, state) + block.body.execution_requests.withdrawals = withdrawal_requests + block.body.execution_payload.block_hash = compute_el_block_hash_for_block(spec, block) + signed_block = state_transition_and_sign_block(spec, state, block) + + yield 'blocks', [signed_block] + yield 'post', state + + assert len(state.pending_partial_withdrawals) == 2 + for validator_index in validator_indices: + assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH \ No newline at end of file From ad63ae7e38be6c98d4fe2b3ace273818901082bc Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 21 Jan 2025 13:47:42 +0600 Subject: [PATCH 2/2] Fix lint --- .../pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py index d85dbf5cee..e5b07cd3dd 100644 --- a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py @@ -174,6 +174,7 @@ def test_cl_exit_and_el_withdrawal_request_in_same_block(spec, state): assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH + @with_electra_and_later @spec_state_test def test_multiple_el_partial_withdrawal_requests_same_validator(spec, state): @@ -211,6 +212,7 @@ def test_multiple_el_partial_withdrawal_requests_same_validator(spec, state): assert len(state.pending_partial_withdrawals) == 2 assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + @with_electra_and_later @spec_state_test def test_multiple_el_partial_withdrawal_requests_different_validator(spec, state): @@ -248,4 +250,4 @@ def test_multiple_el_partial_withdrawal_requests_different_validator(spec, state assert len(state.pending_partial_withdrawals) == 2 for validator_index in validator_indices: - assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH \ No newline at end of file + assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH