Search in sources :

Example 1 with SignerMetricResult

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

the class QbftGetSignerMetricsTest method getSignerMetricsWithEarliest.

@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWithEarliest() {
    final long startBlock = 0L;
    final long endBlock = 3L;
    final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
    when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
    LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
    final JsonRpcRequestContext request = requestWithParams("earliest", String.valueOf(endBlock));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
    assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Example 2 with SignerMetricResult

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

the class QbftGetSignerMetricsTest method getSignerMetricsWhenNoParams.

@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWhenNoParams() {
    final long startBlock = 1L;
    final long endBlock = 3L;
    when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
    final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
    LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
    // missing validator
    signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0]));
    final JsonRpcRequestContext request = requestWithParams();
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
    assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Example 3 with SignerMetricResult

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

the class QbftGetSignerMetricsTest method generateBlock.

private SignerMetricResult generateBlock(final long number) {
    final Address proposerAddressBlock = VALIDATORS[(int) (number % VALIDATORS.length)];
    final BlockHeader header = new BlockHeaderTestFixture().number(number).buildHeader();
    when(blockchainQueries.getBlockHeaderByNumber(number)).thenReturn(Optional.of(header));
    when(blockInterface.getProposerOfBlock(header)).thenReturn(proposerAddressBlock);
    when(validatorProvider.getValidatorsAfterBlock(header)).thenReturn(Arrays.asList(VALIDATORS));
    final SignerMetricResult signerMetricResult = new SignerMetricResult(proposerAddressBlock);
    signerMetricResult.incrementeNbBlock();
    signerMetricResult.setLastProposedBlockNumber(number);
    return signerMetricResult;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Address(org.hyperledger.besu.datatypes.Address) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult)

Example 4 with SignerMetricResult

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

the class CliqueGetSignerMetricsTest method getSignerMetricsWithEarliest.

@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWithEarliest() {
    final long startBlock = 0L;
    final long endBlock = 3L;
    final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
    when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
    LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
    final JsonRpcRequestContext request = requestWithParams("earliest", String.valueOf(endBlock));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
    assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Example 5 with SignerMetricResult

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

the class CliqueGetSignerMetricsTest method getSignerMetricsWithLatest.

@Test
@SuppressWarnings("unchecked")
public void getSignerMetricsWithLatest() {
    final long startBlock = 1L;
    final long endBlock = 3L;
    final List<SignerMetricResult> signerMetricResultList = new ArrayList<>();
    when(blockchainQueries.headBlockNumber()).thenReturn(endBlock);
    LongStream.range(startBlock, endBlock).forEach(value -> signerMetricResultList.add(generateBlock(value)));
    // missing validator
    signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0]));
    final JsonRpcRequestContext request = requestWithParams(String.valueOf(startBlock), "latest");
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request);
    assertThat((Collection<SignerMetricResult>) response.getResult()).containsExactlyInAnyOrderElementsOf(signerMetricResultList);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) SignerMetricResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult) Test(org.junit.Test)

Aggregations

SignerMetricResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult)22 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)19 ArrayList (java.util.ArrayList)18 Collection (java.util.Collection)18 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)18 Test (org.junit.Test)18 Address (org.hyperledger.besu.datatypes.Address)4 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)4 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)3 HashMap (java.util.HashMap)1 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1