def test_process_max_attestations(genesis_state, genesis_block, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap): attestation_slot = config.GENESIS_SLOT current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.copy(slot=current_slot, ) attestations = create_mock_signed_attestations_at_slot( state=state, config=config, attestation_slot=attestation_slot, beacon_block_root=genesis_block.root, keymap=keymap, voted_attesters_ratio=1.0, ) attestations_count = len(attestations) assert attestations_count > 0 block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( attestations=attestations * (attestations_count // config.MAX_ATTESTATIONS + 1), ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=current_slot, body=block_body, ) with pytest.raises(ValidationError): process_attestations( state, block, config, )
def test_process_attestations(genesis_state, genesis_block, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, fixture_sm_class, chaindb, empty_attestation_pool, success): attestation_slot = 0 current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.copy(slot=current_slot, ) attestations = create_mock_signed_attestations_at_slot( state=state, config=config, state_machine=fixture_sm_class( chaindb, empty_attestation_pool, genesis_block.slot, ), attestation_slot=attestation_slot, beacon_block_root=genesis_block.signing_root, keymap=keymap, voted_attesters_ratio=1.0, ) assert len(attestations) > 0 if not success: # create invalid attestation by shard # i.e. wrong parent invalid_attestation_data = attestations[-1].data.copy( crosslink=attestations[-1].data.crosslink.copy( parent_root=Crosslink(shard=333, ).root, )) invalid_attestation = attestations[-1].copy( data=invalid_attestation_data, ) attestations = attestations[:-1] + (invalid_attestation, ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( attestations=attestations, ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=current_slot, body=block_body, ) if success: new_state = process_attestations( state, block, config, ) assert len(new_state.current_epoch_attestations) == len(attestations) else: with pytest.raises(ValidationError): process_attestations( state, block, config, )
def test_process_attestations(genesis_state, genesis_block, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, fixture_sm_class, base_db, success): attestation_slot = 0 current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.copy(slot=current_slot, ) attestations = create_mock_signed_attestations_at_slot( state=state, config=config, state_machine=fixture_sm_class( BeaconChainDB(base_db), genesis_block, ), attestation_slot=attestation_slot, beacon_block_root=genesis_block.signed_root, keymap=keymap, voted_attesters_ratio=1.0, ) assert len(attestations) > 0 if not success: # create invalid attestation in the future invalid_attestation_data = attestations[-1].data.copy(slot=state.slot + 10, ) invalid_attestation = attestations[-1].copy( data=invalid_attestation_data, ) attestations = attestations[:-1] + (invalid_attestation, ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( attestations=attestations, ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=current_slot, body=block_body, ) if success: new_state = process_attestations( state, block, config, ) assert len(new_state.current_epoch_attestations) == len(attestations) else: with pytest.raises(ValidationError): process_attestations( state, block, config, )
def test_process_attestations( genesis_state, genesis_block, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, fixture_sm_class, chaindb, genesis_fork_choice_context, success, ): attestation_slot = 0 current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.set("slot", current_slot) attestations = create_mock_signed_attestations_at_slot( state=state, config=config, state_machine=fixture_sm_class(chaindb, genesis_fork_choice_context), attestation_slot=attestation_slot, beacon_block_root=genesis_block.message.hash_tree_root, keymap=keymap, voted_attesters_ratio=1.0, ) assert len(attestations) > 0 if not success: # create invalid attestation # i.e. wrong slot invalid_attestation_data = attestations[-1].data.set( "slot", state.slot + 1) invalid_attestation = attestations[-1].set("data", invalid_attestation_data) attestations = attestations[:-1] + (invalid_attestation, ) block_body = BeaconBlockBody.create(**sample_beacon_block_body_params).set( "attestations", attestations) block = SerenityBeaconBlock.create(**sample_beacon_block_params).mset( "slot", current_slot, "body", block_body) if success: new_state = process_attestations(state, block, config) assert len(new_state.current_epoch_attestations) == len(attestations) else: with pytest.raises(ValidationError): process_attestations(state, block, config)
def test_process_attestations(genesis_state, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, success): attestation_slot = 0 current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.copy(slot=current_slot, ) attestations = create_mock_signed_attestations_at_slot( state, config, attestation_slot, keymap, 1.0, ) assert len(attestations) > 0 if not success: # create invalid attestation in the future invalid_attestation_data = attestations[-1].data.copy(slot=state.slot + 10, ) invalid_attestation = attestations[-1].copy( data=invalid_attestation_data, ) attestations = attestations[:-1] + (invalid_attestation, ) block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( attestations=attestations, ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=current_slot, body=block_body, ) if success: new_state = process_attestations( state, block, config, ) assert len(new_state.latest_attestations) == len(attestations) else: with pytest.raises(ValidationError): process_attestations( state, block, config, )
def test_process_max_attestations( genesis_state, genesis_block, sample_beacon_block_params, sample_beacon_block_body_params, config, keymap, fixture_sm_class, chaindb, genesis_fork_choice_context, ): attestation_slot = config.GENESIS_SLOT current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY state = genesis_state.copy(slot=current_slot) attestations = create_mock_signed_attestations_at_slot( state=state, config=config, state_machine=fixture_sm_class(chaindb, genesis_fork_choice_context), attestation_slot=attestation_slot, beacon_block_root=genesis_block.signing_root, keymap=keymap, voted_attesters_ratio=1.0, ) attestations_count = len(attestations) assert attestations_count > 0 block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy( attestations=attestations * (config.MAX_ATTESTATIONS // attestations_count + 1) ) block = SerenityBeaconBlock(**sample_beacon_block_params).copy( slot=current_slot, body=block_body ) with pytest.raises(ValidationError): process_attestations(state, block, config)
def FuzzerRunOne(input_data: bytes) -> typing.Optional[bytes]: test_case = ssz.decode(input_data, AttestationTestCase) # NOTE Trinity doesn't implement a standalone process_attestation # So we make a dummy block to pass to process_attestations dummy_block = Dummy() dummy_block.body = Dummy() dummy_block.body.attestations = [test_case.attestation] # TODO(gnattishness) any other relevant exceptions to catch? try: post = process_attestations( state=test_case.pre, block=dummy_block, config=SERENITY_CONFIG ) except ValidationError: return None return ssz.encode(post)