Search in sources :

Example 16 with AionTxExecSummary

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;
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) InternalTransaction(org.aion.types.InternalTransaction) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) BigInteger(java.math.BigInteger) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 17 with AionTxExecSummary

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;
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 18 with AionTxExecSummary

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());
    }
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) AionTransaction(org.aion.base.AionTransaction) DataWord(org.aion.util.types.DataWord)

Example 19 with AionTxExecSummary

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;
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 20 with AionTxExecSummary

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;
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTxExecSummary(org.aion.base.AionTxExecSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Aggregations

AionTxExecSummary (org.aion.base.AionTxExecSummary)121 AionTransaction (org.aion.base.AionTransaction)103 AionAddress (org.aion.types.AionAddress)98 Test (org.junit.Test)97 RepositoryCache (org.aion.base.db.RepositoryCache)72 BigInteger (java.math.BigInteger)66 AccountState (org.aion.base.AccountState)37 ImportResult (org.aion.zero.impl.core.ImportResult)31 MiningBlock (org.aion.zero.impl.types.MiningBlock)26 ArrayList (java.util.ArrayList)22 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)22 InternalTransaction (org.aion.types.InternalTransaction)20 Block (org.aion.zero.impl.types.Block)20 BlockContext (org.aion.zero.impl.types.BlockContext)19 DataWord (org.aion.util.types.DataWord)18 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)18 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 Bloom (org.aion.base.Bloom)5 ECKey (org.aion.crypto.ECKey)5