use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessagesAndAddThemToBlockchainInReverseOrder.
@Test
public void sendBlockMessagesAndAddThemToBlockchainInReverseOrder() {
for (int i = 1; i < 52; i += 5) {
Blockchain blockchain = BlockChainBuilder.ofSize(10 * i);
BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(10 * i, blockchain.getBestBlock().getNumber());
Block initialBestBlock = blockchain.getBestBlock();
List<Block> extendedChain = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), i);
Collections.reverse(extendedChain);
for (int j = 0; j < extendedChain.size() - 1; j++) {
Block block = extendedChain.get(j);
blockSyncService.processBlock(block, null, false);
// we don't have all the parents, so we wait to update the best chain
Assert.assertEquals(initialBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(initialBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
// the chain is complete, we have a new best block
Block closingBlock = extendedChain.get(extendedChain.size() - 1);
Block newBestBlock = extendedChain.get(0);
blockSyncService.processBlock(closingBlock, null, false);
Assert.assertEquals(newBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(newBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTwoBlockListsAddingToBlockchainWithFork.
@Test
public void processTwoBlockListsAddingToBlockchainWithFork() {
BlockStore store = new BlockStore();
Blockchain blockchain = BlockChainBuilder.ofSize(0);
Block genesis = blockchain.getBestBlock();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
List<Block> blocks2 = blockGenerator.getBlockChain(blocks.get(4), 20);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
for (Block b : blocks2) processor.processBlock(null, b);
Assert.assertEquals(25, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingEmptyStore.
@Test
public void processGetBlockHeaderMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final BlockStore store = new BlockStore();
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksAddingToBlockchain.
@Test
public void processTenBlocksAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksGenesisAtLastAddingToBlockchain.
@Test
public void processTenBlocksGenesisAtLastAddingToBlockchain() {
BlockStore store = new BlockStore();
Blockchain blockchain = BlockChainBuilder.ofSize(0);
Block genesis = blockchain.getBestBlock();
List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
for (Block b : blocks) processor.processBlock(null, b);
processor.processBlock(null, genesis);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
Aggregations