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