Search in sources :

Example 16 with AionTxReceipt

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

the class SolidityTypeTest method testBytes2.

@Test
public void testBytes2() throws Exception {
    byte[] x = Hex.decode("11223344556677881122334455667788112233445566778811223344556677881122334455667788");
    SolidityType type = new BytesType();
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("61cb5a01"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertArrayEquals(x, (byte[]) type.decode(receipt.getTransactionOutput(), 16));
}
Also used : RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) SolidityType(org.aion.solidity.SolidityType) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) BytesType(org.aion.solidity.SolidityType.BytesType) Test(org.junit.Test)

Example 17 with AionTxReceipt

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

the class AvmTransactionExecutor method makeReceipt.

/**
 * Constructs a new transaction receipt.
 *
 * @param transaction The transaction.
 * @param logs The logs fired off during execution of the transaction.
 * @param result The transaction result.
 * @param output The transaction output.
 * @return the receipt.
 */
private static AionTxReceipt makeReceipt(AionTransaction transaction, List<Log> logs, TransactionResult result, byte[] output) {
    AionTxReceipt receipt = new AionTxReceipt();
    receipt.setTransaction(transaction);
    receipt.setLogs(logs);
    receipt.setNrgUsed(result.energyUsed);
    receipt.setExecutionResult(output);
    receipt.setError(result.transactionStatus.causeOfError);
    return receipt;
}
Also used : AionTxReceipt(org.aion.base.AionTxReceipt)

Example 18 with AionTxReceipt

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

the class BlockUtil method calcLogBloom.

public static byte[] calcLogBloom(List<AionTxReceipt> receipts) {
    Objects.requireNonNull(receipts);
    if (receipts.isEmpty()) {
        return new byte[Bloom.SIZE];
    }
    Bloom retBloomFilter = new Bloom();
    for (AionTxReceipt receipt : receipts) {
        retBloomFilter.or(receipt.getBloomFilter());
    }
    return retBloomFilter.getBloomFilterBytes();
}
Also used : Bloom(org.aion.base.Bloom) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 19 with AionTxReceipt

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

the class FvmTransactionExecutor method makeReceipt.

private static AionTxReceipt makeReceipt(AionTransaction transaction, List<Log> logs, TransactionResult result) {
    AionTxReceipt receipt = new AionTxReceipt();
    receipt.setTransaction(transaction);
    receipt.setLogs(logs);
    receipt.setNrgUsed(result.energyUsed);
    receipt.setExecutionResult(result.copyOfTransactionOutput().orElse(ByteUtil.EMPTY_BYTE_ARRAY));
    receipt.setError(result.transactionStatus.isSuccess() ? "" : result.transactionStatus.causeOfError);
    return receipt;
}
Also used : AionTxReceipt(org.aion.base.AionTxReceipt)

Example 20 with AionTxReceipt

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

the class AvmBulkTransactionTest method importBlockWithContractAndCallsForBothVMsWhereFVMContractIsEmpty.

/**
 * Ensures that a block containing the transactions described below is processed correctly:
 *
 * <ol>
 *   <li>an empty FVM contract deployment,
 *   <li>an AVM contract deployment,
 *   <li>an FVM call to the first contract,
 *   <li>an AVM call to the second contract.
 * </ol>
 */
@Test
public void importBlockWithContractAndCallsForBothVMsWhereFVMContractIsEmpty() {
    BigInteger expectedNonce = getNonce(deployerKey);
    BigInteger initialBalance = getBalance(deployerKey);
    List<AionTransaction> transactions = new ArrayList<>();
    // Deploy empty FVM contract.
    AionTransaction deployTxFVM = AionTransaction.create(deployerKey, expectedNonce.toByteArray(), null, BigInteger.ZERO.toByteArray(), new byte[0], 5_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
    AionAddress fvmContract = TxUtil.calculateContractAddress(deployTxFVM);
    transactions.add(deployTxFVM);
    expectedNonce = expectedNonce.add(BigInteger.ONE);
    // Deploy AVM contract.
    AionTransaction deployTxAVM = makeAvmContractCreateTransaction(deployerKey, expectedNonce);
    AionAddress avmContract = TxUtil.calculateContractAddress(deployTxAVM);
    transactions.add(deployTxAVM);
    expectedNonce = expectedNonce.add(BigInteger.ONE);
    // Call FVM contract with code data that will be ignored by the VM because the contract has no code.
    AionTransaction contractCallTx = AionTransaction.create(deployerKey, expectedNonce.toByteArray(), fvmContract, BigInteger.ZERO.toByteArray(), Hex.decode("6080608055"), 2_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
    transactions.add(contractCallTx);
    expectedNonce = expectedNonce.add(BigInteger.ONE);
    // Call AVM contract.
    transactions.add(makeAvmContractCallTransaction(deployerKey, expectedNonce, avmContract));
    expectedNonce = expectedNonce.add(BigInteger.ONE);
    // Process the 4 transactions in a single block.
    AionBlockSummary blockSummary = sendTransactionsInBulkInSingleBlock(transactions);
    // Verify that all transactions were successful.
    assertThat(blockSummary.getSummaries().size()).isEqualTo(4);
    BigInteger expectedBalance = initialBalance;
    for (AionTxExecSummary transactionSummary : blockSummary.getSummaries()) {
        AionTxReceipt receipt = transactionSummary.getReceipt();
        assertThat(receipt.isSuccessful()).isTrue();
        // Compute the expected balance.
        expectedBalance = expectedBalance.subtract(BigInteger.valueOf(receipt.getEnergyUsed()).multiply(BigInteger.valueOf(energyPrice)));
    }
    // Verify that the code and storage of the FVM contract are unchanged.
    AccountState fvm = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
    assertThat(fvm.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
    assertThat(fvm.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
    assertThat(getBalance(deployerKey)).isEqualTo(expectedBalance);
    assertThat(getNonce(deployerKey)).isEqualTo(expectedNonce);
}
Also used : AionAddress(org.aion.types.AionAddress) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt) AccountState(org.aion.base.AccountState) 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