Return hashrate of 0 when not mining. (#1672)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Rob Dawson 5 years ago committed by GitHub
parent 15bc6e243d
commit d0e69a2433
  1. 5
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrate.java
  2. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrateTest.java

@ -40,10 +40,7 @@ public class EthHashrate implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequest req) {
try {
final Optional<Long> hashesPerSecond = miningCoordinator.hashesPerSecond();
if (hashesPerSecond.isPresent()) {
return new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashesPerSecond.get()));
}
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NO_HASHES_PER_SECOND);
return new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashesPerSecond.orElse(0L)));
} catch (final UnsupportedOperationException ex) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_REQUEST);
}

@ -59,10 +59,9 @@ public class EthHashrateTest {
}
@Test
public void shouldReturnErrorWhenMiningCoordinatorDoesNotHaveHashes() {
public void shouldReturnZeroWhenMiningCoordinatorDoesNotHaveHashes() {
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NO_HASHES_PER_SECOND);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), "0x0");
when(miningCoordinator.hashesPerSecond()).thenReturn(Optional.empty());
final JsonRpcResponse actualResponse = method.response(request);

Loading…
Cancel
Save