diff --git a/rskj-core/src/main/java/org/ethereum/rpc/parameters/CallArgumentsParam.java b/rskj-core/src/main/java/org/ethereum/rpc/parameters/CallArgumentsParam.java index c7b40fee4a6..96134328f51 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/parameters/CallArgumentsParam.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/parameters/CallArgumentsParam.java @@ -38,10 +38,11 @@ public class CallArgumentsParam { private final HexNumberParam chainId; private final HexNumberParam value; private final HexDataParam data; + private final HexDataParam input; public CallArgumentsParam(HexAddressParam from, HexAddressParam to, HexNumberParam gas, HexNumberParam gasPrice, HexNumberParam gasLimit, HexNumberParam nonce, - HexNumberParam chainId, HexNumberParam value, HexDataParam data) { + HexNumberParam chainId, HexNumberParam value, HexDataParam data, HexDataParam input) { this.from = from; this.to = to; this.gas = gas; @@ -51,6 +52,7 @@ public CallArgumentsParam(HexAddressParam from, HexAddressParam to, HexNumberPar this.chainId = chainId; this.value = value; this.data = data; + this.input = input; } public HexAddressParam getFrom() { @@ -89,8 +91,11 @@ public HexDataParam getData() { return data; } - public CallArguments toCallArguments() { + public HexDataParam getInput() { + return input; + } + public CallArguments toCallArguments() { String caFrom = this.from == null ? null : this.from.getAddress().toJsonString(); String caTo = this.to == null ? null : this.to.getAddress().toJsonString(); String caGas = this.gas == null ? null : this.gas.getHexNumber(); @@ -100,6 +105,7 @@ public CallArguments toCallArguments() { String caChainId = this.chainId == null ? null : this.chainId.getHexNumber(); String caValue = this.value == null ? null : this.value.getHexNumber(); String caData = this.data == null ? null : this.data.getAsHexString(); + String caInput = this.input == null ? null : this.input.getAsHexString(); CallArguments callArguments = new CallArguments(); callArguments.setFrom(caFrom); @@ -110,7 +116,12 @@ public CallArguments toCallArguments() { callArguments.setNonce(caNonce); callArguments.setChainId(caChainId); callArguments.setValue(caValue); - callArguments.setData(caData); + if (caData != null) { + callArguments.setData(caData); + } + if (caInput != null) { + callArguments.setInput(caInput); + } return callArguments; } @@ -126,8 +137,6 @@ public static class Deserializer extends StdDeserializer { public CallArgumentsParam deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); - BlockIdentifierParam fromBlock = node.has("fromBlock") ? new BlockIdentifierParam(node.get("fromBlock").asText()) : null; - HexAddressParam from = node.has("from") ? new HexAddressParam(node.get("from").asText()) : null; HexAddressParam to = node.has("to") ? new HexAddressParam(node.get("to").asText()) : null; HexNumberParam gas = node.has("gas") ? new HexNumberParam(node.get("gas").asText()) : null; @@ -137,8 +146,9 @@ public CallArgumentsParam deserialize(JsonParser jp, DeserializationContext ctxt HexNumberParam chainId = node.has("chainId") ? new HexNumberParam(node.get("chainId").asText()) : null; HexNumberParam value = node.has("value") ? new HexNumberParam(node.get("value").asText()) : null; HexDataParam data = node.has("data") ? new HexDataParam(node.get("data").asText()) : null; + HexDataParam input = node.has("input") ? new HexDataParam(node.get("input").asText()) : null; - return new CallArgumentsParam(from, to, gas, gasPrice, gasLimit, nonce, chainId, value, data); + return new CallArgumentsParam(from, to, gas, gasPrice, gasLimit, nonce, chainId, value, data, input); } } } diff --git a/rskj-core/src/test/java/org/ethereum/rpc/parameters/CallArgumentsParamTest.java b/rskj-core/src/test/java/org/ethereum/rpc/parameters/CallArgumentsParamTest.java index 599272d26aa..1a89239437f 100644 --- a/rskj-core/src/test/java/org/ethereum/rpc/parameters/CallArgumentsParamTest.java +++ b/rskj-core/src/test/java/org/ethereum/rpc/parameters/CallArgumentsParamTest.java @@ -7,9 +7,7 @@ import org.ethereum.rpc.exception.RskJsonRpcRequestException; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; public class CallArgumentsParamTest { @@ -148,7 +146,7 @@ public void testInvalidChainIdInCallArgumentsParam() throws JsonProcessingExcept } @Test - public void testToCallArguments() { + public void testToCallArgumentsWithData() { CallArgumentsParam callArgumentsParam = new CallArgumentsParam( new HexAddressParam(FROM), new HexAddressParam(TO), @@ -158,6 +156,35 @@ public void testToCallArguments() { new HexNumberParam(NONCE), new HexNumberParam(CHAIN_ID), new HexNumberParam(VALUE), + new HexDataParam(DATA), + null + ); + + CallArguments callArguments = callArgumentsParam.toCallArguments(); + + assertEquals(FROM, callArguments.getFrom()); + assertEquals(TO, callArguments.getTo()); + assertEquals(GAS, callArguments.getGas()); + assertEquals(GAS_PRICE, callArguments.getGasPrice()); + assertEquals(NONCE, callArguments.getNonce()); + assertEquals(CHAIN_ID, callArguments.getChainId()); + assertEquals(VALUE, callArguments.getValue()); + assertEquals(DATA, callArguments.getData()); + assertEquals(DATA, callArguments.getInput()); + } + + @Test + public void testToCallArgumentsWithInput() { + CallArgumentsParam callArgumentsParam = new CallArgumentsParam( + new HexAddressParam(FROM), + new HexAddressParam(TO), + new HexNumberParam(GAS), + new HexNumberParam(GAS_PRICE), + null, + new HexNumberParam(NONCE), + new HexNumberParam(CHAIN_ID), + new HexNumberParam(VALUE), + null, new HexDataParam(DATA) ); @@ -171,5 +198,6 @@ public void testToCallArguments() { assertEquals(CHAIN_ID, callArguments.getChainId()); assertEquals(VALUE, callArguments.getValue()); assertEquals(DATA, callArguments.getData()); + assertEquals(DATA, callArguments.getInput()); } } diff --git a/rskj-core/src/test/java/org/ethereum/util/TransactionFactoryHelper.java b/rskj-core/src/test/java/org/ethereum/util/TransactionFactoryHelper.java index bea56c4e635..a8d5828ec7f 100644 --- a/rskj-core/src/test/java/org/ethereum/util/TransactionFactoryHelper.java +++ b/rskj-core/src/test/java/org/ethereum/util/TransactionFactoryHelper.java @@ -131,7 +131,8 @@ public static CallArgumentsParam toCallArgumentsParam(CallArguments args) { Optional.ofNullable(args.getNonce()).filter(p -> !p.isEmpty()).map(HexNumberParam::new).orElse(null), Optional.ofNullable(args.getChainId()).filter(p -> !p.isEmpty()).map(HexNumberParam::new).orElse(null), Optional.ofNullable(args.getValue()).filter(p -> !p.isEmpty()).map(HexNumberParam::new).orElse(null), - Optional.ofNullable(args.getData()).filter(p -> !p.isEmpty()).map(HexDataParam::new).orElse(null) + Optional.ofNullable(args.getData()).filter(p -> !p.isEmpty()).map(HexDataParam::new).orElse(null), + Optional.ofNullable(args.getInput()).filter(p -> !p.isEmpty()).map(HexDataParam::new).orElse(null) ); }