Search in sources :

Example 6 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class ApiAion method estimateNrg.

protected long estimateNrg(ArgTxCall params) {
    AionAddress fromAddr = (params.getFrom() == null) ? AddressUtils.ZERO_ADDRESS : params.getFrom();
    AionTransaction tx = AionTransaction.createWithoutKey(params.getNonce().toByteArray(), fromAddr, params.getTo(), params.getValue().toByteArray(), params.getData(), params.getNrg(), params.getNrgPrice(), params.getType(), null);
    AionTxReceipt receipt = this.ac.callConstant(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
    return receipt.getEnergyUsed();
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 7 with AionTxReceipt

use of org.aion.base.AionTxReceipt 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 8 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class AvmHelloWorldTest method testDeployAndCallContractInTheSameBlock.

@Test
public void testDeployAndCallContractInTheSameBlock() {
    TransactionTypeRule.allowAVMContractTransaction();
    // Deploy the contract.
    byte[] jar = getJarBytes(AvmVersion.VERSION_1);
    AionTransaction transaction = AionTransaction.create(deployerKey, new byte[0], null, new byte[0], jar, 5_000_000, energyPrice, TransactionTypes.AVM_CREATE_CODE, null);
    List<AionTransaction> ls = new ArrayList<>();
    ls.add(transaction);
    byte[] call = getCallArguments(AvmVersion.VERSION_1);
    AionTransaction transaction2 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), TxUtil.calculateContractAddress(transaction), new byte[0], call, 2_000_000, energyPrice, TransactionTypes.DEFAULT, null);
    ls.add(transaction2);
    MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), ls, false);
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    assertThat(connectResult.getRight().getReceipts().size() == 2);
    // Check the block was imported, the contract has the Avm prefix, and deployment succeeded.
    AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
    assertThat(receipt.getTransactionOutput()[0]).isEqualTo(AddressSpecs.A0_IDENTIFIER);
    assertThat(receipt.isSuccessful()).isTrue();
    // Check the call success
    receipt = connectResult.getRight().getReceipts().get(1);
    assertThat(receipt.isSuccessful()).isTrue();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 9 with AionTxReceipt

use of org.aion.base.AionTxReceipt 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());
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) AionTxReceipt(org.aion.base.AionTxReceipt) InternalTransaction(org.aion.types.InternalTransaction) AvmVersion(org.aion.avm.stub.AvmVersion) Test(org.junit.Test)

Example 10 with AionTxReceipt

use of org.aion.base.AionTxReceipt 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());
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) AionTxReceipt(org.aion.base.AionTxReceipt) InternalTransaction(org.aion.types.InternalTransaction) AvmVersion(org.aion.avm.stub.AvmVersion) Test(org.junit.Test)

Aggregations

AionTxReceipt (org.aion.base.AionTxReceipt)111 Test (org.junit.Test)76 AionTransaction (org.aion.base.AionTransaction)74 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)61 AionAddress (org.aion.types.AionAddress)56 BigInteger (java.math.BigInteger)53 ImportResult (org.aion.zero.impl.core.ImportResult)50 MiningBlock (org.aion.zero.impl.types.MiningBlock)43 ArrayList (java.util.ArrayList)24 Block (org.aion.zero.impl.types.Block)24 AionTxExecSummary (org.aion.base.AionTxExecSummary)17 RepositoryCache (org.aion.base.db.RepositoryCache)17 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)15 Builder (org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder)14 ECKey (org.aion.crypto.ECKey)12 SolidityType (org.aion.solidity.SolidityType)10 AccountState (org.aion.base.AccountState)9 Log (org.aion.types.Log)9 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)7 StakingBlock (org.aion.zero.impl.types.StakingBlock)7