Skip to content

Commit

Permalink
RPC Parameters to accept input and data field (hyperledger#6094)
Browse files Browse the repository at this point in the history
* Accept input or data as payload for RPC calls

Signed-off-by: Gabriel Fukushima <[email protected]>

* Add json new rpc valid and invalid request to test the changes

Signed-off-by: Gabriel Fukushima <[email protected]>

* Change JsonCallParameter signature to avoid duplicating constructor

Signed-off-by: Gabriel Fukushima <[email protected]>

* Add changelog

Signed-off-by: Gabriel Fukushima <[email protected]>

---------

Signed-off-by: Gabriel Fukushima <[email protected]>
(cherry picked from commit 6dd558b)
  • Loading branch information
gfukushima authored and jflo committed Nov 10, 2023
1 parent 7f00c48 commit 98f97ad
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Ethereum Classic Spiral network upgrade [#6078](https://github.com/hyperledger/besu/pull/6078)
- Add a method to read from a `Memory` instance without altering its inner state [#6073](https://github.com/hyperledger/besu/pull/6073)
- TraceService: return results for transactions in block [#6086](https://github.com/hyperledger/besu/pull/6086)
- Accept `input` and `data` field for the payload of transaction-related RPC methods [#6094](https://github.com/hyperledger/besu/pull/6094)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void shouldReturnExpectedResultForCallAtLatestBlock() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -98,6 +99,7 @@ public void shouldReturnExpectedResultForCallAtSpecificBlock() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "0x8");
final JsonRpcResponse expectedResponse =
Expand All @@ -123,6 +125,7 @@ public void shouldReturnSuccessWhenCreatingContract() {
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -148,6 +151,7 @@ public void shouldReturnErrorWithGasLimitTooLow() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -170,6 +174,7 @@ public void shouldReturnErrorWithGasPriceTooHighAndStrict() {
null,
null,
Bytes.fromHexString("0x12a7b914"),
null,
true,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
Expand All @@ -193,6 +198,7 @@ public void shouldReturnSuccessWithGasPriceTooHighNotStrict() {
null,
null,
Bytes.fromHexString("0x12a7b914"),
null,
false,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
Expand All @@ -218,6 +224,7 @@ public void shouldReturnErrorWithGasPriceTooHigh() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -241,6 +248,7 @@ public void shouldReturnSuccessWithValidGasPrice() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -265,6 +273,7 @@ public void shouldReturnErrorWithGasPriceAndEmptyBalance() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -288,6 +297,7 @@ public void shouldReturnSuccessWithZeroGasPriceAndEmptyBalance() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -312,6 +322,7 @@ public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -336,6 +347,7 @@ public void shouldReturnSuccessWithInvalidGasPricingAndEmptyBalance() {
null,
Bytes.fromHexString("0x12a7b914"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -360,6 +372,7 @@ public void shouldReturnEmptyHashResultForCallWithOnlyToField() {
null,
null,
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void shouldSucceedWhenCreateAccessListSimpleContract() {
@Test
public void shouldReturnExpectedValueForEmptyCallParameter() {
final JsonCallParameter callParameter =
new JsonCallParameter(null, null, null, null, null, null, null, null, null, null);
new JsonCallParameter(null, null, null, null, null, null, null, null, null, null, null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08));
Expand All @@ -163,6 +163,7 @@ public void shouldReturnExpectedValueForTransfer() {
Wei.ZERO,
null,
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
Expand All @@ -187,6 +188,7 @@ public void shouldReturnExpectedValueForContractDeploy() {
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
Expand All @@ -210,6 +212,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec
null,
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
false,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
Expand All @@ -224,7 +227,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec
@Test
public void shouldReturnExpectedValueForInsufficientGas() {
final JsonCallParameter callParameter =
new JsonCallParameter(null, null, 1L, null, null, null, null, null, null, null);
new JsonCallParameter(null, null, 1L, null, null, null, null, null, null, null, null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08));
Expand Down Expand Up @@ -258,6 +261,7 @@ private JsonCallParameter createAccessListJsonCallParameters(
null,
null,
null,
null,
accessList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setUp() {
@Test
public void shouldReturnExpectedValueForEmptyCallParameter() {
final JsonCallParameter callParameter =
new JsonCallParameter(null, null, null, null, null, null, null, null, null, null);
new JsonCallParameter(null, null, null, null, null, null, null, null, null, null, null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208");

Expand All @@ -86,6 +86,7 @@ public void shouldReturnExpectedValueForTransfer() {
Wei.ONE,
null,
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208");
Expand All @@ -109,6 +110,7 @@ public void shouldReturnExpectedValueForContractDeploy() {
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x1b551");
Expand All @@ -131,6 +133,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec
null,
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
false,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
Expand All @@ -154,6 +157,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr
null,
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
true,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
Expand All @@ -167,7 +171,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr
@Test
public void shouldReturnExpectedValueForInsufficientGas() {
final JsonCallParameter callParameter =
new JsonCallParameter(null, null, 1L, null, null, null, null, null, null, null);
new JsonCallParameter(null, null, 1L, null, null, null, null, null, null, null, null);
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -98,6 +99,7 @@ public void shouldReturnErrorWithGasPriceTooHigh() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -121,6 +123,7 @@ public void shouldReturnSuccessWithValidGasPrice() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -145,6 +148,7 @@ public void shouldReturnErrorWithGasPriceLessThanCurrentBaseFee() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -168,6 +172,7 @@ public void shouldReturnSuccessWithValidMaxFeePerGas() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -192,6 +197,7 @@ public void shouldReturnSuccessWithValidMaxFeePerGasAndMaxPriorityFeePerGas() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -216,6 +222,7 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanCurrentBaseFee() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -239,6 +246,7 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanMaxPriorityFeePerGas()
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand All @@ -263,6 +271,7 @@ public void shouldReturnErrorWithMaxFeePerGasAndEmptyBalance() {
null,
Bytes.fromHexString("0x2e64cec1"),
null,
null,
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void shouldReturnExpectedValueForTransfer() {
Wei.ONE,
null,
null,
null,
null);

final JsonRpcResponse response = method.response(requestWithParams(callParameter));
Expand All @@ -98,6 +99,7 @@ public void shouldReturnExpectedValueForTransfer_WithAccessList() {
Wei.ONE,
null,
null,
null,
createAccessList());

final JsonRpcResponse response = method.response(requestWithParams(callParameter));
Expand All @@ -119,6 +121,7 @@ public void shouldReturnExpectedValueForContractDeploy() {
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
null);
final JsonRpcResponse response = method.response(requestWithParams(callParameter));
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x1f081");
Expand All @@ -139,6 +142,7 @@ public void shouldReturnExpectedValueForContractDeploy_WithAccessList() {
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
createAccessList());

final JsonRpcResponse response = method.response(requestWithParams(callParameter));
Expand Down
Loading

0 comments on commit 98f97ad

Please sign in to comment.