Search in sources :

Example 46 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method add2.

@Test
public void add2() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
    TxPoolV1 tp = new TxPoolV1(config);
    PooledTransaction pooledTx = genTransaction(new byte[0], 0);
    tp.add(pooledTx);
    Assert.assertEquals(1, tp.size());
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 47 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method snapshot.

@Test
public void snapshot() {
    Properties config = new Properties();
    // 10 sec
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = getMockTransaction(0);
    tp.add(txnl);
    tp.snapshot();
    Assert.assertEquals(1, tp.size());
}
Also used : PooledTransaction(org.aion.base.PooledTransaction) Properties(java.util.Properties) Test(org.junit.Test)

Example 48 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method addRepeatedTxn2.

@Test
public void addRepeatedTxn2() {
    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;
    for (int i = 0; i < cnt; i++) {
        byte[] nonce = new byte[Long.BYTES];
        nonce[Long.BYTES - 1] = (byte) i;
        PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 1);
        txnl.add(pooledTx);
    }
    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt);
    byte[] nonce = new byte[Long.BYTES];
    nonce[Long.BYTES - 1] = (byte) 5;
    PooledTransaction pooledTx = genTransactionWithEnergyPrice(nonce, 2);
    tp.add(pooledTx);
    List<AionTransaction> snapshot = tp.snapshot();
    Assert.assertEquals(snapshot.size(), cnt);
    Assert.assertEquals(snapshot.get(5), pooledTx.tx);
}
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 49 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method snapshot4.

@Test
public void snapshot4() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 26;
    for (int i = 0; i < cnt; i++) {
        byte[] nonce = new byte[Long.BYTES];
        nonce[Long.BYTES - 1] = (byte) i;
        PooledTransaction txn = genTransaction(nonce, Constant.MIN_ENERGY_CONSUME + (1000L - i));
        txnl.add(txn);
    }
    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt);
    // sort the inserted txs
    List<AionTransaction> snapshot = tp.snapshot();
    long nonce = 0;
    for (AionTransaction tx : snapshot) {
        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 50 with PooledTransaction

use of org.aion.base.PooledTransaction in project aion by aionnetwork.

the class TxPoolV1Test method noncebyAccountTest2.

@Test
public void noncebyAccountTest2() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");
    TxPoolV1 tp = new TxPoolV1(config);
    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 100;
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt; i++) {
            byte[] nonce = new byte[Long.BYTES];
            nonce[Long.BYTES - 1] = (byte) (i + 1);
            AionTransaction txn = AionTransaction.create(aKey1, 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 * key.size());
    // sort the inserted txs
    tp.snapshot();
    for (ECKey aKey : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
        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) ECKey(org.aion.crypto.ECKey) 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