Search in sources :

Example 1 with Bytes8

use of tech.pegasys.teku.infrastructure.bytes.Bytes8 in project teku by ConsenSys.

the class Web3JExecutionEngineClientTest method shouldDeserializeBytes8.

@TestTemplate
void shouldDeserializeBytes8() throws IOException {
    Bytes8 originalBytes8 = dataStructureUtil.randomBytes8();
    JsonParser parser = prepareDeserializationContext("\"" + originalBytes8.toHexString() + "\"");
    Bytes8Deserializer deserializer = new Bytes8Deserializer();
    Bytes8 result = deserializer.deserialize(parser, objectMapper.getDeserializationContext());
    assertThat(originalBytes8).isEqualTo(result);
}
Also used : Bytes8Deserializer(tech.pegasys.teku.ethereum.executionlayer.client.serialization.Bytes8Deserializer) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) JsonParser(com.fasterxml.jackson.core.JsonParser) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 2 with Bytes8

use of tech.pegasys.teku.infrastructure.bytes.Bytes8 in project teku by ConsenSys.

the class ForkChoiceNotifierTest method getPayloadId_shouldObtainAPayloadIdWhenProposingTheMergeBlock.

@Test
void getPayloadId_shouldObtainAPayloadIdWhenProposingTheMergeBlock() {
    reInitializePreMerge();
    Bytes32 terminalBlockHash = dataStructureUtil.randomBytes32();
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    final BeaconState headState = getHeadState();
    final UInt64 blockSlot = headState.getSlot().plus(1);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    // we expect head block root and slot to be ZERO since in the test we do not send an
    // onForkChoiceUpdated before calling onTerminalBlock, so it will initialize ZEROED
    final ForkChoiceState forkChoiceState = new ForkChoiceState(Bytes32.ZERO, UInt64.ZERO, terminalBlockHash, terminalBlockHash, Bytes32.ZERO, false);
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    notifier.onTerminalBlockReached(terminalBlockHash);
    validateGetPayloadIdOnTheFlyRetrieval(blockSlot, blockRoot, forkChoiceState, payloadId, payloadAttributes, false);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with Bytes8

use of tech.pegasys.teku.infrastructure.bytes.Bytes8 in project teku by ConsenSys.

the class ForkChoiceNotifierTest method getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot.

@Test
void getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot() {
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    final BeaconState headState = getHeadState();
    final UInt64 blockSlot = headState.getSlot().plus(1);
    final Bytes32 wrongBlockRoot = dataStructureUtil.randomBytes32();
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
    when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
    assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
    responseFuture.complete(createForkChoiceUpdatedResult(ExecutionPayloadStatus.VALID, Optional.of(payloadId)));
    assertThatSafeFuture(notifier.getPayloadId(wrongBlockRoot, blockSlot)).isCompletedExceptionally();
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 4 with Bytes8

use of tech.pegasys.teku.infrastructure.bytes.Bytes8 in project teku by ConsenSys.

the class ForkChoiceNotifierTest method getPayloadId_shouldObtainAPayloadIdOnPostMergeBlockFinalizedEvenIfProposerNotPrepared.

@Test
void getPayloadId_shouldObtainAPayloadIdOnPostMergeBlockFinalizedEvenIfProposerNotPrepared() {
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    // current slot: 1
    // send post-merge onForkChoiceUpdated (with finalized block state)
    ForkChoiceState finalizedForkChoiceState = getCurrentForkChoiceState();
    assertThat(finalizedForkChoiceState.getFinalizedExecutionBlockHash()).isNotEqualTo(Bytes32.ZERO);
    assertThat(notifier.onForkChoiceUpdated(finalizedForkChoiceState)).isCompleted();
    verify(executionEngineChannel).forkChoiceUpdated(finalizedForkChoiceState, Optional.empty());
    final BeaconState headState = getHeadState();
    // proposing slot 3
    final UInt64 blockSlot = headState.getSlot().plus(2);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final PayloadAttributes payloadAttributes = withProposerForSlotButDoNotPrepare(headState, blockSlot, defaultFeeRecipient);
    validateGetPayloadIdOnTheFlyRetrieval(blockSlot, blockRoot, finalizedForkChoiceState, payloadId, payloadAttributes, false);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 5 with Bytes8

use of tech.pegasys.teku.infrastructure.bytes.Bytes8 in project teku by ConsenSys.

the class ForkChoiceNotifierTest method getPayloadId_shouldFailIfDefaultFeeRecipientIsNotConfigured.

@Test
void getPayloadId_shouldFailIfDefaultFeeRecipientIsNotConfigured() {
    setUp(true);
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    // current slot: 1
    // send post-merge onForkChoiceUpdated (with finalized block state)
    ForkChoiceState finalizedForkChoiceState = getCurrentForkChoiceState();
    assertThat(finalizedForkChoiceState.getFinalizedExecutionBlockHash()).isNotEqualTo(Bytes32.ZERO);
    assertThat(notifier.onForkChoiceUpdated(finalizedForkChoiceState)).isCompleted();
    verify(executionEngineChannel).forkChoiceUpdated(finalizedForkChoiceState, Optional.empty());
    final BeaconState headState = getHeadState();
    // proposing slot 3
    final UInt64 blockSlot = headState.getSlot().plus(2);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final PayloadAttributes payloadAttributes = withProposerForSlotButDoNotPrepare(headState, blockSlot, Optional.empty());
    validateGetPayloadIdOnTheFlyRetrieval(blockSlot, blockRoot, finalizedForkChoiceState, payloadId, payloadAttributes, true);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

Bytes8 (tech.pegasys.teku.infrastructure.bytes.Bytes8)12 Bytes32 (org.apache.tuweni.bytes.Bytes32)9 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)9 Test (org.junit.jupiter.api.Test)8 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)8 ForkChoiceState (tech.pegasys.teku.spec.executionengine.ForkChoiceState)8 PayloadAttributes (tech.pegasys.teku.spec.executionengine.PayloadAttributes)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 ForkChoiceUpdatedResult (tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult)3 TestTemplate (org.junit.jupiter.api.TestTemplate)2 SafeFutureAssert.assertThatSafeFuture (tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 ForkChoiceUpdatedResult (tech.pegasys.teku.ethereum.executionlayer.client.schema.ForkChoiceUpdatedResult)1 Bytes8Deserializer (tech.pegasys.teku.ethereum.executionlayer.client.serialization.Bytes8Deserializer)1 AsyncRunnerFactory (tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory)1 AsyncRunnerEventThread (tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread)1