def test_validate_eligible_exit_epoch(genesis_state, keymap, current_epoch, voluntary_exit_epoch, slots_per_epoch, config, success): state = genesis_state.copy(slot=get_epoch_start_slot( current_epoch, slots_per_epoch), ) validator_index = 0 voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, exit_epoch=voluntary_exit_epoch, ) if success: _validate_eligible_exit_epoch( voluntary_exit.epoch, state.current_epoch(slots_per_epoch), ) else: with pytest.raises(ValidationError): _validate_eligible_exit_epoch( voluntary_exit.epoch, state.current_epoch(slots_per_epoch), )
def test_validate_eligible_exit_epoch( genesis_state, keymap, current_epoch, voluntary_exit_epoch, slots_per_epoch, config, success, ): state = genesis_state.set( "slot", compute_start_slot_at_epoch(current_epoch, slots_per_epoch)) validator_index = 0 signed_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, exit_epoch=voluntary_exit_epoch) voluntary_exit = signed_voluntary_exit.message if success: _validate_eligible_exit_epoch(voluntary_exit.epoch, state.current_epoch(slots_per_epoch)) else: with pytest.raises(ValidationError): _validate_eligible_exit_epoch(voluntary_exit.epoch, state.current_epoch(slots_per_epoch))
def test_validate_voluntary_exit(genesis_state, keymap, slots_per_epoch, persistent_committee_period, config): state = genesis_state.copy(slot=compute_start_slot_at_epoch( config.GENESIS_EPOCH + persistent_committee_period, slots_per_epoch)) validator_index = 0 valid_voluntary_exit = create_mock_voluntary_exit(state, config, keymap, validator_index) validate_voluntary_exit(state, valid_voluntary_exit, slots_per_epoch, persistent_committee_period)
def test_process_voluntary_exits(genesis_state, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, success): state = genesis_state.copy(slot=get_epoch_start_slot( config.GENESIS_EPOCH + config.PERSISTENT_COMMITTEE_PERIOD, config.SLOTS_PER_EPOCH, ), ) validator_index = 0 validator = state.validators[validator_index].copy( activation_epoch=config.GENESIS_EPOCH, ) state = state.update_validator(validator_index, validator) valid_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) if success: block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(valid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) new_state = process_voluntary_exits( state, block, config, ) updated_validator = new_state.validators[validator_index] assert updated_validator.exit_epoch != FAR_FUTURE_EPOCH assert updated_validator.exit_epoch > state.current_epoch( config.SLOTS_PER_EPOCH) assert updated_validator.withdrawable_epoch == ( updated_validator.exit_epoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY) else: invalid_voluntary_exit = valid_voluntary_exit.copy( signature=b'\x12' * 96, # Put wrong signature ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(invalid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) with pytest.raises(ValidationError): process_voluntary_exits( state, block, config, )
def test_validate_voluntary_exit(genesis_state, keymap, slots_per_epoch, shard_committee_period, config): state = genesis_state.set( "slot", compute_start_slot_at_epoch(GENESIS_EPOCH + shard_committee_period, slots_per_epoch), ) validator_index = 0 valid_voluntary_exit = create_mock_voluntary_exit(state, config, keymap, validator_index) validate_voluntary_exit(state, valid_voluntary_exit, slots_per_epoch, shard_committee_period)
def test_validate_voluntary_exit(genesis_state, keymap, slots_per_epoch, activation_exit_delay, config): state = genesis_state validator_index = 0 valid_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) validate_voluntary_exit(state, valid_voluntary_exit, slots_per_epoch, activation_exit_delay)
def test_process_voluntary_exits(genesis_state, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, success): state = genesis_state.copy(slot=get_epoch_start_slot( config.GENESIS_EPOCH + config.PERSISTENT_COMMITTEE_PERIOD, config.SLOTS_PER_EPOCH, ), ) validator_index = 0 validator = state.validator_registry[validator_index].copy( activation_epoch=config.GENESIS_EPOCH, ) state = state.update_validator_registry(validator_index, validator) valid_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) if success: block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(valid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) new_state = process_voluntary_exits( state, block, config, ) # Check if initiated exit assert (new_state.validator_registry[validator_index].initiated_exit) else: invalid_voluntary_exit = valid_voluntary_exit.copy( signature=b'\x12' * 96, # Put wrong signature ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(invalid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) with pytest.raises(ValidationError): process_voluntary_exits( state, block, config, )
def test_process_voluntary_exits( genesis_state, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, success, ): state = genesis_state.set( "slot", compute_start_slot_at_epoch( config.GENESIS_EPOCH + config.PERSISTENT_COMMITTEE_PERIOD, config.SLOTS_PER_EPOCH, ), ) validator_index = 0 validator = state.validators[validator_index].set("activation_epoch", config.GENESIS_EPOCH) state = state.transform(["validators", validator_index], validator) valid_voluntary_exit = create_mock_voluntary_exit(state, config, keymap, validator_index) if success: block_body = BeaconBlockBody.create( **sample_beacon_block_body_params).set("voluntary_exits", (valid_voluntary_exit, )) block = SerenityBeaconBlock.create(**sample_beacon_block_params).mset( "slot", state.slot, "body", block_body) new_state = process_voluntary_exits(state, block, config) updated_validator = new_state.validators[validator_index] assert updated_validator.exit_epoch != FAR_FUTURE_EPOCH assert updated_validator.exit_epoch > state.current_epoch( config.SLOTS_PER_EPOCH) assert updated_validator.withdrawable_epoch == ( updated_validator.exit_epoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY) else: invalid_voluntary_exit = valid_voluntary_exit.set( "signature", b"\x12" * 96 # Put wrong signature ) block_body = BeaconBlockBody.create( **sample_beacon_block_body_params).set("voluntary_exits", (invalid_voluntary_exit, )) block = SerenityBeaconBlock.create(**sample_beacon_block_params).mset( "slot", state.slot, "body", block_body) with pytest.raises(ValidationError): process_voluntary_exits(state, block, config)
def test_process_voluntary_exits(genesis_state, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, min_attestation_inclusion_delay, success): state = genesis_state validator_index = 0 valid_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) if success: block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(valid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) new_state = process_voluntary_exits( state, block, config, ) # Check if initiated exit assert (new_state.validator_registry[validator_index].initiated_exit) else: invalid_voluntary_exit = valid_voluntary_exit.copy( signature=b'\x12' * 96, # Put wrong signature ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( voluntary_exits=(invalid_voluntary_exit, ), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=state.slot, body=block_body, ) with pytest.raises(ValidationError): process_voluntary_exits( state, block, config, )
def test_validate_voluntary_exit_signature(genesis_state, keymap, config, success): slots_per_epoch = config.SLOTS_PER_EPOCH state = genesis_state validator_index = 0 voluntary_exit = create_mock_voluntary_exit(state, config, keymap, validator_index) validator = state.validators[validator_index] if success: _validate_voluntary_exit_signature(state, voluntary_exit, validator, slots_per_epoch) else: # Use wrong signature voluntary_exit = voluntary_exit.set("signature", b"\x12" * 96) # wrong signature with pytest.raises(ValidationError): _validate_voluntary_exit_signature(state, voluntary_exit, validator, slots_per_epoch)
def test_validate_voluntary_exit(genesis_state, keymap, slots_per_epoch, persistent_committee_period, config): state = genesis_state.copy(slot=get_epoch_start_slot( config.GENESIS_EPOCH + persistent_committee_period, slots_per_epoch), ) validator_index = 0 validator = state.validator_registry[validator_index].copy( activation_epoch=config.GENESIS_EPOCH, ) state = state.update_validator_registry(validator_index, validator) valid_voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) validate_voluntary_exit( state, valid_voluntary_exit, slots_per_epoch, persistent_committee_period, )
def test_validate_voluntary_exit_signature(genesis_state, keymap, config, success): state = genesis_state validator_index = 0 voluntary_exit = create_mock_voluntary_exit( state, config, keymap, validator_index, ) validator = state.validator_registry[validator_index] if success: validate_voluntary_exit_signature(state, voluntary_exit, validator) else: # Use wrong signature voluntary_exit = voluntary_exit.copy( signature=b'\x12' * 96, # wrong signature ) with pytest.raises(ValidationError): validate_voluntary_exit_signature(state, voluntary_exit, validator)