Search in sources :

Example 11 with BlockResult

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());
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 12 with BlockResult

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);
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) CallArguments(org.ethereum.rpc.CallArguments) ProgramResult(org.ethereum.vm.program.ProgramResult) Block(org.ethereum.core.Block) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) Test(org.junit.Test)

Example 13 with BlockResult

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"));
    }
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) BlockResult(co.rsk.core.bc.BlockResult) CallArguments(org.ethereum.rpc.CallArguments) ProgramResult(org.ethereum.vm.program.ProgramResult) Block(org.ethereum.core.Block) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) Test(org.junit.Test)

Example 14 with BlockResult

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);
    }
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) ProgramResult(org.ethereum.vm.program.ProgramResult)

Aggregations

BlockResult (co.rsk.core.bc.BlockResult)14 Test (org.junit.Test)12 Block (org.ethereum.core.Block)7 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)4 ProgramResult (org.ethereum.vm.program.ProgramResult)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Coin (co.rsk.core.Coin)3 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3 Keccak256 (co.rsk.crypto.Keccak256)3 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 BlockHeader (org.ethereum.core.BlockHeader)3 CallArguments (org.ethereum.rpc.CallArguments)3 ArrayList (java.util.ArrayList)2 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 EthereumImpl (org.ethereum.facade.EthereumImpl)1 RskJsonRpcRequestException (org.ethereum.rpc.exception.RskJsonRpcRequestException)1 BuildInfo (org.ethereum.util.BuildInfo)1