use of org.aion.base.type.ITransaction 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.base.type.ITransaction 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.base.type.ITransaction in project aion by aionnetwork.
the class PendingTxCacheTest method flushTest1.
@Test
public void flushTest1() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == 10);
Map<Address, BigInteger> map = new HashMap<>();
map.put(Address.wrap(key.get(0).getAddress()), BigInteger.TWO);
newCache = cache.flush(map);
assertTrue(newCache.size() == 1);
Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 8);
}
use of org.aion.base.type.ITransaction in project aion by aionnetwork.
the class PendingTxCacheTest method addCacheTxTest4.
@Test
public void addCacheTxTest4() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(5, 10, 0));
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == 20);
Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 15);
}
use of org.aion.base.type.ITransaction in project aion by aionnetwork.
the class PendingTxCacheTest method addCacheTxTest.
@Test
public void addCacheTxTest() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == txn.size());
}
Aggregations