(state)
| 480 | |
| 481 | # @timeit |
| 482 | def test_voluntary_exit(state): |
| 483 | pre_state = deepcopy(state) |
| 484 | validator_index = get_active_validator_indices(pre_state.validator_registry, get_current_epoch(pre_state))[-1] |
| 485 | pubkey = pubkeys[validator_index] |
| 486 | |
| 487 | # move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit |
| 488 | pre_state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH |
| 489 | # artificially trigger registry update at next epoch transition |
| 490 | pre_state.validator_registry_update_epoch -= 1 |
| 491 | |
| 492 | post_state = deepcopy(pre_state) |
| 493 | |
| 494 | voluntary_exit = VoluntaryExit( |
| 495 | epoch=get_current_epoch(pre_state), |
| 496 | validator_index=validator_index, |
| 497 | signature=b'\x00'*96, |
| 498 | ) |
| 499 | voluntary_exit.signature = bls.sign( |
| 500 | message_hash=signed_root(voluntary_exit), |
| 501 | privkey=pubkey_to_privkey[pubkey], |
| 502 | domain=get_domain( |
| 503 | fork=pre_state.fork, |
| 504 | epoch=get_current_epoch(pre_state), |
| 505 | domain_type=spec.DOMAIN_VOLUNTARY_EXIT, |
| 506 | ) |
| 507 | ) |
| 508 | |
| 509 | # |
| 510 | # Add to state via block transition |
| 511 | # |
| 512 | initiate_exit_block = construct_empty_block_for_next_slot(post_state) |
| 513 | initiate_exit_block.body.voluntary_exits.append(voluntary_exit) |
| 514 | state_transition(post_state, initiate_exit_block) |
| 515 | |
| 516 | assert not pre_state.validator_registry[validator_index].initiated_exit |
| 517 | assert post_state.validator_registry[validator_index].initiated_exit |
| 518 | assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH |
| 519 | |
| 520 | # |
| 521 | # Process within epoch transition |
| 522 | # |
| 523 | exit_block = construct_empty_block_for_next_slot(post_state) |
| 524 | exit_block.slot += spec.SLOTS_PER_EPOCH |
| 525 | state_transition(post_state, exit_block) |
| 526 | |
| 527 | assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH |
| 528 | |
| 529 | return pre_state, [initiate_exit_block, exit_block], post_state |
| 530 | |
| 531 | |
| 532 | # @timeit |
nothing calls this directly
no test coverage detected