use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessagesAndAddThemToBlockchainInReverseOrder.
@Test
public void sendBlockMessagesAndAddThemToBlockchainInReverseOrder() {
for (int i = 1; i < 52; i += 5) {
Blockchain blockchain = new BlockChainBuilder().ofSize(10 * i);
NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
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.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHashRequestMessageUsingOutOfBoundsHeight.
@Test
public void processBlockHashRequestMessageUsingOutOfBoundsHeight() throws UnknownHostException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
processor.processBlockHashRequest(sender, 100, 99999);
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksGenesisAtLastAddingToBlockchain.
@Test
public void processTenBlocksGenesisAtLastAddingToBlockchain() {
NetBlockStore store = new NetBlockStore();
Blockchain blockchain = new 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;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
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());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method noSyncingWithEmptyBlockchain.
@Test
public void noSyncingWithEmptyBlockchain() {
NetBlockStore store = new NetBlockStore();
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertFalse(processor.hasBetterBlockToSync());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method syncingWithEmptyBlockchainAndHighBestBlock.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingWithEmptyBlockchainAndHighBestBlock() {
NetBlockStore store = new NetBlockStore();
Block block = new BlockGenerator().createBlock(30, 0);
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertFalse(processor.hasBetterBlockToSync());
// Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(new SimpleNodeChannel(null, null), status);
Assert.assertTrue(processor.hasBetterBlockToSync());
}
Aggregations