Search in sources :

Example 16 with PooledTransaction

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++);
    }
}
Also used : ArrayList(java.util.ArrayList) PooledTransaction(org.aion.base.PooledTransaction) AionTransaction(org.aion.base.AionTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 17 with PooledTransaction

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);
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 18 with PooledTransaction

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

Example 19 with PooledTransaction

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());
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 20 with PooledTransaction

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

Aggregations

PooledTransaction (org.aion.base.PooledTransaction)55 ArrayList (java.util.ArrayList)40 Properties (java.util.Properties)40 AionTransaction (org.aion.base.AionTransaction)40 Test (org.junit.Test)40 BigInteger (java.math.BigInteger)16 AionAddress (org.aion.types.AionAddress)16 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)11 HashMap (java.util.HashMap)5 ECKey (org.aion.crypto.ECKey)5 AionTxExecSummary (org.aion.base.AionTxExecSummary)3 List (java.util.List)2 AionTxReceipt (org.aion.base.AionTxReceipt)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Stack (java.util.Stack)1 TreeMap (java.util.TreeMap)1 Block (org.aion.zero.impl.types.Block)1