Search in sources :

Example 1 with ProposerSlashingFuzzInput

use of tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput in project teku by ConsenSys.

the class FuzzUtilTest method fuzzProposerSlashing_minimal.

@Test
public void fuzzProposerSlashing_minimal() {
    final FuzzUtil fuzzUtil = new FuzzUtil(false, true);
    final Path testCaseDir = Path.of("minimal/operations/proposer_slashing/pyspec_tests/success");
    final ProposerSlashing data = loadSsz(testCaseDir.resolve("proposer_slashing.ssz"), ProposerSlashing.SSZ_SCHEMA);
    final BeaconState preState = loadSsz(testCaseDir.resolve("pre.ssz"), genesisBeaconStateSchema);
    final BeaconState postState = loadSsz(testCaseDir.resolve("post.ssz"), genesisBeaconStateSchema);
    ProposerSlashingFuzzInput input = new ProposerSlashingFuzzInput(spec, preState, data);
    byte[] rawInput = input.sszSerialize().toArrayUnsafe();
    Optional<Bytes> result = fuzzUtil.fuzzProposerSlashing(rawInput).map(Bytes::wrap);
    Bytes expected = postState.sszSerialize();
    assertThat(result).isNotEmpty();
    assertThat(result.get()).isEqualTo(expected);
}
Also used : Path(java.nio.file.Path) Bytes(org.apache.tuweni.bytes.Bytes) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) ProposerSlashingFuzzInput(tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with ProposerSlashingFuzzInput

use of tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput in project teku by ConsenSys.

the class FuzzUtil method fuzzProposerSlashing.

public Optional<byte[]> fuzzProposerSlashing(final byte[] input) {
    ProposerSlashingFuzzInput structuredInput = deserialize(input, ProposerSlashingFuzzInput.createType(spec.getGenesisSpec()));
    SszList<ProposerSlashing> proposerSlashings = beaconBlockBodySchema.getProposerSlashingsSchema().of(structuredInput.getProposer_slashing());
    // process and return post state
    try {
        BeaconState postState = structuredInput.getState().updated(state -> spec.getBlockProcessor(state.getSlot()).processProposerSlashings(state, proposerSlashings, signatureVerifier));
        Bytes output = postState.sszSerialize();
        return Optional.of(output.toArrayUnsafe());
    } catch (BlockProcessingException e) {
        // "expected error"
        return Optional.empty();
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlockProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) ProposerSlashingFuzzInput(tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

Bytes (org.apache.tuweni.bytes.Bytes)2 ProposerSlashingFuzzInput (tech.pegasys.teku.fuzz.input.ProposerSlashingFuzzInput)2 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 BlockProcessingException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException)1