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