Search in sources :

Example 1 with BeaconStateSchema

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema in project teku by ConsenSys.

the class ForkChoiceTestExecutor method parseForkChoiceFile.

@SuppressWarnings("unchecked")
private static Optional<? extends Arguments> parseForkChoiceFile(Path path) {
    final File file = path.toFile();
    final SchemaDefinitions schemaDefinitions = SPEC.getGenesisSchemaDefinitions();
    final BeaconStateSchema<?, ?> beaconStateSchema = schemaDefinitions.getBeaconStateSchema();
    try {
        @SuppressWarnings("rawtypes") Map content = mapper.readValue(file, Map.class);
        if (content.containsKey("steps")) {
            BeaconState genesisState = resolvePart(BeaconState.class, beaconStateSchema, file, content.get("genesis"));
            @SuppressWarnings("unchecked") List<Object> steps = ((List<Map<String, Object>>) content.get("steps")).stream().map(step -> extractTestStep(file, step)).collect(Collectors.toList());
            return Optional.of(Arguments.of(genesisState, steps, file.getName(), true));
        } else {
            return Optional.empty();
        }
    } catch (IOException e) {
        return Optional.empty();
    }
}
Also used : AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) Bytes(org.apache.tuweni.bytes.Bytes) ArrayList(java.util.ArrayList) Map(java.util.Map) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) SszData(tech.pegasys.teku.infrastructure.ssz.SszData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Path(java.nio.file.Path) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) MethodSource(org.junit.jupiter.params.provider.MethodSource) SszSchema(tech.pegasys.teku.infrastructure.ssz.schema.SszSchema) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) BeaconStateSchema(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema) Paths(java.nio.file.Paths) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) Collections(java.util.Collections) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Arguments (org.junit.jupiter.params.provider.Arguments)1