use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method validateBlockWithTransaction.
@Test
public void validateBlockWithTransaction() {
BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
Block genesis = BlockChainImplTest.getGenesisBlock(blockChain);
genesis.seal();
Block parent = new BlockBuilder().parent(genesis).build();
parent.seal();
List<Transaction> txs = new ArrayList<>();
txs.add(BlockExecutorTest.generateBlockWithOneTransaction().getTransaction());
Block block = new BlockBuilder().parent(parent).transactions(txs).build();
;
block.seal();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(parent));
BlockValidator validator = createValidator(blockChain.getBlockStore());
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method processValidMGPBlock.
@Test
public void processValidMGPBlock() {
BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
Block parent = new BlockBuilder().minGasPrice(BigInteger.TEN).parent(new BlockGenerator().getGenesisBlock()).build();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(12L), BigInteger.TEN);
tx.sign(new byte[] { 22, 11, 00 });
txs.add(tx);
Block block = new BlockBuilder().transactions(txs).minGasPrice(BigInteger.valueOf(11L)).parent(parent).build();
Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().addTxsMinGasPriceRule().blockStore(blockStore).build();
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method parentInvalidNumber.
@Test
public void parentInvalidNumber() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block = new BlockBuilder().parent(genesis).build();
block.getHeader().setNumber(25L);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentNumberRule().blockStore(store).build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class TransactionPoolImplTest method processBestBlockRemovesTransactionsInBlock.
@Test
public void processBestBlockRemovesTransactionsInBlock() {
BlockChainImpl blockchain = createBlockchain();
Coin balance = Coin.valueOf(1000000);
TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(3, balance, blockchain);
transactionPool.processBest(blockchain.getBestBlock());
Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
Transaction tx3 = createSampleTransaction(2, 3, 1000, 0);
Transaction tx4 = createSampleTransaction(2, 3, 3000, 1);
transactionPool.addTransaction(tx1);
transactionPool.addTransaction(tx2);
List<Transaction> txs = new ArrayList<>();
txs.add(tx1);
txs.add(tx2);
txs.add(tx3);
txs.add(tx4);
transactionPool.addTransactions(txs);
List<Transaction> btxs = new ArrayList<>();
btxs.add(tx1);
btxs.add(tx3);
Block genesis = blockchain.getBestBlock();
Block block = new BlockBuilder().parent(genesis).transactions(btxs).build();
transactionPool.getBlockStore().saveBlock(genesis, new BlockDifficulty(BigInteger.ONE), true);
transactionPool.processBest(block);
List<Transaction> alltxs = transactionPool.getPendingTransactions();
Assert.assertNotNull(alltxs);
Assert.assertFalse(alltxs.isEmpty());
Assert.assertEquals(2, alltxs.size());
Assert.assertFalse(alltxs.contains(tx1));
Assert.assertTrue(alltxs.contains(tx2));
Assert.assertFalse(alltxs.contains(tx3));
Assert.assertTrue(alltxs.contains(tx4));
Assert.assertSame(block, transactionPool.getBestBlock());
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method remascTx.
@Test
public void remascTx() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(12L), BigInteger.TEN);
tx.sign(new byte[] {});
txs.add(tx);
txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
Block block = new BlockBuilder().parent(genesis).transactions(txs).build();
BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
Assert.assertTrue(validator.isValid(block));
}
Aggregations