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);
}
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());
}
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())));
}
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)));
}
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());
}
Aggregations