Search in sources :

Example 1 with AionTransaction

use of org.aion.zero.types.AionTransaction 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 AionTransaction

use of org.aion.zero.types.AionTransaction 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 AionTransaction

use of org.aion.zero.types.AionTransaction 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 AionTransaction

use of org.aion.zero.types.AionTransaction 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 AionTransaction

use of org.aion.zero.types.AionTransaction 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

AionTransaction (org.aion.zero.types.AionTransaction)75 Test (org.junit.Test)44 BigInteger (java.math.BigInteger)30 ITransaction (org.aion.base.type.ITransaction)26 Address (org.aion.base.type.Address)23 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionBlock (org.aion.zero.impl.types.AionBlock)17 ArrayList (java.util.ArrayList)16 ECKey (org.aion.crypto.ECKey)12 AionTxReceipt (org.aion.zero.types.AionTxReceipt)7 TxRecpt (org.aion.api.server.types.TxRecpt)4 ImportResult (org.aion.mcf.core.ImportResult)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuffer (java.nio.ByteBuffer)2 java.util (java.util)2 Entry (java.util.Map.Entry)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Collectors (java.util.stream.Collectors)2