use of org.aion.zero.impl.core.ImportResult 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.zero.impl.core.ImportResult 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());
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class AvmInternalTxTest method makeCall.
private void makeCall(BigInteger nonce, AionAddress contract, byte[] call) {
AionTransaction transaction = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, new byte[0], call, 2_000_000, minEnergyPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false);
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
// Check the block was imported and the transaction was successful.
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
assertThat(receipt.isSuccessful()).isTrue();
System.out.println(block);
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class AvmBulkTransactionTest method sendTransactionsInBulkInSingleBlock.
private AionBlockSummary sendTransactionsInBulkInSingleBlock(List<AionTransaction> transactions) {
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, transactions, false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
return connectResult.getRight();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class AionBlockchainImpl method tryToConnect.
/**
* Imports a batch of blocks.
*
* @param blockRange the block range to be imported
* @param peerDisplayId the display identifier for the peer who provided the batch
* @return a {@link Triple} containing:
* <ol>
* <li>the best block height after the imports,</li>
* <li>the set of imported hashes,</li>
* <li>the import result for the last imported block</li>
* </ol>
*/
public Triple<Long, Set<ByteArrayWrapper>, ImportResult> tryToConnect(final List<Block> blockRange, String peerDisplayId) {
lock.lock();
try {
ImportResult importResult = null;
Set<ByteArrayWrapper> imported = new HashSet<>();
for (Block block : blockRange) {
Pair<ImportResult, Long> result = tryToConnectWithTimedExecution(new BlockWrapper(block));
importResult = result.getLeft();
long importTime = result.getRight();
// printing additional information when debug is enabled
SYNC_LOG.debug("<import-status: node = {}, hash = {}, number = {}, txs = {}, block time = {}, result = {}, time elapsed = {} ns, block td = {}, chain td = {}>", peerDisplayId, block.getShortHash(), block.getNumber(), block.getTransactionsList().size(), block.getTimestamp(), importResult, importTime, block.getTotalDifficulty(), getTotalDifficulty());
if (checkKernelShutdownForCLI()) {
break;
} else if (!importResult.isStored()) {
// stop at invalid blocks
return Triple.of(bestBlock.getNumber(), imported, importResult);
} else {
imported.add(block.getHashWrapper());
}
}
return Triple.of(bestBlock.getNumber(), imported, importResult);
} finally {
lock.unlock();
checkKernelExit();
}
}
Aggregations