use of org.aion.base.type.Address in project aion by aionnetwork.
the class TxnPoolTest method noncebyAccountTest.
@Test
public void noncebyAccountTest() {
Properties config = new Properties();
config.put("txn-timeout", "10");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
Address acc = Address.wrap(key.get(0).getAddress());
List<ITransaction> 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);
ITransaction txn = new AionTransaction(nonce, acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(key.get(0));
txn.setNrgConsume(100L);
txnl.add(txn);
}
tp.add(txnl);
assertTrue(tp.size() == cnt);
// sort the inserted txs
tp.snapshot();
List<BigInteger> nl = tp.getNonceList(acc);
for (int i = 0; i < cnt; i++) {
assertTrue(nl.get(i).equals(BigInteger.valueOf(i + 1)));
}
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class TxnPoolTest method benchmarkSnapshot4.
@Test
public /* 100K new transactions in pool around 350ms (cold-call)
*/
void benchmarkSnapshot4() {
Properties config = new Properties();
config.put("txn-timeout", "100");
TxPoolA0<ITransaction> tp = new TxPoolA0<>(config);
List<ITransaction> txnl = new ArrayList<>();
List<ITransaction> txnlrm = new ArrayList<>();
int cnt = 100000;
int rmCnt = 10;
Address acc = Address.wrap(key.get(0).getAddress());
System.out.println("gen new transactions...");
long start = System.currentTimeMillis();
for (int i = 0; i < cnt; i++) {
ITransaction txn = new AionTransaction(BigInteger.valueOf(i).toByteArray(), acc, Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10000L, 1L);
((AionTransaction) txn).sign(key.get(0));
txn.setNrgConsume(100L);
txnl.add(txn);
if (i < rmCnt) {
txnlrm.add(txn);
}
}
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
System.out.println("Inserting txns...");
start = System.currentTimeMillis();
tp.add(txnl);
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
assertTrue(tp.size() == cnt);
// sort the inserted txs
System.out.println("Snapshoting...");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
System.out.println("Removing the first 10 txns...");
start = System.currentTimeMillis();
List rm = tp.remove(txnlrm);
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
assertTrue(rm.size() == rmCnt);
assertTrue(tp.size() == cnt - rmCnt);
System.out.println("Re-Snapshot after some txns was been removed...");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
List<BigInteger> nl = tp.getNonceList(Address.wrap(key.get(0).getAddress()));
for (int i = 0; i < nl.size(); i++) {
assertTrue(nl.get(i).equals(BigInteger.valueOf(i).add(BigInteger.valueOf(rmCnt))));
}
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class BlockchainIntegrationTest method testSimpleFailedTransactionInsufficientBalance.
@Test
public void testSimpleFailedTransactionInsufficientBalance() {
// generate a recipient
final Address receiverAddress = Address.wrap(ByteUtil.hexStringToBytes("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"));
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
// (byte[] nonce, byte[] from, byte[] to, byte[] value, byte[] data)
AionTransaction tx = new AionTransaction(BigInteger.valueOf(1).toByteArray(), receiverAddress, BigInteger.valueOf(100).toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 1L, 1L);
tx.sign(bundle.privateKeys.get(0));
AionBlock block = bc.createNewBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
assertThat(block.getTransactionsList()).isEmpty();
assertThat(block.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
ImportResult connection = bc.tryToConnect(block);
assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class PendingTxCacheTest method flushTest2.
@Test
public void flushTest2() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == 10);
Map<Address, BigInteger> map = new HashMap<>();
map.put(Address.wrap(key.get(1).getAddress()), BigInteger.TWO);
cache.flush(map);
Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 10);
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class BloomFilterTest method testContainsAddress.
@Test
public void testContainsAddress() {
Address addr = new Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
Bloom bloom = BloomFilter.create(addr.toBytes());
assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue();
}
Aggregations