use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHeadersRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(100);
final Block block = blockchain.getBlockByNumber(60);
final BlockStore store = new BlockStore();
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();
processor.processBlockHeadersRequest(sender, 100, block.getHash().getBytes(), 20);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());
final BlockHeadersResponseMessage response = (BlockHeadersResponseMessage) message;
Assert.assertEquals(100, response.getId());
Assert.assertNotNull(response.getBlockHeaders());
Assert.assertEquals(20, response.getBlockHeaders().size());
for (int k = 0; k < 20; k++) Assert.assertEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.
@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(skeletonStep / 2);
final Block blockStart = blockchain.getBlockByNumber(5);
final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
final BlockStore store = new BlockStore();
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();
processor.processSkeletonRequest(sender, 100, 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block genesis = blockchain.getBlockByNumber(0);
Block bestBlock = blockchain.getBestBlock();
BlockIdentifier[] expected = { new BlockIdentifier(genesis.getHash().getBytes(), genesis.getNumber()), new BlockIdentifier(bestBlock.getHash().getBytes(), bestBlock.getNumber()) };
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockAddingToBlockchainUsingItsParent.
@Test
public void processBlockAddingToBlockchainUsingItsParent() {
BlockStore store = new BlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
store.saveBlock(genesis);
Blockchain blockchain = BlockChainBuilder.ofSize(10);
Block parent = blockGenerator.createChildBlock(blockchain.getBlockByNumber(10));
Block block = blockGenerator.createChildBlock(parent);
Assert.assertEquals(11, parent.getNumber());
Assert.assertEquals(12, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), parent.getParentHash().getBytes());
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, block);
Assert.assertTrue(store.hasBlock(block));
Assert.assertNull(blockchain.getBlockByHash(block.getHash().getBytes()));
processor.processBlock(null, parent);
Assert.assertFalse(store.hasBlock(block));
Assert.assertFalse(store.hasBlock(parent));
Assert.assertEquals(12, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertEquals(1, store.size());
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockWithTooMuchHeight.
@Test
public void processBlockWithTooMuchHeight() throws UnknownHostException {
final BlockStore store = new BlockStore();
final MessageChannel sender = new SimpleMessageChannel();
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
final Block orphan = new BlockGenerator().createBlock(1000, 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);
processor.processBlock(sender, orphan);
Assert.assertFalse(processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size() == 1);
Assert.assertFalse(store.hasBlock(orphan));
Assert.assertEquals(0, store.size());
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.
@Test
public void processSkeletonRequestNotIncludingGenesis() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(400);
final BlockStore store = new BlockStore();
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();
processor.processSkeletonRequest(sender, 100, skeletonStep + 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block b1 = blockchain.getBlockByNumber(skeletonStep);
Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
Block b3 = blockchain.getBestBlock();
BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Aggregations