use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class PendingStateTest method replayTransactionWithDoubleEnergyPriceAfterSealing.
@Test
public void replayTransactionWithDoubleEnergyPriceAfterSealing() {
AionTransaction tx1 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice, TransactionTypes.DEFAULT, null);
AionTransaction tx2 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice * 2, TransactionTypes.DEFAULT, null);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx1));
assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(tx2));
assertEquals(1, pendingState.getPendingTxSize());
// tx2 will get cached and will replace tx1 if tx1 is not included in the next block.
assertEquals(pendingState.getPendingTransactions().get(0), tx1);
MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), pendingState.getPendingTransactions(), false);
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
pendingState.applyBlockUpdate(block, connectResult.getRight().getReceipts());
assertEquals(0, pendingState.getPendingTxSize());
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class PendingStateTest method replayTransactionWithDoubleEnergyPrice.
@Test
public void replayTransactionWithDoubleEnergyPrice() {
AionTransaction tx1 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice, TransactionTypes.DEFAULT, null);
AionTransaction tx2 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice * 2, TransactionTypes.DEFAULT, null);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx1));
assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(tx2));
assertEquals(1, pendingState.getPendingTxSize());
// tx2 will get cached and will replace tx1 if tx1 is not included in the next block.
assertEquals(pendingState.getPendingTransactions().get(0), tx1);
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());
assertEquals(pendingState.getPendingTransactions().get(0), tx2);
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class PendingStateTest method replayTransactionThatUsesEntireBalance.
@Test
public void replayTransactionThatUsesEntireBalance() {
BigInteger balance = blockchain.getRepository().getBalance(new AionAddress(deployerKey.getAddress()));
BigInteger value = balance.subtract(BigInteger.valueOf(21000 * 3).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 * 2, 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, 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(3, 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);
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class PendingStateTest method replayInvalidTransactionInMiddle.
@Test
public void replayInvalidTransactionInMiddle() {
BigInteger balance = blockchain.getRepository().getBalance(new AionAddress(deployerKey.getAddress()));
BigInteger value = balance.subtract(BigInteger.valueOf(21000 * 3).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);
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 tx will get dropped after tx3 is rejected
AionTransaction tx4 = AionTransaction.create(deployerKey, BigInteger.TWO.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(3, 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());
assertEquals(1, pendingState.getPendingTxSize());
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class PendingStateTest method updateCacheTransactionsTest.
@Test
public void updateCacheTransactionsTest() {
List<AionTransaction> transactions = getMockTransaction(0, 2, 0);
List<AionTransaction> cachedTx = getMockTransaction(2, 1, 0);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(transactions.get(0)));
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(TxResponse.CACHED_NONCE, pendingState.addTransactionFromApiServer(cachedTx.get(0)));
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(1, pendingState.getCachePoolSize());
MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), transactions, false);
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(0, pendingState.getCachePoolSize());
assertEquals(cachedTx.get(0), pendingState.getPendingTransactions().get(0));
}
Aggregations