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