Search in sources :

Example 36 with BlockBuilder

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));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockValidator(co.rsk.validators.BlockValidator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 37 with BlockBuilder

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 38 with BlockBuilder

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 39 with BlockBuilder

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());
}
Also used : Coin(co.rsk.core.Coin) BlockDifficulty(co.rsk.core.BlockDifficulty) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 40 with BlockBuilder

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));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Aggregations

BlockBuilder (co.rsk.test.builders.BlockBuilder)61 Test (org.junit.Test)54 World (co.rsk.test.World)36 ArrayList (java.util.ArrayList)27 AccountBuilder (co.rsk.test.builders.AccountBuilder)26 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)17 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)13 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)12 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)11 SimpleBlock (co.rsk.peg.simples.SimpleBlock)11 Block (org.ethereum.core.Block)11 HashMapDB (org.ethereum.datasource.HashMapDB)9 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)8 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)8 RemascTransaction (co.rsk.remasc.RemascTransaction)7 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)7 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)6 BlockHeader (org.ethereum.core.BlockHeader)4 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)3 BlockStore (org.ethereum.db.BlockStore)3