Skip to content

Commit

Permalink
[PAN-3062] Stop Returning null for 'pending' RPC calls (PegaSysEng#1883)
Browse files Browse the repository at this point in the history
Treat "pending" RPC calls as "latest" instead of returning null.
  • Loading branch information
Danno Ferrin authored and pscott committed Sep 2, 2019
1 parent 4be81a3 commit 5286650
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
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.TransactionResult;
import tech.pegasys.pantheon.testutil.BlockTestUtil;

Expand Down Expand Up @@ -148,8 +147,7 @@ public void earliestBlockTransactions() {
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}

@Test
public void latestBlockHashes() {
private JsonRpcResponse expectedLatestBlockHashes() {
final Map<JsonRpcResponseKey, String> out = new EnumMap<>(JsonRpcResponseKey.class);
out.put(COINBASE, "0x8888f1f195afa192cfee860698584c030f4c9db1");
out.put(DIFFICULTY, "0x207c0");
Expand All @@ -173,16 +171,20 @@ public void latestBlockHashes() {
final List<TransactionResult> transactions =
responseUtils.transactions(
"0xcef53f2311d7c80e9086d661e69ac11a5f3d081e28e02a9ba9b66749407ac310");
final JsonRpcResponse expected = responseUtils.response(out, transactions);
return responseUtils.response(out, transactions);
}

@Test
public void latestBlockHashes() {
final JsonRpcResponse expected = expectedLatestBlockHashes();
final JsonRpcRequest request = requestWithParams("latest", false);

final JsonRpcResponse actual = ethGetBlockNumber().response(request);

assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}

@Test
public void latestBlockTransactions() {
private JsonRpcResponse expectedLatestBlockTransactions() {
final Map<JsonRpcResponseKey, String> out = new EnumMap<>(JsonRpcResponseKey.class);
out.put(COINBASE, "0x8888f1f195afa192cfee860698584c030f4c9db1");
out.put(DIFFICULTY, "0x207c0");
Expand Down Expand Up @@ -220,7 +222,12 @@ public void latestBlockTransactions() {
"0x1b",
"0x705b002a7df60707d33812e0298411721be20ea5a2f533707295140d89263b79",
"0x78024390784f24160739533b3ceea2698289a02afd9cc768581b4aa3d5f4b105"));
final JsonRpcResponse expected = responseUtils.response(out, transactions);
return responseUtils.response(out, transactions);
}

@Test
public void latestBlockTransactions() {
final JsonRpcResponse expected = expectedLatestBlockTransactions();
final JsonRpcRequest request = requestWithParams("latest", true);

final JsonRpcResponse actual = ethGetBlockNumber().response(request);
Expand All @@ -230,22 +237,22 @@ public void latestBlockTransactions() {

@Test
public void pendingBlockHashes() {
final JsonRpcResponse expected = new JsonRpcSuccessResponse(null, null);
final JsonRpcResponse expected = expectedLatestBlockHashes();
final JsonRpcRequest request = requestWithParams("pending", false);

final JsonRpcResponse actual = ethGetBlockNumber().response(request);

assertThat(actual).isEqualToComparingFieldByField(expected);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}

@Test
public void pendingBlockTransactions() {
final JsonRpcResponse expected = new JsonRpcSuccessResponse(null, null);
final JsonRpcResponse expected = expectedLatestBlockTransactions();
final JsonRpcRequest request = requestWithParams("pending", true);

final JsonRpcResponse actual = ethGetBlockNumber().response(request);

assertThat(actual).isEqualToComparingFieldByField(expected);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ protected JsonRpcParameter getParameters() {

protected Object pendingResult(final JsonRpcRequest request) {
// TODO: Update once we mine and better understand pending semantics.
// This may also be worth always returning null for.
return null;
// For now act like we are not mining and just return latest.
return latestResult(request);
}

protected Object latestResult(final JsonRpcRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public void ethGetUncleCountByBlockNumberPending() throws Exception {
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcResult(json, id);
// Check result
assertThat(json.getString("result")).isNull();
assertThat(json.getString("result")).isEqualTo("0x0");
}
}

Expand All @@ -581,7 +581,7 @@ public void ethGetUncleCountByBlockNumberPendingNoData() throws Exception {
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcResult(json, id);
// Check result
assertThat(json.getString("result")).isNull();
assertThat(json.getString("result")).isEqualTo("0x0");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"request": {
"id": 3,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"data": "0x12a7b914"
},
"pending"
]
},
"response": {
"jsonrpc": "2.0",
"id": 3,
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"request": {
"id": 27,
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"pending"
]
},
"response": {
"jsonrpc": "2.0",
"id": 27,
"result": "0x140"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"request": {
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"pending"
]
},
"response": {
"jsonrpc": "2.0",
"id": 0,
"result": "0x6000357c010000000000000000000000000000000000000000000000000000000090048063102accc11461012c57806312a7b9141461013a5780631774e6461461014c5780631e26fd331461015d5780631f9030371461016e578063343a875d1461018057806338cc4831146101955780634e7ad367146101bd57806357cb2fc4146101cb57806365538c73146101e057806368895979146101ee57806376bc21d9146102005780639a19a9531461020e5780639dc2c8f51461021f578063a53b1c1e1461022d578063a67808571461023e578063b61c05031461024c578063c2b12a731461025a578063d2282dc51461026b578063e30081a01461027c578063e8beef5b1461028d578063f38b06001461029b578063f5b53e17146102a9578063fd408767146102bb57005b6101346104d6565b60006000f35b61014261039b565b8060005260206000f35b610157600435610326565b60006000f35b6101686004356102c9565b60006000f35b610176610442565b8060005260206000f35b6101886103d3565b8060ff1660005260206000f35b61019d610413565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6101c56104c5565b60006000f35b6101d36103b7565b8060000b60005260206000f35b6101e8610454565b60006000f35b6101f6610401565b8060005260206000f35b61020861051f565b60006000f35b6102196004356102e5565b60006000f35b610227610693565b60006000f35b610238600435610342565b60006000f35b610246610484565b60006000f35b610254610493565b60006000f35b61026560043561038d565b60006000f35b610276600435610350565b60006000f35b61028760043561035e565b60006000f35b6102956105b4565b60006000f35b6102a3610547565b60006000f35b6102b16103ef565b8060005260206000f35b6102c3610600565b60006000f35b80600060006101000a81548160ff021916908302179055505b50565b80600060016101000a81548160ff02191690837f01000000000000000000000000000000000000000000000000000000000000009081020402179055505b50565b80600060026101000a81548160ff021916908302179055505b50565b806001600050819055505b50565b806002600050819055505b50565b80600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b50565b806004600050819055505b50565b6000600060009054906101000a900460ff1690506103b4565b90565b6000600060019054906101000a900460000b90506103d0565b90565b6000600060029054906101000a900460ff1690506103ec565b90565b600060016000505490506103fe565b90565b60006002600050549050610410565b90565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905061043f565b90565b60006004600050549050610451565b90565b7f65c9ac8011e286e89d02a269890f41d67ca2cc597b2c76c7c69321ff492be5806000602a81526020016000a15b565b6000602a81526020016000a05b565b60017f81933b308056e7e85668661dcd102b1f22795b4431f9cf4625794f381c271c6b6000602a81526020016000a25b565b60016000602a81526020016000a15b565b3373ffffffffffffffffffffffffffffffffffffffff1660017f0e216b62efbb97e751a2ce09f607048751720397ecfb9eef1e48a6644948985b6000602a81526020016000a35b565b3373ffffffffffffffffffffffffffffffffffffffff1660016000602a81526020016000a25b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001023373ffffffffffffffffffffffffffffffffffffffff1660017f317b31292193c2a4f561cc40a95ea0d97a2733f14af6d6d59522473e1f3ae65f6000602a81526020016000a45b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001023373ffffffffffffffffffffffffffffffffffffffff1660016000602a81526020016000a35b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001023373ffffffffffffffffffffffffffffffffffffffff1660017fd5f0a30e4be0c6be577a71eceb7464245a796a7e6a55c0d971837b250de05f4e60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe98152602001602a81526020016000a45b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001023373ffffffffffffffffffffffffffffffffffffffff16600160007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe98152602001602a81526020016000a35b56"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"request": {
"id": 341,
"jsonrpc": "2.0",
"method": "eth_getStorageAt",
"params": [
"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"0x4",
"pending"
]
},
"response": {
"jsonrpc": "2.0",
"id": 341,
"result": "0xaabbccffffffffffffffffffffffffffffffffffffffffffffffffffffffffee"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"request": {
"id": 484,
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex",
"params": [
"pending",
"0x0"
]
},
"response": {
"jsonrpc": "2.0",
"id": 484,
"result": {
"blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53",
"blockNumber": "0x20",
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f",
"gasPrice": "0x1",
"hash": "0xcef53f2311d7c80e9086d661e69ac11a5f3d081e28e02a9ba9b66749407ac310",
"input": "0x9dc2c8f5",
"nonce": "0x1f",
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"transactionIndex": "0x0",
"value": "0xa",
"v": "0x1b",
"r": "0x705b002a7df60707d33812e0298411721be20ea5a2f533707295140d89263b79",
"s": "0x78024390784f24160739533b3ceea2698289a02afd9cc768581b4aa3d5f4b105"
}
},
"statusCode": 200
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"request": {
"id": 488,
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"pending"
]
},
"response": {
"jsonrpc": "2.0",
"id": 488,
"result": "0x20"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"response": {
"jsonrpc": "2.0",
"id": 415,
"result": null
"result": [{}]
},
"statusCode": 200
}

0 comments on commit 5286650

Please sign in to comment.