use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.
the class TxnPoolTest method snapshot2.
@Test
public void snapshot2() throws Throwable {
Properties config = new Properties();
// 100 sec
config.put("txn-timeout", "100");
ITxPool<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txl = new ArrayList<>();
int cnt = 26;
for (int i = 0; i < cnt; i++) {
AionTransaction txe = (AionTransaction) genTransaction(BigInteger.valueOf(i).toByteArray());
txe.setNrgConsume(5000L);
txe.sign(key.get(0));
txl.add(txe);
}
List rtn = tp.add(txl);
assertTrue(rtn.size() == txl.size());
txl = tp.snapshot();
assertTrue(txl.size() == cnt);
}
use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.
the class TxnPoolTest method benchmarkSnapshot5.
@Test
public /* 100K new transactions in pool around 350ms (cold-call)
the second time snapshot is around 35ms
*/
void benchmarkSnapshot5() {
Properties config = new Properties();
config.put("txn-timeout", "100");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
int cnt = 10000;
for (ECKey aKey1 : key) {
Address acc = Address.wrap(aKey1.getAddress());
for (int i = 0; i < cnt; i++) {
ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(aKey1);
txn.setNrgConsume(100L);
txnl.add(txn);
}
}
tp.add(txnl);
assertTrue(tp.size() == cnt * key.size());
// sort the inserted txs
System.out.println("1st time snapshot...");
long start = System.currentTimeMillis();
tp.snapshot();
System.out.println("1st time spent: " + (System.currentTimeMillis() - start) + " ms.");
System.out.println("2nd time snapshot...");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("2nd time spent: " + (System.currentTimeMillis() - start) + " ms.");
for (ECKey aKey : key) {
List<BigInteger> nl = tp.getNonceList(Address.wrap(aKey.getAddress()));
for (int i = 0; i < cnt; i++) {
assertTrue(nl.get(i).equals(BigInteger.valueOf(i)));
}
}
}
use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.
the class TxnPoolTest method addRepeatedTxn3.
@Test
public void addRepeatedTxn3() {
Properties config = new Properties();
config.put("txn-timeout", "10");
ITxPool<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
int cnt = 10;
for (int i = 0; i < cnt; i++) {
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) i;
ITransaction txn = genTransaction(nonce);
((AionTransaction) txn).sign(key.get(0));
txn.setNrgConsume(50);
txnl.add(txn);
}
tp.add(txnl);
tp.snapshot();
assertTrue(tp.size() == cnt);
byte[] nonce = new byte[Long.BYTES];
nonce[Long.BYTES - 1] = (byte) 5;
ITransaction txn = genTransaction(nonce);
((AionTransaction) txn).sign(key.get(0));
txn.setNrgConsume(500);
tp.add(txn);
List<ITransaction> snapshot = tp.snapshot();
assertTrue(snapshot.size() == cnt);
assertTrue(snapshot.get(5).equals(txn));
}
use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.
the class TxnPoolTest method addRepeatedTxn.
@Test
public void addRepeatedTxn() {
Properties config = new Properties();
config.put("txn-timeout", "10");
ITxPool<ITransaction> tp = new TxPoolA0<>(config);
ITransaction txn = new AionTransaction(ByteUtils.fromHexString("0000000000000001"), Address.wrap(key.get(0).getAddress()), Address.wrap(key.get(0).getAddress()), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(key.get(0));
List<ITransaction> txnl = new ArrayList<>();
txnl.add(txn);
txnl.add(txn);
tp.add(txnl);
assertTrue(tp.size() == 1);
}
use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.
the class TxnPoolTest method feemapTest.
@Test
public void feemapTest() {
Properties config = new Properties();
config.put("txn-timeout", "10");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
int cnt = 100;
byte[] nonce = new byte[Long.BYTES];
for (int i = 0; i < cnt; i++) {
nonce[Long.BYTES - 1] = 1;
Address addr = Address.wrap(key2.get(i).getAddress());
ITransaction txn = new AionTransaction(nonce, addr, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(key.get(0));
txn.setNrgConsume(i + 1);
txnl.add(txn);
}
tp.add(txnl);
assertTrue(tp.size() == cnt);
// sort the inserted txs
tp.snapshot();
List<BigInteger> nl = tp.getFeeList();
long val = 100;
for (int i = 0; i < cnt; i++) {
assertTrue(nl.get(i).compareTo(BigInteger.valueOf(val--)) == 0);
}
}
Aggregations