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));
}
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;
}
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();
}
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;
}
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);
}
Aggregations