Search in sources :

Example 1 with VoluntaryExitFuzzInput

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

the class FuzzUtil method fuzzVoluntaryExit.

public Optional<byte[]> fuzzVoluntaryExit(final byte[] input) {
    VoluntaryExitFuzzInput structuredInput = deserialize(input, VoluntaryExitFuzzInput.createSchema(spec.getGenesisSpec()));
    SszList<SignedVoluntaryExit> voluntaryExits = beaconBlockBodySchema.getVoluntaryExitsSchema().of(structuredInput.getExit());
    try {
        BeaconState postState = structuredInput.getState().updated(state -> spec.getBlockProcessor(state.getSlot()).processVoluntaryExits(state, voluntaryExits, signatureVerifier));
        Bytes output = postState.sszSerialize();
        return Optional.of(output.toArrayUnsafe());
    } catch (BlockProcessingException e) {
        // "expected error"
        return Optional.empty();
    }
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Bytes(org.apache.tuweni.bytes.Bytes) BlockProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException) VoluntaryExitFuzzInput(tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 2 with VoluntaryExitFuzzInput

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

the class FuzzUtilTest method fuzzVoluntaryExit_minimal.

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

Aggregations

Bytes (org.apache.tuweni.bytes.Bytes)2 VoluntaryExitFuzzInput (tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput)2 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)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