use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot7.
@Test
public void snapshot7() {
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 = 25;
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);
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt);
List<PooledTransaction> txnl2 = new ArrayList<>();
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTxn = genTransaction(nonce, 1);
txnl2.add(pooledTxn);
txMap.put(ByteArrayWrapper.wrap(pooledTxn.tx.getTransactionHash()), pooledTxn);
}
tp.add(txnl2);
Assert.assertEquals(tp.size(), cnt * 2);
// 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 timeout1.
@Test
public void timeout1() {
Properties config = new Properties();
// 10 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = getMockTransaction(30000L);
tp.add(txnl);
tp.snapshot(TimeUnit.MICROSECONDS.toSeconds(txnl.get(0).tx.getTimeStampBI().longValue()) + 10);
Assert.assertEquals(1, tp.size());
tp.snapshot(TimeUnit.MICROSECONDS.toSeconds(txnl.get(0).tx.getTimeStampBI().longValue()) + 11);
Assert.assertEquals(0, tp.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method remove2.
@Test
public void remove2() {
Properties config = new Properties();
// 100 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txl = new ArrayList<>();
List<PooledTransaction> txlrm = 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);
if (i < 10) {
txlrm.add(tx);
}
}
List<PooledTransaction> rtn = tp.add(txl);
Assert.assertEquals(rtn.size(), txl.size());
List<AionTransaction> snapshot = tp.snapshot();
Assert.assertEquals(snapshot.size(), cnt);
rtn = tp.remove(txlrm);
Assert.assertEquals(10, rtn.size());
Assert.assertEquals(10, tp.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method updatePoolTransactionTest.
@Test
public void updatePoolTransactionTest() {
List<PooledTransaction> txs = new ArrayList<>();
AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(0).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);
PooledTransaction pTx = tp.add(txs).get(0);
assertNotNull(pTx);
assertEquals(tx, pTx.tx);
PooledTransaction newPtx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME + 1);
tp.updatePoolTransaction(newPtx);
PooledTransaction ptx = tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO);
assertNotNull(ptx);
assertEquals(newPtx, ptx);
assertEquals(tx, ptx.tx);
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method getDroppedTxTest.
@Test
public void getDroppedTxTest() {
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> txs = new ArrayList<>();
AionTransaction tx = AionTransaction.create(key.get(0), BigInteger.valueOf(0).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);
PooledTransaction pTx = tp.add(txs).get(0);
assertNotNull(pTx);
AionTransaction tx2 = AionTransaction.create(key.get(0), BigInteger.valueOf(0).toByteArray(), AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 2L, TransactionTypes.DEFAULT, null);
PooledTransaction newPtx = new PooledTransaction(tx2, Constant.MIN_ENERGY_CONSUME + 1);
PooledTransaction ptx = tp.add(newPtx);
assertEquals(newPtx, ptx);
PooledTransaction drppedPtx = tp.getDroppedPoolTx();
assertNotNull(drppedPtx);
assertEquals(pooledTx, drppedPtx);
}
Aggregations