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);
}
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);
}
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());
}
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++);
}
}
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));
}
Aggregations