use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot5.
@Test
public void snapshot5() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 100;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction txn = genTransaction(nonce, Constant.MIN_ENERGY_CONSUME + r.nextInt(1000));
txnl.add(txn);
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt);
// sort the inserted txs
List<AionTransaction> snapshot = tp.snapshot();
Assert.assertEquals(tp.size(), snapshot.size());
Assert.assertEquals(tp.snapshotAll().size(), snapshot.size());
long nonce = 0;
for (AionTransaction tx : snapshot) {
Assert.assertEquals(tx.getNonceBI().longValue(), nonce++);
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method remove.
@Test
public void remove() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = getMockTransaction(0);
tp.add(txnl);
Assert.assertEquals(1, tp.size());
tp.remove(txnl);
Assert.assertEquals(0, tp.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method poolFullTest.
@Test
public void poolFullTest() {
List<PooledTransaction> txs = new ArrayList<>();
for (int i = 0; i < Constant.TXPOOL_SIZE_MIN + 1; i++) {
AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
txs.add(pooledTx);
}
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> pooledTransactions = tp.add(txs);
assertThat(tp.isFull()).isTrue();
assertEquals(Constant.TXPOOL_SIZE_MIN, pooledTransactions.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method remove3.
@Test
public void remove3() {
Properties config = new Properties();
// 100 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 txPool = new TxPoolV1(config);
List<PooledTransaction> txl = new ArrayList<>();
int cnt = 20;
for (int i = 0; i < cnt; i++) {
PooledTransaction tx = genTransaction(BigInteger.valueOf(i).toByteArray(), Constant.MIN_ENERGY_CONSUME);
txl.add(tx);
}
List<PooledTransaction> added = txPool.add(txl);
Assert.assertEquals(added.size(), txl.size());
List<AionTransaction> snapshot = txPool.snapshot();
Assert.assertEquals(snapshot.size(), cnt);
// We pass nonce 11 to the remove function, which should also remove any tx from the same
// sender with a lower nonce
Map<AionAddress, BigInteger> txWithNonceEleven = new HashMap<>();
txWithNonceEleven.put(snapshot.get(0).getSenderAddress(), BigInteger.valueOf(11));
List<PooledTransaction> removed = txPool.removeTxsWithNonceLessThan(txWithNonceEleven);
assertEquals(11, removed.size());
assertEquals(9, txPool.size());
assertEquals(txPool.snapshot().get(0), txl.get(11).tx);
assertEquals(txPool.snapshot().get(0).getNonceBI(), BigInteger.valueOf(11));
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method testSnapshotAll2.
@Test
public void testSnapshotAll2() {
List<PooledTransaction> txs = new ArrayList<>();
for (int i = 0; i < 17; i++) {
AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
txs.add(pooledTx);
}
Properties config = new Properties();
TxPoolV1 tp = new TxPoolV1(config);
tp.add(txs.subList(0, 17));
assertEquals(17, tp.snapshot().size());
assertEquals(17, tp.snapshotAll().size());
}
Aggregations