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_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 FuzzerRunOne(input_data: bytes) -> typing.Optional[bytes]: test_case = ssz.decode(input_data, sedes=VoluntaryExitTestCase) # NOTE Trinity doesn't implement a standalone process_attestation # So we make a dummy block to pass to process_voluntary_exits dummy_block = Dummy() dummy_block.body = Dummy() dummy_block.body.voluntary_exits = [test_case.voluntary_exit] # TODO(gnattishness) remove IndexError handling once we use a trinity version # where ethereum/trinity#1498 is accepted try: post = process_voluntary_exits( state=test_case.pre, block=dummy_block, config=SERENITY_CONFIG, ) except (ValidationError, IndexError): return None return ssz.encode(post)