Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Return hashrate of 0 when not mining.
Browse files Browse the repository at this point in the history
  • Loading branch information
rojotek committed Jul 11, 2019
1 parent 1b68539 commit 8536f9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public String getName() {
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 hashesPerSecond
.map(hashes -> new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashes)))
.orElseGet(() -> new JsonRpcSuccessResponse(req.getId(), Quantity.create(0)));
} catch (final UnsupportedOperationException ex) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_REQUEST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void shouldReturnValueFromMiningCoordinator() {
}

@Test
public void shouldReturnErrorWhenMiningCoordinatorDoesNotHaveHashes() {
public void shouldReturnZeroWhenMiningCoordinatorDoesNotHaveHashes() {
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NO_HASHES_PER_SECOND);
new JsonRpcSuccessResponse(request.getId(), "0x0");
when(miningCoordinator.hashesPerSecond()).thenReturn(Optional.empty());

final JsonRpcResponse actualResponse = method.response(request);
Expand Down
2 changes: 1 addition & 1 deletion ethereum/referencetests/src/test/resources
Submodule resources updated 25069 files

0 comments on commit 8536f9a

Please sign in to comment.