Search in sources :

Example 1 with ExecutionPayloadHeader

use of tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader 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 2 with ExecutionPayloadHeader

use of tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader in project teku by ConsenSys.

the class Web3JExecutionEngineClientTest method shouldSerializeDeserializeExecutionPayloadHeaderV1.

@TestTemplate
void shouldSerializeDeserializeExecutionPayloadHeaderV1() throws IOException {
    ExecutionPayloadHeader internalExecutionPayloadHeader = dataStructureUtil.randomExecutionPayloadHeader();
    ExecutionPayloadHeaderV1 executionPayloadHeaderV1Orig = ExecutionPayloadHeaderV1.fromInternalExecutionPayloadHeader(internalExecutionPayloadHeader);
    String executionPayloadHeaderV1OrigSerialized = objectMapper.writeValueAsString(executionPayloadHeaderV1Orig);
    ExecutionPayloadHeaderV1 executionPayloadHeaderV1New = objectMapper.readValue(executionPayloadHeaderV1OrigSerialized, ExecutionPayloadHeaderV1.class);
    assertThat(executionPayloadHeaderV1Orig).isEqualTo(executionPayloadHeaderV1New);
    assertThat(executionPayloadHeaderV1Orig.asInternalExecutionPayloadHeader(internalExecutionPayloadHeader.getSchema())).isEqualTo(internalExecutionPayloadHeader);
}
Also used : ExecutionPayloadHeaderV1(tech.pegasys.teku.ethereum.executionlayer.client.schema.ExecutionPayloadHeaderV1) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 3 with ExecutionPayloadHeader

use of tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader in project teku by ConsenSys.

the class GenesisGeneratorTest method shouldGenerateStateWithExecutionPayload.

@Test
public void shouldGenerateStateWithExecutionPayload() {
    final Spec spec = TestSpecFactory.createMinimalBellatrix();
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    final GenesisGenerator genesisGenerator = new GenesisGenerator(spec.getGenesisSpec(), spec.fork(UInt64.ZERO));
    genesisGenerator.updateCandidateState(dataStructureUtil.randomBytes32(), UInt64.valueOf(982928293223232L), initialDeposits.subList(0, 8));
    final ExecutionPayloadHeader payloadHeader = dataStructureUtil.randomExecutionPayloadHeader();
    genesisGenerator.updateExecutionPayloadHeader(payloadHeader);
    final BeaconState actualState = genesisGenerator.getGenesisState();
    assertThat(actualState).isInstanceOf(BeaconStateBellatrix.class);
    assertThat(BeaconStateBellatrix.required(actualState).getLatestExecutionPayloadHeader()).isEqualTo(payloadHeader);
}
Also used : ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) Spec(tech.pegasys.teku.spec.Spec) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionPayloadHeader (tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader)3 Spec (tech.pegasys.teku.spec.Spec)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 TestTemplate (org.junit.jupiter.api.TestTemplate)1 ExecutionPayloadHeaderV1 (tech.pegasys.teku.ethereum.executionlayer.client.schema.ExecutionPayloadHeaderV1)1 TestDefinition (tech.pegasys.teku.ethtests.finder.TestDefinition)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 TestDataUtils.loadSsz (tech.pegasys.teku.reference.TestDataUtils.loadSsz)1 TestDataUtils.loadStateFromSsz (tech.pegasys.teku.reference.TestDataUtils.loadStateFromSsz)1 TestDataUtils.loadYaml (tech.pegasys.teku.reference.TestDataUtils.loadYaml)1 TestExecutor (tech.pegasys.teku.reference.TestExecutor)1 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)1