(state)
| 531 | |
| 532 | # @timeit |
| 533 | def test_transfer(state): |
| 534 | pre_state = deepcopy(state) |
| 535 | current_epoch = get_current_epoch(pre_state) |
| 536 | sender_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[-1] |
| 537 | recipient_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0] |
| 538 | transfer_pubkey = pubkeys[-1] |
| 539 | transfer_privkey = pubkey_to_privkey[transfer_pubkey] |
| 540 | amount = pre_state.validator_balances[sender_index] |
| 541 | pre_transfer_recipient_balance = pre_state.validator_balances[recipient_index] |
| 542 | transfer = Transfer( |
| 543 | sender=sender_index, |
| 544 | recipient=recipient_index, |
| 545 | amount=amount, |
| 546 | fee=0, |
| 547 | slot=pre_state.slot + 1, |
| 548 | pubkey=transfer_pubkey, |
| 549 | signature=b'\x00'*96, |
| 550 | ) |
| 551 | transfer.signature = bls.sign( |
| 552 | message_hash=signed_root(transfer), |
| 553 | privkey=transfer_privkey, |
| 554 | domain=get_domain( |
| 555 | fork=pre_state.fork, |
| 556 | epoch=get_current_epoch(pre_state), |
| 557 | domain_type=spec.DOMAIN_TRANSFER, |
| 558 | ) |
| 559 | ) |
| 560 | |
| 561 | # ensure withdrawal_credentials reproducable |
| 562 | pre_state.validator_registry[sender_index].withdrawal_credentials = ( |
| 563 | spec.BLS_WITHDRAWAL_PREFIX_BYTE + hash(transfer_pubkey)[1:] |
| 564 | ) |
| 565 | # un-activate so validator can transfer |
| 566 | pre_state.validator_registry[sender_index].activation_epoch = spec.FAR_FUTURE_EPOCH |
| 567 | |
| 568 | post_state = deepcopy(pre_state) |
| 569 | # |
| 570 | # Add to state via block transition |
| 571 | # |
| 572 | block = construct_empty_block_for_next_slot(post_state) |
| 573 | block.body.transfers.append(transfer) |
| 574 | state_transition(post_state, block) |
| 575 | |
| 576 | sender_balance = post_state.validator_balances[sender_index] |
| 577 | recipient_balance = post_state.validator_balances[recipient_index] |
| 578 | assert sender_balance == 0 |
| 579 | assert recipient_balance == pre_transfer_recipient_balance + amount |
| 580 | |
| 581 | return pre_state, [block], post_state |
| 582 | |
| 583 | |
| 584 | # @timeit |
nothing calls this directly
no test coverage detected