use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method addRepeatedTxn.
@Test
public void addRepeatedTxn() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
AionTransaction txn = AionTransaction.create(key.get(0), ByteUtils.fromHexString("0000000000000001"), new AionAddress(key.get(0).getAddress()), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, 0);
List<PooledTransaction> txnl = new ArrayList<>();
txnl.add(pooledTx);
txnl.add(pooledTx);
tp.add(txnl);
Assert.assertEquals(1, tp.size());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot3.
@Test
public void snapshot3() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 26;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction txn = genTransaction(nonce, i + Constant.MIN_ENERGY_CONSUME);
txnl.add(txn);
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt);
// sort the inserted txs
List<AionTransaction> snapshot = tp.snapshot();
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 snapshotWithSameTransactionTimestamp.
@Test
public void snapshotWithSameTransactionTimestamp() {
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<>();
byte[] timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
final int cnt = 16;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransactionWithTimestamp(nonce, key.get(0), timeStamp);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransactionWithTimestamp(nonce, key.get(1), timeStamp);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
for (int i = cnt; i < 2 * cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransactionWithTimestamp(nonce, key.get(0), timeStamp);
txnl.add(pooledTx);
txMap.put(ByteArrayWrapper.wrap(pooledTx.tx.getTransactionHash()), pooledTx);
}
timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
for (int i = cnt; i < 2 * cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction pooledTx = genTransactionWithTimestamp(nonce, key.get(1), timeStamp);
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> txl = tp.snapshot();
Assert.assertEquals(tp.size(), txl.size());
Assert.assertEquals(tp.snapshotAll().size(), txl.size());
for (AionTransaction tx : txl) {
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 clearOutDateTransactionTest.
@Test
public void clearOutDateTransactionTest() {
Properties config = new Properties();
// 10 sec
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txl = new ArrayList<>();
int cnt = 2;
for (int i = 0; i < cnt; i++) {
PooledTransaction tx = genTransaction(BigInteger.valueOf(i).toByteArray(), Constant.MIN_ENERGY_CONSUME);
txl.add(tx);
}
tp.add(txl);
tp.clearOutDateTransaction(TimeUnit.MICROSECONDS.toSeconds(txl.get(0).tx.getTimeStampBI().longValue()) + 10);
Assert.assertEquals(cnt, tp.size());
tp.clearOutDateTransaction(TimeUnit.MICROSECONDS.toSeconds(txl.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 getPoolTxTest.
@Test
public void getPoolTxTest() {
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);
List<PooledTransaction> pooledTransactions = tp.add(txs);
assertNull(tp.getPoolTx(new AionAddress(key.get(1).getAddress()), BigInteger.ZERO));
assertNull(tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ONE));
PooledTransaction pTx = tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO);
assertNotNull(pTx);
assertEquals(tx, pTx.tx);
}
Aggregations