Skip to content

Commit

Permalink
Merge pull request #2278 from rsksmart/eth-call-block-ref-param-fix
Browse files Browse the repository at this point in the history
Fixed block ref param handling in eth_call
  • Loading branch information
Vovchyk committed Apr 8, 2024
2 parents 7f6a8e9 + 601a9f9 commit b0d2515
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions rskj-core/src/main/java/co/rsk/rpc/Web3EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ default String eth_sign(HexAddressParam addr, HexDataParam data) {
return getEthModule().sign(addr.getAddress().toHexString(), data.getAsHexString());
}

default String eth_call(CallArgumentsParam args, BlockIdentifierParam bnOrId) {
return getEthModule().call(args, bnOrId);
default String eth_call(CallArgumentsParam args, BlockRefParam blockRefParam) {
if (blockRefParam.getIdentifier() != null) {
return getEthModule().call(args, new BlockIdentifierParam(blockRefParam.getIdentifier()));
}
return eth_call(args, blockRefParam.getInputs());
}

default Map<String, Object> eth_bridgeState() throws Exception {
Expand Down Expand Up @@ -78,7 +81,7 @@ default String eth_chainId() {

String eth_blockNumber();

String eth_call(CallArgumentsParam args, Map<String, String> blockRef) throws Exception; // NOSONAR
String eth_call(CallArgumentsParam args, Map<String, String> blockRef); // NOSONAR

String eth_getBalance(HexAddressParam address, BlockRefParam blockRefParam) throws Exception;

Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public String eth_blockNumber() {

@Override
public String eth_call(CallArgumentsParam args, Map<String, String> inputs) {
return invokeByBlockRef(inputs, blockNumber -> this.eth_call(args, new BlockIdentifierParam(blockNumber)));
return invokeByBlockRef(inputs, blockNumber -> getEthModule().call(args, new BlockIdentifierParam(blockNumber)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ public byte[] execute(byte[] data) {
int expLen = parseLen(data, EXPONENT);
int modLen = parseLen(data, MODULUS);

if (baseLen == 0 && modLen == 0) {
return ByteUtil.leftPadBytes(ByteUtil.EMPTY_BYTE_ARRAY, modLen);
}

int expOffset = Math.addExact(ARGS_OFFSET, baseLen);
int modOffset = Math.addExact(expOffset, expLen);

Expand Down
8 changes: 4 additions & 4 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ function greet(string memory param) public pure returns (string memory) {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData("0xead710c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000");

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", result);
}
Expand Down Expand Up @@ -1997,7 +1997,7 @@ function greet(string memory param) public pure returns (string memory) {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData("0xead710c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000");

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", result);
}
Expand Down Expand Up @@ -2030,7 +2030,7 @@ void callNoneContractReturn() {
argsForCall.setTo(HexUtils.toUnformattedJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData(HexUtils.toUnformattedJsonHex(func.encode()));

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x", result);
}
Expand Down Expand Up @@ -2612,7 +2612,7 @@ void callWithoutReturn() {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData(HexUtils.toJsonHex(noreturn.functions.get("noreturn").encodeSignature()));

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

Assertions.assertEquals("0x", result);
}
Expand Down

0 comments on commit b0d2515

Please sign in to comment.