Skip to content

Commit

Permalink
Fixed eth_call 'input' param handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed May 17, 2024
1 parent 6d8ae0e commit 3d7631b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -126,8 +137,6 @@ public static class Deserializer extends StdDeserializer<CallArgumentsParam> {
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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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),
Expand All @@ -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)
);

Expand All @@ -171,5 +198,6 @@ public void testToCallArguments() {
assertEquals(CHAIN_ID, callArguments.getChainId());
assertEquals(VALUE, callArguments.getValue());
assertEquals(DATA, callArguments.getData());
assertEquals(DATA, callArguments.getInput());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down

0 comments on commit 3d7631b

Please sign in to comment.