Search in sources :

Example 1 with TestDefinition

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);
}
Also used : IntStream(java.util.stream.IntStream) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) TestDataUtils.loadYaml(tech.pegasys.teku.reference.TestDataUtils.loadYaml) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OptimisticExecutionPayloadExecutor(tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor) TestExecutor(tech.pegasys.teku.reference.TestExecutor) TestDataUtils.loadStateFromSsz(tech.pegasys.teku.reference.TestDataUtils.loadStateFromSsz) Collectors(java.util.stream.Collectors) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) IGNORED(tech.pegasys.teku.reference.BlsSetting.IGNORED) TestDataUtils.loadSsz(tech.pegasys.teku.reference.TestDataUtils.loadSsz) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BlsSetting(tech.pegasys.teku.reference.BlsSetting) Optional(java.util.Optional) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 2 with TestDefinition

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);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ImmutableMap(com.google.common.collect.ImmutableMap) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) TestAbortedException(org.opentest4j.TestAbortedException) OptimisticExecutionPayloadExecutor(tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor) TestExecutor(tech.pegasys.teku.reference.TestExecutor) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) TestDataUtils(tech.pegasys.teku.reference.TestDataUtils) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) SszDataAssert.assertThatSszData(tech.pegasys.teku.infrastructure.ssz.SszDataAssert.assertThatSszData) SpecFactory(tech.pegasys.teku.spec.SpecFactory) SpecConfigLoader(tech.pegasys.teku.spec.config.SpecConfigLoader) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Example 3 with TestDefinition

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);
}
Also used : IntStream(java.util.stream.IntStream) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) TestDataUtils.loadYaml(tech.pegasys.teku.reference.TestDataUtils.loadYaml) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestExecutor(tech.pegasys.teku.reference.TestExecutor) TestDataUtils.loadStateFromSsz(tech.pegasys.teku.reference.TestDataUtils.loadStateFromSsz) Collectors(java.util.stream.Collectors) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) TestDataUtils.loadSsz(tech.pegasys.teku.reference.TestDataUtils.loadSsz) List(java.util.List) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SchemaDefinitionsBellatrix(tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) Spec(tech.pegasys.teku.spec.Spec) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with TestDefinition

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));
}
Also used : ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Bytes(org.apache.tuweni.bytes.Bytes) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SSZ(org.apache.tuweni.ssz.SSZ) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Map(java.util.Map) InMemoryStorageSystemBuilder(tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) UInt256(org.apache.tuweni.units.bigints.UInt256) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) ImmutableMap(com.google.common.collect.ImmutableMap) TestAbortedException(org.opentest4j.TestAbortedException) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) TestExecutor(tech.pegasys.teku.reference.TestExecutor) TestDataUtils(tech.pegasys.teku.reference.TestDataUtils) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) ByteOrder(java.nio.ByteOrder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Condition(org.assertj.core.api.Condition) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) 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) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)

Aggregations

TestDefinition (tech.pegasys.teku.ethtests.finder.TestDefinition)4 TestExecutor (tech.pegasys.teku.reference.TestExecutor)4 Spec (tech.pegasys.teku.spec.Spec)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)4 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)3 List (java.util.List)3 Optional (java.util.Optional)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 TestAbortedException (org.opentest4j.TestAbortedException)2 BLSSignatureVerifier (tech.pegasys.teku.bls.BLSSignatureVerifier)2 TestDataUtils (tech.pegasys.teku.reference.TestDataUtils)2 TestDataUtils.loadSsz (tech.pegasys.teku.reference.TestDataUtils.loadSsz)2 TestDataUtils.loadStateFromSsz (tech.pegasys.teku.reference.TestDataUtils.loadStateFromSsz)2 TestDataUtils.loadYaml (tech.pegasys.teku.reference.TestDataUtils.loadYaml)2