Search in sources :

Example 11 with ITransaction

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)));
        }
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 12 with ITransaction

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));
}
Also used : ITransaction(org.aion.base.type.ITransaction) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 13 with ITransaction

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);
}
Also used : Address(org.aion.base.type.Address) HashMap(java.util.HashMap) ITransaction(org.aion.base.type.ITransaction) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 14 with ITransaction

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);
}
Also used : ITransaction(org.aion.base.type.ITransaction) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 15 with ITransaction

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());
}
Also used : ITransaction(org.aion.base.type.ITransaction) ArrayList(java.util.ArrayList) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Aggregations

ITransaction (org.aion.base.type.ITransaction)29 AionTransaction (org.aion.zero.types.AionTransaction)26 Test (org.junit.Test)26 BigInteger (java.math.BigInteger)22 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)19 Address (org.aion.base.type.Address)13 ArrayList (java.util.ArrayList)7 ECKey (org.aion.crypto.ECKey)5 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)3 HashMap (java.util.HashMap)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AccountState (org.aion.txpool.common.AccountState)1 TxDependList (org.aion.txpool.common.TxDependList)1