eth_protocolVersion is a Quantity, not an Integer (#1470)

Per the eth JSON-RPC spec all values are strings, not raw json numbers, hence eth_protocolVersion is a Quantity ("0x3f"), not an Integer (63)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Danno Ferrin 6 years ago committed by GitHub
parent f8f81e57f9
commit a8fb76ba63
  1. 4
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthProtocolVersion.java
  2. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/EthJsonRpcHttpBySpecTest.java
  3. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthProtocolVersionTest.java
  4. 14
      ethereum/jsonrpc/src/test/resources/tech/pegasys/pantheon/ethereum/jsonrpc/eth_protocolVersion.json

@ -17,6 +17,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.Quantity;
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import java.util.OptionalInt;
@ -42,6 +43,7 @@ public class EthProtocolVersion implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
return new JsonRpcSuccessResponse(req.getId(), highestEthVersion);
return new JsonRpcSuccessResponse(
req.getId(), highestEthVersion == null ? null : Quantity.create(highestEthVersion));
}
}

@ -32,6 +32,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthGetTransaction
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthNewBlockFilter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthNewFilter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthNewPendingTransactionFilter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthProtocolVersion;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthSendRawTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.EthUninstallFilter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
@ -235,6 +236,8 @@ public class EthJsonRpcHttpBySpecTest extends AbstractEthJsonRpcHttpServiceTest
specs.put(EthEstimateGas.class, "eth_estimateGas_noParams");
specs.put(EthEstimateGas.class, "eth_estimateGas_insufficientGas");
specs.put(EthProtocolVersion.class, "eth_protocolVersion");
return specs.values();
}

@ -43,7 +43,7 @@ public class EthProtocolVersionTest {
setupSupportedEthProtocols();
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), 63);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), "0x3f");
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}
@ -69,7 +69,7 @@ public class EthProtocolVersionTest {
method = new EthProtocolVersion(supportedCapabilities);
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), 63);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), "0x3f");
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}

@ -0,0 +1,14 @@
{
"request": {
"id": 2,
"jsonrpc": "2.0",
"method": "eth_protocolVersion",
"params": []
},
"response": {
"jsonrpc": "2.0",
"id": 2,
"result": "0x3f"
},
"statusCode": 200
}
Loading…
Cancel
Save