use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class BlockToMineBuilderTest method BuildBlockHasEmptyUnclesWhenCreateAnInvalidBlock.
@Test
public void BuildBlockHasEmptyUnclesWhenCreateAnInvalidBlock() {
BlockHeader parent = buildBlockHeaderWithSibling();
BlockResult expectedResult = mock(BlockResult.class);
ArgumentCaptor<Block> blockCaptor = ArgumentCaptor.forClass(Block.class);
when(validationRules.isValid(any())).thenReturn(false);
when(blockExecutor.executeAndFill(blockCaptor.capture(), any())).thenReturn(expectedResult);
blockBuilder.build(new ArrayList<>(Collections.singletonList(parent)), new byte[0]);
assertThat(blockCaptor.getValue().getUncleList(), empty());
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class EthModuleTest method callSmokeTest.
@Test
public void callSmokeTest() {
CallArguments args = new CallArguments();
BlockResult blockResult = mock(BlockResult.class);
Block block = mock(Block.class);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);
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), config.getGasEstimationCap());
String expectedResult = TypeConverter.toUnformattedJsonHex(hReturn);
String actualResult = eth.call(args, "latest");
assertEquals(expectedResult, actualResult);
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class EthModuleTest method test_revertedTransaction.
@Test
public void test_revertedTransaction() {
CallArguments args = new CallArguments();
BlockResult blockResult = mock(BlockResult.class);
Block block = mock(Block.class);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);
byte[] hreturn = Hex.decode("08c379a000000000000000000000000000000000000000000000000000000000" + "0000002000000000000000000000000000000000000000000000000000000000" + "0000000f6465706f73697420746f6f2062696700000000000000000000000000" + "00000000");
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.isRevert()).thenReturn(true);
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), config.getGasEstimationCap());
try {
eth.call(args, "latest");
} catch (RskJsonRpcRequestException e) {
assertThat(e.getMessage(), Matchers.containsString("deposit too big"));
}
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class EthModule method call.
public String call(CallArguments args, String bnOrId) {
String hReturn = null;
try {
BlockResult blockResult = executionBlockRetriever.retrieveExecutionBlock(bnOrId);
ProgramResult res;
if (blockResult.getFinalState() != null) {
res = callConstant_workaround(args, blockResult);
} else {
res = callConstant(args, blockResult.getBlock());
}
if (res.isRevert()) {
Optional<String> revertReason = decodeRevertReason(res);
if (revertReason.isPresent()) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertReason.get());
} else {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}
}
hReturn = toUnformattedJsonHex(res.getHReturn());
return hReturn;
} finally {
LOGGER.debug("eth_call(): {}", hReturn);
}
}
Aggregations