use of tech.pegasys.teku.ethtests.finder.TestDefinition in project teku by ConsenSys.
the class SanityBlocksTestExecutor method runTest.
@Override
public void runTest(final TestDefinition testDefinition) throws Exception {
final SanityBlocksMetaData metaData = loadYaml(testDefinition, "meta.yaml", SanityBlocksMetaData.class);
final BeaconState preState = loadStateFromSsz(testDefinition, "pre.ssz_snappy");
final List<SignedBeaconBlock> blocks = IntStream.range(0, metaData.getBlocksCount()).mapToObj(index -> loadSsz(testDefinition, "blocks_" + index + ".ssz_snappy", testDefinition.getSpec()::deserializeSignedBeaconBlock)).collect(Collectors.toList());
final Optional<BeaconState> expectedState;
if (testDefinition.getTestDirectory().resolve(EXPECTED_STATE_FILENAME).toFile().exists()) {
expectedState = Optional.of(loadStateFromSsz(testDefinition, EXPECTED_STATE_FILENAME));
} else {
expectedState = Optional.empty();
}
runBlockProcessor(this::applyBlocks, testDefinition, metaData, preState, blocks, expectedState);
}
use of tech.pegasys.teku.ethtests.finder.TestDefinition in project teku by ConsenSys.
the class TransitionTestExecutor method processAltairUpgrade.
private void processAltairUpgrade(final TestDefinition testDefinition, final MetaData metadata) throws Exception {
final UInt64 forkEpoch = UInt64.valueOf(metadata.forkEpoch);
final SpecConfig config = SpecConfigLoader.loadConfig(testDefinition.getConfigName(), c -> c.altairBuilder(a -> a.altairForkEpoch(forkEpoch)));
final Spec spec = SpecFactory.create(config);
final BeaconState preState = TestDataUtils.loadSsz(testDefinition, "pre.ssz_snappy", spec::deserializeBeaconState);
final BeaconState postState = TestDataUtils.loadSsz(testDefinition, "post.ssz_snappy", spec::deserializeBeaconState);
BeaconState result = preState;
for (int i = 0; i < metadata.blocksCount; i++) {
final SignedBeaconBlock block = TestDataUtils.loadSsz(testDefinition, "blocks_" + i + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
try {
final BLSSignatureVerifier signatureVerifier = metadata.blsSetting == 2 ? BLSSignatureVerifier.NO_OP : BLSSignatureVerifier.SIMPLE;
result = spec.processBlock(result, block, signatureVerifier, OptimisticExecutionPayloadExecutor.NOOP);
} catch (final StateTransitionException e) {
Assertions.fail("Failed to process block " + i + " at slot " + block.getSlot() + ": " + e.getMessage(), e);
}
}
assertThatSszData(result).isEqualByGettersTo(postState);
}
use of tech.pegasys.teku.ethtests.finder.TestDefinition in project teku by ConsenSys.
the class GenesisInitializationTestExecutor method runTest.
@Override
public void runTest(final TestDefinition testDefinition) throws Exception {
final Spec spec = testDefinition.getSpec();
final BeaconState expectedGenesisState = loadStateFromSsz(testDefinition, "state.ssz_snappy");
final Eth1MetaData eth1MetaData = loadYaml(testDefinition, "eth1.yaml", Eth1MetaData.class);
final GenesisMetaData metaData = loadYaml(testDefinition, "meta.yaml", GenesisMetaData.class);
final List<Deposit> deposits = IntStream.range(0, metaData.getDepositsCount()).mapToObj(index -> loadSsz(testDefinition, "deposits_" + index + ".ssz_snappy", Deposit.SSZ_SCHEMA)).collect(Collectors.toList());
final Optional<ExecutionPayloadHeader> executionPayloadHeader;
if (metaData.hasExecutionPayloadHeader()) {
executionPayloadHeader = Optional.of(loadSsz(testDefinition, "execution_payload_header.ssz_snappy", SchemaDefinitionsBellatrix.required(spec.getGenesisSchemaDefinitions()).getExecutionPayloadHeaderSchema()));
} else {
executionPayloadHeader = Optional.empty();
}
final BeaconState result = spec.initializeBeaconStateFromEth1(eth1MetaData.getEth1BlockHash(), eth1MetaData.getEth1Timestamp(), deposits, executionPayloadHeader);
assertThat(result).isEqualTo(expectedGenesisState);
}
use of tech.pegasys.teku.ethtests.finder.TestDefinition in project teku by ConsenSys.
the class ForkChoiceTestExecutor method applyBlock.
private void applyBlock(final TestDefinition testDefinition, final Spec spec, final ForkChoice forkChoice, final Map<String, Object> step, final StubExecutionEngineChannel executionEngine) {
final String blockName = get(step, "block");
final boolean valid = !step.containsKey("valid") || (boolean) step.get("valid");
final SignedBeaconBlock block = TestDataUtils.loadSsz(testDefinition, blockName + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
LOG.info("Importing block {} at slot {} with parent {}", block.getRoot(), block.getSlot(), block.getParentRoot());
final SafeFuture<BlockImportResult> result = forkChoice.onBlock(block, executionEngine);
assertThat(result).isCompleted();
final BlockImportResult importResult = result.join();
assertThat(importResult).describedAs("Incorrect block import result for block %s", block).has(new Condition<>(r -> r.isSuccessful() == valid, "isSuccessful matching " + valid));
}
Aggregations