Search in sources :

Example 1 with EnginePayloadStatusResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult in project besu by hyperledger.

the class EngineNewPayloadTest method shouldCheckBlockValidityBeforeCheckingByHashForExisting.

@Test
public void shouldCheckBlockValidityBeforeCheckingByHashForExisting() {
    BlockHeader realHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
    BlockHeader paramHeader = spy(realHeader);
    when(paramHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337"));
    var resp = resp(mockPayload(paramHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getLatestValidHash()).isEmpty();
    assertThat(res.getStatusAsString()).isEqualTo(INVALID_BLOCK_HASH.name());
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 2 with EnginePayloadStatusResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult in project besu by hyperledger.

the class EngineNewPayloadTest method shouldReturnInvalidBlockHashOnBadHashParameter.

@Test
public void shouldReturnInvalidBlockHashOnBadHashParameter() {
    BlockHeader mockHeader = new BlockHeaderTestFixture().buildHeader();
    var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getLatestValidHash()).isEmpty();
    assertThat(res.getStatusAsString()).isEqualTo(INVALID_BLOCK_HASH.name());
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 3 with EnginePayloadStatusResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult in project besu by hyperledger.

the class EngineNewPayloadTest method shouldRespondWithSyncingDuringForwardSync.

@Test
public void shouldRespondWithSyncingDuringForwardSync() {
    BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
    when(blockchain.getBlockByHash(any())).thenReturn(Optional.empty());
    when(mergeContext.isSyncing()).thenReturn(Boolean.TRUE);
    var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getError()).isNull();
    assertThat(res.getStatusAsString()).isEqualTo(SYNCING.name());
    assertThat(res.getLatestValidHash()).isEmpty();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 4 with EnginePayloadStatusResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult in project besu by hyperledger.

the class EngineNewPayloadTest method shouldReturnValid.

@Test
public void shouldReturnValid() {
    BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
    when(blockchain.getBlockByHash(any())).thenReturn(Optional.empty());
    when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))).thenReturn(Optional.of(mockHash));
    when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(any(BlockHeader.class))).thenReturn(true);
    when(mergeCoordinator.getOrSyncHeaderByHash(any(Hash.class))).thenReturn(Optional.of(mockHeader));
    when(mergeCoordinator.executeBlock(any())).thenReturn(new Result(new BlockProcessingOutputs(null, List.of())));
    var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getLatestValidHash().get()).isEqualTo(mockHeader.getHash());
    assertThat(res.getStatusAsString()).isEqualTo(VALID.name());
    assertThat(res.getError()).isNull();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) Test(org.junit.Test)

Example 5 with EnginePayloadStatusResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult in project besu by hyperledger.

the class EngineNewPayloadTest method shouldRespondWithSyncingDuringBackwardsSync.

@Test
public void shouldRespondWithSyncingDuringBackwardsSync() {
    when(mergeCoordinator.getOrSyncHeaderByHash(any(Hash.class))).thenReturn(Optional.empty());
    BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
    var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getLatestValidHash()).isEmpty();
    assertThat(res.getStatusAsString()).isEqualTo(SYNCING.name());
    assertThat(res.getError()).isNull();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) Hash(org.hyperledger.besu.datatypes.Hash) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

EnginePayloadStatusResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult)12 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)12 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)12 Test (org.junit.Test)12 Hash (org.hyperledger.besu.datatypes.Hash)7 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)2 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)1