use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferAfterCreatingContractToPayableFunction.
@Test
public void testTransferAfterCreatingContractToPayableFunction() {
BigInteger amount = BigInteger.TEN.pow(17).add(BigInteger.valueOf(38_193));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create transaction.
AionTransaction transaction = makeCreatePayableContractTx();
AionAddress contractAddress = TxUtil.calculateContractAddress(transaction);
assertArrayEquals(Hex.decode(CONTRACT), contractAddress.toByteArray());
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT3), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT3), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE3), receiptTrieEncoded);
// Make the balance transfer transaction.
transaction = makeCallPayableFunctionTx(contractAddress, amount);
// Process the transaction.
results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
blockSummary = results.getRight();
receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
stateRoot = blockSummary.getBlock().getStateRoot();
blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT5), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT5), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE5), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("999999897458394815058678");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
assertEquals(amount, getBalance(contractAddress));
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("1500539557347676526");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferAfterCreatingContractToNonPayableFunction.
@Test
public void testTransferAfterCreatingContractToNonPayableFunction() {
BigInteger amount = BigInteger.TEN.pow(9).add(BigInteger.valueOf(3_124_587));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create transaction.
AionTransaction transaction = makeCreatePayableContractTx();
AionAddress contractAddress = TxUtil.calculateContractAddress(transaction);
assertArrayEquals(Hex.decode(CONTRACT), contractAddress.toByteArray());
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT3), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT3), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE3), receiptTrieEncoded);
// Make the balance transfer transaction.
transaction = makeCallNonpayableFunctionTx(contractAddress, amount);
// Process the transaction.
results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
blockSummary = results.getRight();
receipt = blockSummary.getSummaries().get(0).getReceipt();
assertFalse(receipt.isSuccessful());
stateRoot = blockSummary.getBlock().getStateRoot();
blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT4), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT4), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE4), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("999999997458455555837605");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
assertEquals(BigInteger.ZERO, getBalance(contractAddress));
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("1500539496606935792");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AionPendingStateImpl method clearPending.
private void clearPending(Block block, List<AionTxReceipt> receipts) {
List<AionTransaction> txList = block.getTransactionsList();
LOGGER_TX.info("clearPending block#[{}] tx#[{}]", block.getNumber(), txList.size());
if (!txList.isEmpty()) {
Map<AionAddress, BigInteger> accountNonce = new HashMap<>();
int cnt = 0;
for (AionTransaction tx : txList) {
accountNonce.computeIfAbsent(tx.getSenderAddress(), this::bestRepoNonce);
LOGGER_TX.debug("Clear pending transaction, addr: {} hash: {}", tx.getSenderAddress().toString(), Hex.toHexString(tx.getTransactionHash()));
AionTxReceipt receipt = null;
if (receipts != null) {
receipt = receipts.get(cnt);
} else {
AionTxInfo info = getTransactionInfo(tx.getTransactionHash(), block.getHash());
if (info != null) {
receipt = info.getReceipt();
}
}
removeBackupDBPendingTx(tx.getTransactionHash());
if (receipt != null) {
fireTxUpdate(receipt, PendingTransactionState.INCLUDED, block);
}
cnt++;
}
if (!accountNonce.isEmpty()) {
txPool.removeTxsWithNonceLessThan(accountNonce);
}
}
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AionPendingStateImpl method updateCachedTxToTxPool.
private void updateCachedTxToTxPool(Map<AionAddress, BigInteger> nonceMap) {
List<AionTransaction> newPendingTransactions = pendingTxCache.getNewPendingTransactions(nonceMap);
LOGGER_TX.debug("flushCachedTx - newPendingTxs#[{}]", newPendingTransactions.size());
Set<AionAddress> updatedAddress = new HashSet<>();
for (AionTransaction tx : newPendingTransactions) {
if (txPool.isFull()) {
LOGGER_TX.debug("flushCachedTx txPool is full, cannot add new pending transactions from the cachedPool");
break;
}
LOGGER_TX.debug("flushCachedTx - loop: {}", tx);
AionTxExecSummary txSum = executeTx(tx);
AionTxReceipt receipt = txSum.getReceipt();
receipt.setTransaction(tx);
if (txSum.isRejected()) {
LOGGER_TX.debug("Invalid transaction in cachedPool: {}", tx);
fireTxUpdate(receipt, PendingTransactionState.DROPPED, currentBestBlock.get());
pendingTxCache.removeTransaction(tx.getSenderAddress(), tx.getNonceBI());
} else {
PooledTransaction pTx = txPool.add(new PooledTransaction(tx, receipt.getEnergyUsed()));
if (pTx != null) {
fireTxUpdate(receipt, PendingTransactionState.PENDING, currentBestBlock.get());
updatedAddress.add(tx.getSenderAddress());
pendingTxCache.removeTransaction(tx.getSenderAddress(), tx.getNonceBI());
}
}
}
for (AionAddress addr : updatedAddress) {
nonceMap.put(addr, bestPendingStateNonce(addr));
}
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AionPendingStateImpl method fireDroppedTx.
private void fireDroppedTx(AionTransaction tx, String error) {
AionTxReceipt rp = new AionTxReceipt();
rp.setTransaction(tx);
rp.setError(error);
fireTxUpdate(rp, PendingTransactionState.DROPPED, currentBestBlock.get());
}
Aggregations