Search in sources :

Example 1 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method TxnfeeCombineTest.

@Test
public void TxnfeeCombineTest() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<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 + 1);
        ITransaction txn = genTransaction(nonce);
        ((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();
    assertTrue(nl.size() == 1);
    assertTrue(nl.get(0).compareTo(BigInteger.valueOf(55 / 10)) == 0);
}
Also used : ITransaction(org.aion.base.type.ITransaction) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 2 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method TxnfeeCombineTest2.

@Test
public void TxnfeeCombineTest2() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> 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 + 1);
        ITransaction txn = genTransaction(nonce);
        ((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();
    assertTrue(nl.size() == 2);
    assertTrue(nl.get(0).compareTo(BigInteger.valueOf(26)) == 0);
    assertTrue(nl.get(1).compareTo(BigInteger.valueOf(325 / 25)) == 0);
}
Also used : ITransaction(org.aion.base.type.ITransaction) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 3 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method testSnapshotAll.

@Test
public void testSnapshotAll() {
    ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
    ECKey key = ECKeyFac.inst().create();
    List<AionTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        AionTransaction tx = new AionTransaction(BigInteger.valueOf(i).toByteArray(), Address.wrap(key.getAddress()), Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
        tx.sign(key);
        txs.add(tx);
    }
    Properties config = new Properties();
    ITxPool<AionTransaction> tp = new TxPoolA0<>(config);
    tp.add(txs.subList(0, 500));
    assertEquals(500, tp.snapshot().size());
    assertEquals(500, tp.snapshotAll().size());
    tp.remove(txs.subList(0, 100));
    assertEquals(400, tp.snapshot().size());
    assertEquals(400, tp.snapshotAll().size());
}
Also used : ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 4 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method snapshot4.

@Test
public void snapshot4() {
    Properties config = new Properties();
    config.put("txn-timeout", "100");
    TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
    List<ITransaction> 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;
        ITransaction txn = genTransaction(nonce);
        ((AionTransaction) txn).sign(key.get(0));
        txn.setNrgConsume(50 - i);
        txnl.add(txn);
    }
    tp.add(txnl);
    assertTrue(tp.size() == cnt);
    // sort the inserted txs
    List<ITransaction> txl = tp.snapshot();
    long nonce = 0;
    for (ITransaction tx : txl) {
        assertTrue((new BigInteger(tx.getNonce())).longValue() == nonce++);
    }
}
Also used : ITransaction(org.aion.base.type.ITransaction) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) Test(org.junit.Test)

Example 5 with TxPoolA0

use of org.aion.txpool.zero.TxPoolA0 in project aion by aionnetwork.

the class TxnPoolTest method addRepeatedTxn2.

@Test
public void addRepeatedTxn2() {
    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);
    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)

Aggregations

TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionTransaction (org.aion.zero.types.AionTransaction)21 Test (org.junit.Test)21 ITransaction (org.aion.base.type.ITransaction)19 BigInteger (java.math.BigInteger)14 Address (org.aion.base.type.Address)9 ECKey (org.aion.crypto.ECKey)7