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());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingEmptyStore.
@Test
public void processGetBlockHeaderMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
final 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);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockAddingToBlockchain.
@Test
public void processBlockAddingToBlockchain() {
Blockchain blockchain = new BlockChainBuilder().ofSize(10);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
NetBlockStore store = new NetBlockStore();
Block genesis = blockchain.getBlockByNumber(0);
store.saveBlock(genesis);
Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
Assert.assertEquals(11, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
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);
processor.processBlock(null, block);
Assert.assertFalse(store.hasBlock(block));
Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertEquals(1, store.size());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method advancedBlock.
@Test
public void advancedBlock() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
final Peer sender = new SimplePeer();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final long advancedBlockNumber = syncConfiguration.getChunkSize() * syncConfiguration.getMaxSkeletonChunks() + blockchain.getBestBlock().getNumber() + 1;
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.assertTrue(processor.isAdvancedBlock(advancedBlockNumber));
Assert.assertFalse(processor.isAdvancedBlock(advancedBlockNumber - 1));
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksWithHoleAddingToBlockchain.
@Test
public void processTenBlocksWithHoleAddingToBlockchain() {
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
NetBlockStore store = new NetBlockStore();
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 (int k = 0; k < 10; k++) if (k != 5)
processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
processor.processBlock(null, blocks.get(4));
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
Aggregations