def test_defaults(sample_voluntary_exit_params, sample_signature): exit = VoluntaryExit.create(**sample_voluntary_exit_params) signed_exit = SignedVoluntaryExit.create(message=exit, signature=sample_signature) assert exit.epoch == sample_voluntary_exit_params["epoch"] assert ssz.encode(exit) assert ssz.encode(signed_exit)
def create_mock_voluntary_exit(state: BeaconState, config: Eth2Config, keymap: Dict[BLSPubkey, int], validator_index: ValidatorIndex, exit_epoch: Epoch = None) -> VoluntaryExit: current_epoch = state.current_epoch(config.SLOTS_PER_EPOCH) target_epoch = current_epoch if exit_epoch is None else exit_epoch voluntary_exit = VoluntaryExit( epoch=target_epoch, validator_index=validator_index, ) return voluntary_exit.copy(signature=sign_transaction( message_hash=voluntary_exit.signing_root, privkey=keymap[state.validators[validator_index].pubkey], state=state, slot=get_epoch_start_slot(target_epoch, config.SLOTS_PER_EPOCH), signature_domain=SignatureDomain.DOMAIN_VOLUNTARY_EXIT, slots_per_epoch=config.SLOTS_PER_EPOCH, ))
def create_mock_voluntary_exit( state: BeaconState, config: Eth2Config, keymap: Dict[BLSPubkey, int], validator_index: ValidatorIndex, exit_epoch: Epoch = None, ) -> SignedVoluntaryExit: current_epoch = state.current_epoch(config.SLOTS_PER_EPOCH) target_epoch = current_epoch if exit_epoch is None else exit_epoch voluntary_exit = VoluntaryExit.create(epoch=target_epoch, validator_index=validator_index) return SignedVoluntaryExit.create( message=voluntary_exit, signature=sign_transaction( object=voluntary_exit, privkey=keymap[state.validators[validator_index].pubkey], state=state, slot=compute_start_slot_at_epoch(target_epoch, config.SLOTS_PER_EPOCH), signature_domain=SignatureDomain.DOMAIN_VOLUNTARY_EXIT, slots_per_epoch=config.SLOTS_PER_EPOCH, ), )
def test_defaults(sample_voluntary_exit_params): exit = VoluntaryExit(**sample_voluntary_exit_params) assert exit.signature[0] == sample_voluntary_exit_params["signature"][0] assert ssz.encode(exit)