Search in sources :

Example 96 with AionTransaction

use of org.aion.base.AionTransaction 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);
    for (AionTransaction tx : txn) {
        cache.addCacheTx(tx);
    }
    assertTrue(cache.cacheTxSize() == 10);
    Map<AionAddress, BigInteger> map = new HashMap<>();
    map.put(new AionAddress(key.get(1).getAddress()), BigInteger.TWO);
    cache.flush(map);
    Map<BigInteger, AionTransaction> cacheMap = cache.getCacheTx(new AionAddress(key.get(0).getAddress()));
    assertTrue(cacheMap.size() == 10);
}
Also used : AionAddress(org.aion.types.AionAddress) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 97 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheTest method maxPendingSizeTest6.

@Test
public void maxPendingSizeTest6() {
    PendingTxCache cache = new PendingTxCache(1);
    List<AionTransaction> txn = getMockTransaction(0, 100, 0);
    txn.addAll(getMockTransaction(101, 600, 0));
    for (AionTransaction tx : txn) {
        cache.addCacheTx(tx);
    }
    assertTrue(cache.cacheTxSize() == 659);
    Map<BigInteger, AionTransaction> cacheMap = cache.getCacheTx(new AionAddress(key.get(0).getAddress()));
    assertTrue(cacheMap.size() == 659);
    AionTransaction tx = getMockBigTransaction(100, 1, 0, 199_500).get(0);
    cache.addCacheTx(tx);
    assertTrue(cache.cacheTxSize() == 659);
}
Also used : AionAddress(org.aion.types.AionAddress) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 98 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheTest method addCacheTxTest2.

@Test
public void addCacheTxTest2() {
    PendingTxCache cache = new PendingTxCache(1);
    List<AionTransaction> txn = getMockTransaction(0, 10, 0);
    txn.addAll(getMockTransaction(0, 10, 1));
    for (AionTransaction tx : txn) {
        cache.addCacheTx(tx);
    }
    assertTrue(cache.cacheTxSize() == txn.size());
}
Also used : AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 99 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingTxCacheV1Test method flushTxWith2AccountsTest.

@Test
public void flushTxWith2AccountsTest() {
    PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
    List<AionTransaction> txn = getMockTransaction(0, 10, 0);
    txn.addAll(getMockTransaction(0, 10, 1));
    for (AionTransaction tx : txn) {
        cache.addCacheTx(tx);
    }
    assertEquals(20, cache.cacheTxSize());
    Map<AionAddress, BigInteger> map = new HashMap<>();
    map.put(new AionAddress(key.get(0).getAddress()), BigInteger.TWO);
    map.put(new AionAddress(key.get(1).getAddress()), BigInteger.ONE);
    cache.removeSealedTransactions(map);
    List<AionTransaction> cachedTxs = new ArrayList<>(cache.getCacheTxBySender(new AionAddress(key.get(0).getAddress())).values());
    assertEquals(8, cachedTxs.size());
    cachedTxs = new ArrayList<>(cache.getCacheTxBySender(new AionAddress(key.get(1).getAddress())).values());
    assertEquals(9, cachedTxs.size());
}
Also used : AionAddress(org.aion.types.AionAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 100 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method replayTransactionThatThatInvalidatesMiddleTx.

@Test
public void replayTransactionThatThatInvalidatesMiddleTx() {
    BigInteger balance = blockchain.getRepository().getBalance(new AionAddress(deployerKey.getAddress()));
    BigInteger value = balance.subtract(BigInteger.valueOf(21000 * 7).multiply(BigInteger.valueOf(energyPrice)));
    AionTransaction tx1 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), value.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
    AionTransaction tx2 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
    /* tx1 and tx3 should use the entire balance. If tx2 is removed properly, tx3 should be
         * able to replace it in the pending state */
    AionTransaction tx3 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice * 4, TransactionTypes.DEFAULT, null);
    // This would execute fine on top of tx2, but should have insufficient balance on top of tx3
    AionTransaction tx4 = AionTransaction.create(deployerKey, BigInteger.TWO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice * 4, TransactionTypes.DEFAULT, null);
    AionTransaction tx5 = AionTransaction.create(deployerKey, BigInteger.valueOf(3).toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), new byte[0], 21000, energyPrice, TransactionTypes.DEFAULT, null);
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx1));
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx2));
    assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(tx3));
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx4));
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx5));
    assertEquals(4, pendingState.getPendingTxSize());
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), Collections.emptyList(), false);
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
    pendingState.applyBlockUpdate(block, connectResult.getRight().getReceipts());
    // tx3 should replace tx2, and tx4 will now have insufficient funds so it will get dropped
    assertEquals(2, pendingState.getPendingTxSize());
    assertEquals(pendingState.getPendingTransactions().get(1), tx3);
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Aggregations

AionTransaction (org.aion.base.AionTransaction)437 Test (org.junit.Test)308 AionAddress (org.aion.types.AionAddress)273 BigInteger (java.math.BigInteger)174 MiningBlock (org.aion.zero.impl.types.MiningBlock)149 ArrayList (java.util.ArrayList)127 ImportResult (org.aion.zero.impl.core.ImportResult)115 AionTxExecSummary (org.aion.base.AionTxExecSummary)103 Block (org.aion.zero.impl.types.Block)102 RepositoryCache (org.aion.base.db.RepositoryCache)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)87 AionTxReceipt (org.aion.base.AionTxReceipt)75 ECKey (org.aion.crypto.ECKey)52 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)46 BlockContext (org.aion.zero.impl.types.BlockContext)43 PooledTransaction (org.aion.base.PooledTransaction)40 AccountState (org.aion.base.AccountState)39 Properties (java.util.Properties)35 HashMap (java.util.HashMap)33 DataWord (org.aion.util.types.DataWord)29