Search in sources :

Example 16 with CallArguments

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

the class NestedContractsTest method testNested_ABICall_require.

@Test
public void testNested_ABICall_require() throws FileNotFoundException, DslProcessorException {
    processor.processCommands(DslParser.fromResource("dsl/contract_call/contract_nested_abi_calls.txt"));
    world.getRepository().commit();
    assertTrue(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));
    // Null == Zero
    assertEquals(null, 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));
    // Null == Zero
    assertEquals(null, 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("tx03");
    CallArguments args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(0)));
    String call = ethModule.call(args, "latest");
    assertEquals("0x" + DataWord.valueOf(0).toString(), call);
    // Success Call -> 2 > 0
    args = buildArgs(contractA, Hex.toHexString(BUY_FUNCTION.encode(2)));
    call = ethModule.call(args, "latest");
    assertEquals("0x" + DataWord.valueOf(2).toString(), call);
}
Also used : CallArguments(org.ethereum.rpc.CallArguments) Test(org.junit.Test)

Example 17 with CallArguments

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

the class CallArgumentsToByteArrayTest method getGasLimitWhenValueIsNull.

@Test
public void getGasLimitWhenValueIsNull() throws Exception {
    CallArguments args = new CallArguments();
    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 18 with CallArguments

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

the class CallArgumentsToByteArrayTest method gasLimitForGasEstimationBelowGasCap.

@Test
public void gasLimitForGasEstimationBelowGasCap() {
    CallArguments callArguments = new CallArguments();
    callArguments.setGas(TypeConverter.toQuantityJsonHex(1));
    CallArgumentsToByteArray callArgumentsToByteArray = new CallArgumentsToByteArray(callArguments);
    Assert.assertEquals(1, ByteUtil.byteArrayToLong(callArgumentsToByteArray.gasLimitForGasEstimation(config.getGasEstimationCap())));
}
Also used : CallArguments(org.ethereum.rpc.CallArguments) Test(org.junit.Test)

Example 19 with CallArguments

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

the class CallArgumentsToByteArrayTest method gasLimitForGasEstimationExceedingGasCap.

@Test
public void gasLimitForGasEstimationExceedingGasCap() {
    long hugeAmountOfGas = 900000000000000l;
    long gasEstimationCap = config.getGasEstimationCap();
    CallArguments callArguments = new CallArguments();
    callArguments.setGas(TypeConverter.toQuantityJsonHex(hugeAmountOfGas));
    Assert.assertEquals(hugeAmountOfGas, Long.decode(callArguments.getGas()).longValue());
    CallArgumentsToByteArray callArgumentsToByteArray = new CallArgumentsToByteArray(callArguments);
    Assert.assertEquals(hugeAmountOfGas, ByteUtil.byteArrayToLong(callArgumentsToByteArray.getGasLimit()));
    Assert.assertEquals(gasEstimationCap, ByteUtil.byteArrayToLong(callArgumentsToByteArray.gasLimitForGasEstimation(gasEstimationCap)));
}
Also used : CallArguments(org.ethereum.rpc.CallArguments) Test(org.junit.Test)

Example 20 with CallArguments

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

the class CallArgumentsToByteArrayTest method getValueWhenValueIsEmpty.

@Test
public void getValueWhenValueIsEmpty() throws Exception {
    CallArguments args = new CallArguments();
    args.setValue("");
    CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args);
    Assert.assertArrayEquals(new byte[] { 0 }, byteArrayArgs.getValue());
}
Also used : CallArguments(org.ethereum.rpc.CallArguments) 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