Search in sources :

Example 31 with CallArguments

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

the class NestedContractsTest method testNested_interfaceCall_require.

/**
 * ------------------------ **
 *  TESTS
 ** ------------------------ *
 */
@Test
public void testNested_interfaceCall_require() throws FileNotFoundException, DslProcessorException {
    processor.processCommands(DslParser.fromResource("dsl/contract_call/contract_nested_interface_calls.txt"));
    assertFalse(world.getTransactionReceiptByName("tx04").isSuccessful());
    assertTrue(world.getTransactionReceiptByName("tx05").isSuccessful());
    // Assert state: RevertReason.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTRR, BLOCK_CONTRACT_CREATE, DataWord.ZERO));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTRR, BLOCK_TRANSACTION_FAIL, DataWord.ZERO));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTRR, BLOCK_TRANSACTION_SUCCESS, DataWord.ZERO));
    // Assert state: ContractB.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTB, BLOCK_CONTRACT_CREATE, DataWord.ONE));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTB, BLOCK_TRANSACTION_FAIL, DataWord.ONE));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTB, BLOCK_TRANSACTION_SUCCESS, DataWord.ONE));
    // Assert state: ContractA.a
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTA, BLOCK_CONTRACT_CREATE, DataWord.ONE));
    assertEquals(DataWord.valueOf(11), getStorageValue(TX_CONTRACTA, BLOCK_TRANSACTION_FAIL, DataWord.ONE));
    assertEquals(DataWord.valueOf(2), getStorageValue(TX_CONTRACTA, BLOCK_TRANSACTION_SUCCESS, DataWord.ONE));
    // Failed Call ContractA.buy(0) -> 0 > 0
    final String contractA = getContractAddressString(TX_CONTRACTA);
    CallArguments args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(0)));
    try {
        ethModule.call(args, "latest");
        fail();
    } catch (RskJsonRpcRequestException e) {
        assertThat(e.getMessage(), Matchers.containsString("Negative value"));
    }
    // Success Call -> 2 > 0
    args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(2)));
    final String call = ethModule.call(args, "latest");
// assertEquals("0x" + DataWord.valueOf(2).toString(), call);
}
Also used : RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) CallArguments(org.ethereum.rpc.CallArguments) Test(org.junit.Test)

Example 32 with CallArguments

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

the class TransactionArgumentsUtilTest method processArguments.

@Test
public void processArguments() {
    Constants constants = Constants.regtest();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount();
    RskAddress receiver = wallet.addAccount();
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, null, wallet.getAccount(sender), constants.getChainId());
    assertEquals(txArgs.getValue(), BigInteger.valueOf(100000L));
    assertEquals(txArgs.getGasPrice(), BigInteger.valueOf(10000000000000L));
    assertEquals(txArgs.getGasLimit(), BigInteger.valueOf(30400L));
    assertEquals(txArgs.getChainId(), 33);
    assertEquals(txArgs.getNonce(), BigInteger.ONE);
    assertEquals(txArgs.getData(), null);
    assertArrayEquals(txArgs.getTo(), receiver.getBytes());
}
Also used : Wallet(co.rsk.core.Wallet) TransactionArguments(org.ethereum.core.TransactionArguments) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) Constants(org.ethereum.config.Constants) HashMapDB(org.ethereum.datasource.HashMapDB) 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