use of org.aion.base.AionTxExecSummary 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.base.AionTxExecSummary in project aion by aionnetwork.
the class InternalTransactionTest method executeTransaction.
private AionTxExecSummary executeTransaction(StandaloneBlockchain bc, BlockContext context, AionTransaction transaction) throws VmFatalException {
RepositoryCache cache = bc.getRepository().startTracking();
MiningBlock block = context.block;
AionTxExecSummary summary = BulkExecutor.executeTransactionWithNoPostExecutionWork(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), transaction, cache, false, true, false, false, LOGGER_VM, BlockCachingContext.PENDING, block.getNumber() - 1, false, false);
cache.flushTo(bc.getRepository(), true);
return summary;
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class Benchmark method verifyState.
private static void verifyState() throws VmFatalException {
long ownerNonce = repo.getNonce(owner).longValue();
for (int i = 0; i < recipients.size(); i++) {
byte[] nonce = BigInteger.valueOf(ownerNonce + i).toByteArray();
AionAddress to = contract;
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = ByteUtil.merge(Hex.decode("70a08231" + "000000000000000000000000"), recipients.get(i));
long nrg = 1_000_000L;
long nrgPrice = 10_000_000_000L;
AionTransaction tx = AionTransaction.create(key, nonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
AionTxExecSummary summary = executeTransaction(tx);
assertFalse(summary.isFailed());
assertEquals(1, new DataWord(summary.getReceipt().getTransactionOutput()).longValue());
}
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class Benchmark method executeTransactions.
private static List<AionTxReceipt> executeTransactions(List<AionTransaction> txs) throws VmFatalException {
long t1 = System.currentTimeMillis();
List<AionTxReceipt> list = new ArrayList<>();
for (AionTransaction tx : txs) {
AionTxExecSummary summary = executeTransaction(tx);
assertFalse(summary.isFailed());
list.add(summary.getReceipt());
}
long t2 = System.currentTimeMillis();
timeExecuteTransactions = t2 - t1;
return list;
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method deployContract.
private AionAddress deployContract(RepositoryCache repo, AionTransaction tx, String contractName, String contractFilename, BigInteger value, long nrg, long nrgPrice, BigInteger nonce, boolean addToBlockChain) throws IOException, VmFatalException {
assertTrue(tx.isContractCreationTransaction());
assertEquals(deployerBalance, repo.getBalance(deployer));
assertEquals(deployerNonce, repo.getNonce(deployer));
MiningBlock block = makeBlock(tx);
AionTxExecSummary summary = executeTransaction(tx, block, repo);
if (!summary.getReceipt().getError().equals("")) {
return null;
}
assertNotEquals(nrg, summary.getNrgUsed().longValue());
AionAddress contract = TxUtil.calculateContractAddress(tx);
if (contractFilename == null) {
checkStateOfNewContract(repo, contractName, contract, summary.getResult(), FastVmResultCode.SUCCESS, value);
} else {
checkStateOfNewContract(repo, contractName, contractFilename, contract, summary.getResult(), FastVmResultCode.SUCCESS, value);
}
checkStateOfDeployer(repo, summary, nrgPrice, value, nonce);
if (addToBlockChain) {
Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
assertTrue(result.getLeft().isSuccessful());
}
return contract;
}
Aggregations