added blockhash as alias for blockHash param; added tests (#1567)

* JsonAlias

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/1598/head
Sally MacFarlane 4 years ago committed by GitHub
parent fabb6a852d
commit 2898bc6f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      CHANGELOG.md
  2. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/FilterParameter.java
  3. 64
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/FilterParameterTest.java
  4. 28
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getLogs_blockHash_camelCase.json

@ -4,12 +4,13 @@
### Additions and Improvements
* Added support for batched requests in WebSockets. [#1583](https://github.com/hyperledger/besu/pull/1583)
* Add a protocols section to `admin_peers` to provide info about peer health. [\#1582](https://github.com/hyperledger/besu/pull/1582)
* Added protocols section to `admin_peers` to provide info about peer health. [\#1582](https://github.com/hyperledger/besu/pull/1582)
### Bug Fixes
* Ibft2 will discard any received messages targetting a chain height <= current head - this resolves some corner cases in system correctness directly following block import. [#1575](https://github.com/hyperledger/besu/pull/1575)
* Ibft2 will discard any received messages targeting a chain height <= current head - this resolves some corner cases in system correctness directly following block import. [#1575](https://github.com/hyperledger/besu/pull/1575)
* EvmTool now throws `UnsupportedForkException` when there is an unknown fork and is YOLOv2 compatible [\#1584](https://github.com/hyperledger/besu/pull/1584)
* `eth_newFilter` now supports `blockHash` parameter as per the spec [\#1548](https://github.com/hyperledger/besu/issues/1540). (`blockhash` is also still supported.)
## 20.10.1
@ -299,7 +300,7 @@ is owned by that user.
### Remove Manual NAT method
The NAT manager `MANUAL` method has been removed.
If you have have been using the `MANUAL` method, use the `NONE` method instead. The behavior of the
If you have been using the `MANUAL` method, use the `NONE` method instead. The behavior of the
`NONE` method is the same as the previously supported `MANUAL` methods.
### Privacy users

@ -25,6 +25,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -49,7 +50,7 @@ public class FilterParameter {
final List<Address> address,
@JsonDeserialize(using = TopicsDeserializer.class) @JsonProperty("topics")
final List<List<LogTopic>> topics,
@JsonProperty("blockhash") final Hash blockHash) {
@JsonProperty("blockHash") @JsonAlias({"blockhash"}) final Hash blockHash) {
this.isValid = blockHash == null || (fromBlock == null && toBlock == null);
this.fromBlock = fromBlock != null ? fromBlock : BlockParameter.LATEST;
this.toBlock = toBlock != null ? toBlock : BlockParameter.LATEST;

@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -160,8 +161,19 @@ public class FilterParameterTest {
}
@Test
public void jsonWithBlockAndFromAndToParametersIsInvalid() throws Exception {
public void jsonWithBlockHashIncludingAliasAndFromAndToParametersIsInvalid() throws Exception {
final String json =
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
+ "\"address\":\"0x0\", \"fromBlock\": \"0x0\", \"toBlock\": \"pending\","
+ "\"topics\":["
+ TOPICS_TWO_THREE_ARRAY
+ ","
+ TOPICS_TWO_THREE_ARRAY
+ "], \"blockHash\": \""
+ Hash.ZERO
+ "\"}],\"id\":1}";
final String jsonUsingAlias =
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
+ "\"address\":\"0x0\", \"fromBlock\": \"0x0\", \"toBlock\": \"pending\","
+ "\"topics\":["
@ -176,7 +188,55 @@ public class FilterParameterTest {
final FilterParameter parsedFilterParameter =
request.getRequiredParameter(0, FilterParameter.class);
assertThat(parsedFilterParameter.isValid()).isFalse();
final JsonRpcRequestContext requestUsingAlias =
new JsonRpcRequestContext(readJsonAsJsonRpcRequest(jsonUsingAlias));
final FilterParameter parsedFilterParameterUsingAlias =
requestUsingAlias.getRequiredParameter(0, FilterParameter.class);
assertThat(parsedFilterParameterUsingAlias.isValid()).isFalse();
assertThat(parsedFilterParameter)
.isEqualToComparingFieldByField(parsedFilterParameterUsingAlias);
}
@Test
public void jsonBlockHashAliasSucceeds() throws Exception {
final String json =
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
+ "\"address\":\"0x0\","
+ "\"topics\":["
+ TOPICS_TWO_THREE_ARRAY
+ ","
+ TOPICS_TWO_THREE_ARRAY
+ "], \"blockHash\": \""
+ Hash.ZERO
+ "\"}],\"id\":1}";
final String jsonUsingAlias =
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
+ "\"address\":\"0x0\","
+ "\"topics\":["
+ TOPICS_TWO_THREE_ARRAY
+ ","
+ TOPICS_TWO_THREE_ARRAY
+ "], \"blockhash\": \""
+ Hash.ZERO
+ "\"}],\"id\":1}";
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json));
final FilterParameter parsedFilterParameter =
request.getRequiredParameter(0, FilterParameter.class);
final JsonRpcRequestContext requestUsingAlias =
new JsonRpcRequestContext(readJsonAsJsonRpcRequest(jsonUsingAlias));
final FilterParameter parsedFilterParameterUsingAlias =
requestUsingAlias.getRequiredParameter(0, FilterParameter.class);
assertThat(parsedFilterParameterUsingAlias.isValid()).isTrue();
assertThat(parsedFilterParameterUsingAlias.getBlockHash()).isEqualTo(Optional.of(Hash.ZERO));
// blockhash and blockHash should end up the same
assertThat(parsedFilterParameter)
.isEqualToComparingFieldByField(parsedFilterParameterUsingAlias);
}
@Test

@ -0,0 +1,28 @@
{
"request": {
"id": 406,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"address": [],
"topics": [["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x65c9ac8011e286e89d02a269890f41d67ca2cc597b2c76c7c69321ff492be580"]],
"blockHash": "0x3c419f39b340a4c35cc27b8f7880b779dc1abb9814ad13a2a5a55b885cc8ec2d"
}]
},
"response": {
"jsonrpc": "2.0",
"id": 406,
"result" : [{
"logIndex" : "0x0",
"removed": false,
"blockNumber" : "0x17",
"blockHash" : "0x3c419f39b340a4c35cc27b8f7880b779dc1abb9814ad13a2a5a55b885cc8ec2d",
"transactionHash" : "0x97a385bf570ced7821c6495b3877ddd2afd5c452f350f0d4876e98d9161389c6",
"transactionIndex" : "0x0",
"address" : "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"data" : "0x000000000000000000000000000000000000000000000000000000000000002a",
"topics" : ["0x65c9ac8011e286e89d02a269890f41d67ca2cc597b2c76c7c69321ff492be580"]
}]
},
"statusCode": 200
}
Loading…
Cancel
Save