use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method flushTest2.
@Test
public void flushTest2() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
for (AionTransaction tx : txn) {
cache.addCacheTx(tx);
}
assertTrue(cache.cacheTxSize() == 10);
Map<AionAddress, BigInteger> map = new HashMap<>();
map.put(new AionAddress(key.get(1).getAddress()), BigInteger.TWO);
cache.flush(map);
Map<BigInteger, AionTransaction> cacheMap = cache.getCacheTx(new AionAddress(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 10);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method maxPendingSizeTest6.
@Test
public void maxPendingSizeTest6() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 100, 0);
txn.addAll(getMockTransaction(101, 600, 0));
for (AionTransaction tx : txn) {
cache.addCacheTx(tx);
}
assertTrue(cache.cacheTxSize() == 659);
Map<BigInteger, AionTransaction> cacheMap = cache.getCacheTx(new AionAddress(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 659);
AionTransaction tx = getMockBigTransaction(100, 1, 0, 199_500).get(0);
cache.addCacheTx(tx);
assertTrue(cache.cacheTxSize() == 659);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method addCacheTxTest2.
@Test
public void addCacheTxTest2() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(0, 10, 1));
for (AionTransaction tx : txn) {
cache.addCacheTx(tx);
}
assertTrue(cache.cacheTxSize() == txn.size());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheV1Test method flushTxWith2AccountsTest.
@Test
public void flushTxWith2AccountsTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(0, 10, 1));
for (AionTransaction tx : txn) {
cache.addCacheTx(tx);
}
assertEquals(20, cache.cacheTxSize());
Map<AionAddress, BigInteger> map = new HashMap<>();
map.put(new AionAddress(key.get(0).getAddress()), BigInteger.TWO);
map.put(new AionAddress(key.get(1).getAddress()), BigInteger.ONE);
cache.removeSealedTransactions(map);
List<AionTransaction> cachedTxs = new ArrayList<>(cache.getCacheTxBySender(new AionAddress(key.get(0).getAddress())).values());
assertEquals(8, cachedTxs.size());
cachedTxs = new ArrayList<>(cache.getCacheTxBySender(new AionAddress(key.get(1).getAddress())).values());
assertEquals(9, cachedTxs.size());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingStateTest method replayTransactionThatThatInvalidatesMiddleTx.
@Test
public void replayTransactionThatThatInvalidatesMiddleTx() {
BigInteger balance = blockchain.getRepository().getBalance(new AionAddress(deployerKey.getAddress()));
BigInteger value = balance.subtract(BigInteger.valueOf(21000 * 7).multiply(BigInteger.valueOf(energyPrice)));
AionTransaction tx1 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), value.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
AionTransaction tx2 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
/* tx1 and tx3 should use the entire balance. If tx2 is removed properly, tx3 should be
* able to replace it in the pending state */
AionTransaction tx3 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice * 4, TransactionTypes.DEFAULT, null);
// This would execute fine on top of tx2, but should have insufficient balance on top of tx3
AionTransaction tx4 = AionTransaction.create(deployerKey, BigInteger.TWO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice * 4, TransactionTypes.DEFAULT, null);
AionTransaction tx5 = AionTransaction.create(deployerKey, BigInteger.valueOf(3).toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx1));
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx2));
assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(tx3));
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx4));
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx5));
assertEquals(4, pendingState.getPendingTxSize());
MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), Collections.emptyList(), false);
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
pendingState.applyBlockUpdate(block, connectResult.getRight().getReceipts());
// tx3 should replace tx2, and tx4 will now have insufficient funds so it will get dropped
assertEquals(2, pendingState.getPendingTxSize());
assertEquals(pendingState.getPendingTransactions().get(1), tx3);
}
Aggregations