RPC parameter error improvements. Test updates. (#4510)

* RPC parameter error improvements. Test updates.

Signed-off-by: mark-terry <mark.terry@consensys.net>
pull/4518/head
mark-terry 2 years ago committed by GitHub
parent c9d4b89faf
commit 7a2db24695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java
  3. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java
  4. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java
  5. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java
  6. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java
  7. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java
  8. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java
  9. 4
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java
  10. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java
  11. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHashTest.java
  12. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java
  13. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java
  14. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java
  15. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java
  16. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java
  17. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/request/SubscriptionRequestMapperTest.java

@ -9,6 +9,7 @@
### Additions and Improvements
- Improved RLP processing of zero-length string as 0x80 [#4283](https://github.com/hyperledger/besu/pull/4283) [#4388](https://github.com/hyperledger/besu/issues/4388)
- Increased level of detail in JSON-RPC parameter error log messages [#4510](https://github.com/hyperledger/besu/pull/4510)
### Bug Fixes
- Corrects emission of blockadded events when rewinding during a re-org. Fix for [#4495](https://github.com/hyperledger/besu/issues/4495)

@ -75,14 +75,14 @@ public class CliqueGetSignerMetricsTest {
public void exceptionWhenInvalidStartBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
public void exceptionWhenInvalidEndBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -63,7 +63,7 @@ public class IbftDiscardValidatorVoteTest {
public void exceptionWhenInvalidAddressParameterSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test

@ -75,14 +75,14 @@ public class IbftGetSignerMetricsTest {
public void exceptionWhenInvalidStartBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
public void exceptionWhenInvalidEndBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -70,14 +70,14 @@ public class IbftProposeValidatorVoteTest {
public void exceptionWhenNoAddressSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("true")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
public void exceptionWhenInvalidBoolParameterSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams(Address.fromHexString("1"), "c")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -65,7 +65,7 @@ public class QbftDiscardValidatorVoteTest {
public void exceptionWhenInvalidAddressParameterSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test

@ -75,14 +75,14 @@ public class QbftGetSignerMetricsTest {
public void exceptionWhenInvalidStartBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
public void exceptionWhenInvalidEndBlockSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -72,14 +72,14 @@ public class QbftProposeValidatorVoteTest {
public void exceptionWhenNoAddressSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("true")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
public void exceptionWhenInvalidBoolParameterSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams(Address.fromHexString("1"), "c")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -410,7 +410,7 @@ public class EthGetBlockByNumberIntegrationTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
/** The Tag | Quantity is the first parameter, either a String or a number */
@ -422,7 +422,7 @@ public class EthGetBlockByNumberIntegrationTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
/**

@ -74,7 +74,11 @@ public class JsonRpcParameter {
final String json = mapper.writeValueAsString(rawParam);
param = mapper.readValue(json, paramClass);
} catch (final JsonProcessingException e) {
throw new InvalidJsonRpcParameters("Invalid json rpc parameter at index " + index, e);
throw new InvalidJsonRpcParameters(
String.format(
"Invalid json rpc parameter at index %d. Supplied value was: '%s' of type: '%s' - expected type: '%s'",
index, rawParam, rawParam.getClass().getName(), paramClass.getName()),
e);
}
}

@ -77,7 +77,8 @@ public class EthGetBlockByHashTest {
public void exceptionWhenHashParamInvalid() {
assertThatThrownBy(() -> method.response(requestWithParams("hash", "true")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessage(
"Invalid json rpc parameter at index 0. Supplied value was: 'hash' of type: 'java.lang.String' - expected type: 'org.hyperledger.besu.datatypes.Hash'");
verifyNoMoreInteractions(blockchainQueries);
}
@ -85,7 +86,8 @@ public class EthGetBlockByHashTest {
public void exceptionWhenBoolParamInvalid() {
assertThatThrownBy(() -> method.response(requestWithParams(ZERO_HASH, "maybe")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessage(
"Invalid json rpc parameter at index 1. Supplied value was: 'maybe' of type: 'java.lang.String' - expected type: 'java.lang.Boolean'");
verifyNoMoreInteractions(blockchainQueries);
}

@ -120,7 +120,8 @@ public class EthGetBlockByNumberTest {
public void exceptionWhenNumberParamInvalid() {
assertThatThrownBy(() -> method.response(requestWithParams("invalid", "true")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessage(
"Invalid json rpc parameter at index 0. Supplied value was: 'invalid' of type: 'java.lang.String' - expected type: 'org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter'");
verifyNoMoreInteractions(blockchainQueries);
}
@ -128,7 +129,8 @@ public class EthGetBlockByNumberTest {
public void exceptionWhenBoolParamInvalid() {
assertThatThrownBy(() -> method.response(requestWithParams("0", "maybe")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessage(
"Invalid json rpc parameter at index 1. Supplied value was: 'maybe' of type: 'java.lang.String' - expected type: 'java.lang.Boolean'");
verifyNoMoreInteractions(blockchainQueries);
}

@ -121,7 +121,7 @@ public class EthGetMinerDataByBlockHashTest {
JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request);
assertThatThrownBy(() -> method.response(requestContext))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
verifyNoMoreInteractions(blockchainQueries);
}

@ -115,7 +115,7 @@ public class EthGetMinerDataByBlockNumberTest {
JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request);
assertThatThrownBy(() -> method.response(requestContext))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
verifyNoMoreInteractions(blockchainQueries);
}

@ -101,7 +101,7 @@ public class EthGetUncleByBlockHashAndIndexTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test
@ -113,7 +113,7 @@ public class EthGetUncleByBlockHashAndIndexTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test

@ -230,7 +230,7 @@ public class PrivCreatePrivacyGroupTest {
catchThrowableOfType(
() -> privCreatePrivacyGroup.response(request), InvalidJsonRpcParameters.class);
assertThat(response.getMessage()).isEqualTo("Invalid json rpc parameter at index 0");
assertThat(response.getMessage()).contains("Invalid json rpc parameter at index 0");
}
@Test

@ -138,7 +138,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test
@ -290,7 +290,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test
@ -303,7 +303,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid json rpc parameter at index 1");
}
@Test
@ -372,7 +372,7 @@ public class SubscriptionRequestMapperTest {
.isInstanceOf(InvalidSubscriptionRequestException.class)
.getCause()
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid json rpc parameter at index 0");
}
@Test

Loading…
Cancel
Save