use of org.aion.types.InternalTransaction in project aion by aionnetwork.
the class OpcodeIntegTest method testCallcodeActors.
@Test
public void testCallcodeActors() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO);
AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO);
// Deployer calls contract D which performs CALLCODE to call contract E. From the
// perspective
// of the internal transaction, however, it looks like D calls D.
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.TWO;
byte[] input = // use CALLCODE on E.
ByteUtil.merge(Hex.decode("5cce9fc2"), E.toByteArray());
// pass in 'n' also.
input = ByteUtil.merge(input, new DataWord(0).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
assertEquals(deployer, tx.getSenderAddress());
assertEquals(D, tx.getDestinationAddress());
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// We expect that the internal transaction is sent from D to D.
List<InternalTransaction> internalTxs = summary.getInternalTransactions();
assertEquals(1, internalTxs.size());
assertEquals(D, internalTxs.get(0).sender);
assertEquals(D, internalTxs.get(0).destination);
}
use of org.aion.types.InternalTransaction in project aion by aionnetwork.
the class OpcodeIntegTest method testDelegateCallActors.
@Test
public void testDelegateCallActors() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO);
AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO);
BigInteger n = new BigInteger("23786523");
// Deployer calls contract D which performs DELEGATECALL to call contract E.
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger value = new BigInteger("4364463");
BigInteger nonce = BigInteger.TWO;
byte[] input = // use DELEGATECALL on E.
ByteUtil.merge(Hex.decode("32817e1d"), E.toByteArray());
// pass in 'n' also.
input = ByteUtil.merge(input, new DataWord(n).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, value.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
assertEquals(deployer, tx.getSenderAddress());
assertEquals(D, tx.getDestinationAddress());
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// We expect there to be one internal transaction and it should look like deployer sent to
// D.
List<InternalTransaction> internalTxs = summary.getInternalTransactions();
assertEquals(1, internalTxs.size());
assertEquals(deployer, internalTxs.get(0).sender);
assertEquals(D, internalTxs.get(0).destination);
}
use of org.aion.types.InternalTransaction in project aion by aionnetwork.
the class InternalTransactionTest method testNestedCreateWithExistedAccount.
@Test
public void testNestedCreateWithExistedAccount() throws Exception {
String contractA = "0x60506040523415600f5760006000fd5b5b60166048565b604051809103906000f0801582151615602f5760006000fd5b60006000508282909180600101839055555050505b6057565b604051605a8061009f83390190565b603a806100656000396000f30060506040526008565b60006000fd00a165627a7a72305820c0eea40d4778b01848164e58898e9e8c8ab068ed5ee36ed6f0582d119ecbbede002960506040523415600f5760006000fd5b6013565b603a8060206000396000f30060506040526008565b60006000fd00a165627a7a723058208c13bc92baf844f8574632dca44c49776516cb6cd537b10ed700bf61392b6ae80029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
AionAddress firstContractAddr = TxUtil.calculateContractAddress(deployerAccount.getAddress(), BigInteger.ONE);
AionAddress internalContractAddress = TxUtil.calculateContractAddress(firstContractAddr.toByteArray(), BigInteger.ZERO);
BigInteger nonce = BigInteger.ZERO;
// ======================
// Transfer balance to the internal contract address
// ======================
AionTransaction tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), internalContractAddress, BigInteger.ONE.toByteArray(), new byte[0], 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
Block parentBlock = bc.getBestBlock();
MiningBlock newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(1000);
// ======================
// DEPLOY Failed
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
parentBlock = bc.getBestBlock();
newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
assertEquals("reverted", result.getRight().getReceipts().get(0).getError());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(0);
// ======================
// DEPLOY
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
System.out.println("contractaddr: " + TxUtil.calculateContractAddress(tx));
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx), false);
AionTxExecSummary summary = executeTransaction(bc, context, tx);
System.out.println(summary.getReceipt());
boolean firstItx = true;
for (InternalTransaction itx : summary.getInternalTransactions()) {
System.out.println(itx);
if (firstItx) {
AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
assertNotNull(contractAddress);
assertTrue(bc.getRepository().hasAccountState(contractAddress));
assertTrue(bc.getRepository().hasAccountState(TxUtil.calculateContractAddress(contractAddress.toByteArray(), BigInteger.ZERO)));
firstItx = false;
}
}
}
use of org.aion.types.InternalTransaction in project aion by aionnetwork.
the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnSuccess.
@Test
public void testLogAndInternalTransactionsOnSuccess() {
AvmVersion version = AvmVersion.VERSION_1;
AionAddress contract = deployContract(version, BigInteger.ZERO);
AionAddress other = deployContract(version, BigInteger.ONE);
Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsOnSuccess");
AionBlockSummary summary = connectResult.getRight();
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
AionTxReceipt receipt = summary.getReceipts().get(0);
assertTrue(receipt.isSuccessful());
List<Log> logs = receipt.getLogInfoList();
List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
assertEquals(3, logs.size());
assertEquals(1, internalTransactions.size());
}
use of org.aion.types.InternalTransaction in project aion by aionnetwork.
the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnFailure.
@Test
public void testLogAndInternalTransactionsOnFailure() {
AvmVersion version = AvmVersion.VERSION_1;
AionAddress contract = deployContract(version, BigInteger.ZERO);
AionAddress other = deployContract(version, BigInteger.ONE);
Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsAndFail");
AionBlockSummary summary = connectResult.getRight();
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
AionTxReceipt receipt = summary.getReceipts().get(0);
assertFalse(receipt.isSuccessful());
List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
List<Log> logs = receipt.getLogInfoList();
assertEquals(0, logs.size());
assertEquals(1, internalTransactions.size());
}
Aggregations