use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method testRemove2.
@Test
public void testRemove2() {
List<PooledTransaction> txs = new ArrayList<>();
for (int i = 0; i < 95; 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, 26));
assertEquals(26, tp.snapshot().size());
assertEquals(26, tp.snapshotAll().size());
tp.remove(txs.subList(0, 13));
assertEquals(13, tp.snapshot().size());
assertEquals(13, tp.snapshotAll().size());
tp.add(txs.subList(26, 70));
assertEquals(57, tp.snapshot().size());
assertEquals(57, tp.snapshotAll().size());
tp.remove(txs.subList(13, 40));
assertEquals(30, tp.snapshot().size());
assertEquals(30, tp.snapshotAll().size());
// assume we don't remove tx 40
tp.remove(txs.subList(41, 70));
assertEquals(1, tp.snapshot().size());
assertEquals(1, tp.snapshotAll().size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot8.
@Test
public void snapshot8() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
Map<ByteArrayWrapper, PooledTransaction> txMap = new HashMap<>();
int cnt = 16;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransaction(nonce, 0);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransaction(nonce, 1);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
for (int i = 16; i < 16 + cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransaction(nonce, 0);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
for (int i = 16; i < 16 + cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransaction(nonce, 1);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt * 4);
// sort the inserted txs
List<AionTransaction> snapshot = tp.snapshot();
Assert.assertEquals(tp.size(), snapshot.size());
Assert.assertEquals(tp.snapshotAll().size(), snapshot.size());
for (AionTransaction tx : snapshot) {
assertTrue(txMap.containsKey(ByteArrayWrapper.wrap(tx.getTransactionHash())));
Assert.assertEquals(txMap.get(ByteArrayWrapper.wrap(tx.getTransactionHash())).tx, tx);
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method isFullTest.
@Test
public void isFullTest() {
List<PooledTransaction> txs = new ArrayList<>();
for (int i = 0; i < Constant.TXPOOL_SIZE_MIN; 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);
assertThat(tp.isFull()).isFalse();
tp.add(txs);
assertThat(tp.isFull()).isTrue();
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method remove4.
@Test
public void remove4() {
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(), 5000L);
txl.add(tx);
}
List<PooledTransaction> rtn = txPool.add(txl);
Assert.assertEquals(rtn.size(), txl.size());
List<AionTransaction> snapshot = txPool.snapshot();
Assert.assertEquals(snapshot.size(), cnt);
// We will remove the tx with nonce 10, which should only remove the given tx
PooledTransaction txWithNonceTen = txl.get(10);
PooledTransaction removed = txPool.remove(txWithNonceTen);
assertEquals(txWithNonceTen, removed);
assertEquals(19, txPool.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot2.
@Test
public void snapshot2() {
Properties config = new Properties();
// 100 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txl = new ArrayList<>();
int cnt = 26;
for (int i = 0; i < cnt; i++) {
PooledTransaction txe = genTransaction(BigInteger.valueOf(i).toByteArray(), 5000L);
txl.add(txe);
}
List<PooledTransaction> rtn = tp.add(txl);
Assert.assertEquals(rtn.size(), txl.size());
List<AionTransaction> snapshot = tp.snapshot();
Assert.assertEquals(snapshot.size(), cnt);
}
Aggregations