use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method snapshot6.
@Test
public void snapshot6() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 200;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
PooledTransaction txn = genTransactionRandomPrice(nonce, key.get(0), Constant.MIN_ENERGY_CONSUME + r.nextInt(1000));
txnl.add(txn);
}
tp.add(txnl);
Assert.assertEquals(cnt, tp.size());
List<AionTransaction> txl = tp.snapshot();
List<AionTransaction> allSnapshotTx = new ArrayList<>(txl);
while (!txl.isEmpty() && cnt-- != 0) {
List<PooledTransaction> transactions = new ArrayList<>();
for (AionTransaction tx : txl) {
transactions.add(new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME));
}
List<PooledTransaction> pTxs = tp.remove(transactions);
Assert.assertEquals(transactions.size(), pTxs.size());
txl = tp.snapshot();
allSnapshotTx.addAll(txl);
}
Assert.assertEquals(0, tp.size());
long nonce = 0;
for (AionTransaction tx : allSnapshotTx) {
Assert.assertEquals(tx.getNonceBI().longValue(), nonce++);
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method add3.
@Test(expected = NullPointerException.class)
public void add3() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txl = null;
tp.add(txl);
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method noncebyAccountTest.
@Test
public void noncebyAccountTest() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
AionAddress acc = new AionAddress(key.get(0).getAddress());
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 + 1);
AionTransaction txn = AionTransaction.create(key.get(0), nonce, AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, 1L, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, Constant.MIN_ENERGY_CONSUME + 100);
txnl.add(pooledTx);
}
tp.add(txnl);
Assert.assertEquals(tp.size(), cnt);
// sort the inserted txs
tp.snapshot();
List<BigInteger> nl = tp.getNonceList(acc);
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(nl.get(i), BigInteger.valueOf(i + 1));
}
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method add1.
@Test
public void add1() {
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());
}
use of org.aion.base.PooledTransaction in project aion by aionnetwork.
the class TxPoolV1Test method feemapTest.
@Test
public void feemapTest() {
Properties config = new Properties();
config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
TxPoolV1 tp = new TxPoolV1(config);
List<PooledTransaction> txnl = new ArrayList<>();
int cnt = 10;
byte[] nonce = new byte[Long.BYTES];
for (int i = 0; i < cnt; i++) {
nonce[Long.BYTES - 1] = (byte) i;
AionTransaction txn = AionTransaction.create(key2.get(i), nonce, AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), Constant.MIN_ENERGY_CONSUME, i + 1, TransactionTypes.DEFAULT, null);
PooledTransaction pooledTx = new PooledTransaction(txn, i + Constant.MIN_ENERGY_CONSUME + 1);
txnl.add(pooledTx);
}
tp.add(txnl);
Assert.assertEquals(cnt, tp.size());
List<AionTransaction> txSnapshot = tp.snapshot();
assertEquals(cnt, txSnapshot.size());
List<Long> nl = tp.getFeeList();
assertEquals(cnt, nl.size());
long val = 10;
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(0, nl.get(i).compareTo(val--));
}
}
Aggregations