Search in sources :

Example 21 with CallArguments

use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.

the class CallArgumentsToByteArrayTest method getGasLimitWhenValueIsEmpty.

@Test
public void getGasLimitWhenValueIsEmpty() throws Exception {
    CallArguments args = new CallArguments();
    args.setGas("");
    CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args);
    String maxGasLimit = "0x5AF3107A4000";
    byte[] expectedGasLimit = TypeConverter.stringHexToByteArray(maxGasLimit);
    Assert.assertArrayEquals(expectedGasLimit, byteArrayArgs.getGasLimit());
}
Also used : CallArguments(org.ethereum.rpc.CallArguments) Test(org.junit.Test)

Example 22 with CallArguments

use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.

the class PersonalModuleTest method sendTransactionWithGasLimitTest.

@Test
public void sendTransactionWithGasLimitTest() throws Exception {
    TestSystemProperties props = new TestSystemProperties();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount(PASS_FRASE);
    RskAddress receiver = wallet.addAccount();
    // Hash of the expected transaction
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    Transaction tx = TransactionFactoryHelper.createTransaction(args, props.getNetworkConstants().getChainId(), wallet.getAccount(sender, PASS_FRASE));
    String txExpectedResult = tx.getHash().toJsonString();
    TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
    when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
    Ethereum ethereum = mock(Ethereum.class);
    PersonalModuleWalletEnabled personalModuleWalletEnabled = new PersonalModuleWalletEnabled(props, ethereum, wallet, null);
    // Hash of the actual transaction builded inside the sendTransaction
    String txResult = personalModuleWalletEnabled.sendTransaction(args, PASS_FRASE);
    assertEquals(txExpectedResult, txResult);
}
Also used : Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) Ethereum(org.ethereum.facade.Ethereum) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) HashMapDB(org.ethereum.datasource.HashMapDB) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 23 with CallArguments

use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.

the class EthModuleDSLTest method testCall_getRevertReason.

@Test
public void testCall_getRevertReason() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/eth_module/revert_reason.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("tx02");
    byte[] status = transactionReceipt.getStatus();
    Assert.assertNotNull(status);
    Assert.assertEquals(0, status.length);
    EthModule eth = EthModuleTestUtils.buildBasicEthModule(world);
    final Transaction tx01 = world.getTransactionByName("tx01");
    final CallArguments args = new CallArguments();
    // "6252703f5ba322ec64d3ac45e56241b7d9e481ad";
    args.setTo("0x" + tx01.getContractAddress().toHexString());
    // call to contract with param value = 0
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000000");
    args.setValue("0");
    args.setNonce("1");
    args.setGas("10000000");
    try {
        eth.call(args, "0x2");
        fail();
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("Negative value."));
    }
    // call to contract with param value = 1
    args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000001");
    final String call = eth.call(args, "0x2");
    assertEquals("0x", call);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) CallArguments(org.ethereum.rpc.CallArguments) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 24 with CallArguments

use of org.ethereum.rpc.CallArguments 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 25 with CallArguments

use of org.ethereum.rpc.CallArguments 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)

Aggregations

CallArguments (org.ethereum.rpc.CallArguments)32 Test (org.junit.Test)30 Block (org.ethereum.core.Block)10 ProgramResult (org.ethereum.vm.program.ProgramResult)10 World (co.rsk.test.World)9 RskAddress (co.rsk.core.RskAddress)8 TransactionReceipt (org.ethereum.core.TransactionReceipt)8 EthModuleTestUtils (org.ethereum.util.EthModuleTestUtils)8 TestSystemProperties (co.rsk.config.TestSystemProperties)5 Wallet (co.rsk.core.Wallet)4 BigInteger (java.math.BigInteger)4 HashMapDB (org.ethereum.datasource.HashMapDB)4 RskJsonRpcRequestException (org.ethereum.rpc.exception.RskJsonRpcRequestException)4 GasCost (org.ethereum.vm.GasCost)4 Coin (co.rsk.core.Coin)3 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3 BlockResult (co.rsk.core.bc.BlockResult)3 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 DslProcessorException (co.rsk.test.dsl.DslProcessorException)3