Search in sources :

Example 46 with Address

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)));
    }
}
Also used : Address(org.aion.base.type.Address) 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 47 with Address

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))));
    }
}
Also used : Address(org.aion.base.type.Address) ITransaction(org.aion.base.type.ITransaction) AionTransaction(org.aion.zero.types.AionTransaction) TxPoolA0(org.aion.txpool.zero.TxPoolA0) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 48 with Address

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);
}
Also used : ImportResult(org.aion.mcf.core.ImportResult) Address(org.aion.base.type.Address) AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock) Test(org.junit.Test)

Example 49 with Address

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);
}
Also used : Address(org.aion.base.type.Address) HashMap(java.util.HashMap) ITransaction(org.aion.base.type.ITransaction) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 50 with Address

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();
}
Also used : Address(org.aion.base.type.Address) Bloom(org.aion.mcf.vm.types.Bloom) Test(org.junit.Test)

Aggregations

Address (org.aion.base.type.Address)61 Test (org.junit.Test)34 BigInteger (java.math.BigInteger)29 AionTransaction (org.aion.zero.types.AionTransaction)23 ITransaction (org.aion.base.type.ITransaction)14 ECKey (org.aion.crypto.ECKey)13 DataWord (org.aion.mcf.vm.types.DataWord)11 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)10 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)9 IRepositoryCache (org.aion.base.db.IRepositoryCache)8 HashMap (java.util.HashMap)6 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)5 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)5 AccountState (org.aion.mcf.core.AccountState)5 AionBlock (org.aion.zero.impl.types.AionBlock)5 ArrayList (java.util.ArrayList)4 ImportResult (org.aion.mcf.core.ImportResult)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 IRepository (org.aion.base.db.IRepository)3 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)3