Skip to content

Commit

Permalink
Fixed issue with empty contract's return result
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Nov 2, 2020
1 parent 310d527 commit 071426a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
5 changes: 2 additions & 3 deletions rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
import java.io.IOException;
import java.util.Map;

import static org.ethereum.rpc.TypeConverter.stringHexToBigInteger;
import static org.ethereum.rpc.TypeConverter.toJsonHex;
import static org.ethereum.rpc.TypeConverter.*;
import static org.ethereum.rpc.exception.RskJsonRpcRequestException.invalidParamError;

// TODO add all RPC methods
Expand Down Expand Up @@ -126,7 +125,7 @@ public String call(Web3.CallArguments args, String bnOrId) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}

return s = toJsonHex(res.getHReturn());
return s = toUnformattedJsonHex(res.getHReturn());
} finally {
LOGGER.debug("eth_call(): {}", s);
}
Expand Down
43 changes: 40 additions & 3 deletions rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.mockito.Mockito.*;

public class EthModuleTest {

@Test
public void callSmokeTest() {
Web3.CallArguments args = new Web3.CallArguments();
Expand All @@ -52,10 +53,46 @@ public void callSmokeTest() {
.thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);

byte[] hreturn = TypeConverter.stringToByteArray("hello");
byte[] hReturn = TypeConverter.stringToByteArray("hello");
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.getHReturn())
.thenReturn(hReturn);

ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(executorResult);

EthModule eth = new EthModule(
null,
anyByte(),
null,
null,
executor,
retriever,
null,
null,
null,
new BridgeSupportFactory(
null, null, null));

String result = eth.call(args, "latest");
assertThat(result, is(TypeConverter.toUnformattedJsonHex(hReturn)));
}

@Test
public void callWithoutReturn() {
Web3.CallArguments args = new Web3.CallArguments();
BlockResult blockResult = mock(BlockResult.class);
Block block = mock(Block.class);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.getExecutionBlock_workaround("latest"))
.thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);

byte[] hReturn = new byte[0];
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.getHReturn())
.thenReturn(hreturn);
.thenReturn(hReturn);

ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any()))
Expand All @@ -75,7 +112,7 @@ public void callSmokeTest() {
null, null, null));

String result = eth.call(args, "latest");
assertThat(result, is(TypeConverter.toJsonHex(hreturn)));
assertThat(result, is(TypeConverter.toUnformattedJsonHex(hReturn)));
}

@Test
Expand Down

0 comments on commit 071426a

Please # to comment.