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);
}
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();
}
}
Aggregations