use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksInverseOrderAddingToBlockchain.
@Test
public void processTenBlocksInverseOrderAddingToBlockchain() {
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);
for (int k = 0; k < 10; k++) processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHeadersRequestMessageUsingUnknownHash.
@Test
public void processBlockHeadersRequestMessageUsingUnknownHash() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(100);
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, HashUtil.randomHash(), 20);
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusRetrievingBestBlockUsingSender.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusRetrievingBestBlockUsingSender() throws UnknownHostException {
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();
BlockGenerator blockGenerator = new BlockGenerator();
final Block genesis = blockGenerator.getGenesisBlock();
final Block block = blockGenerator.createChildBlock(genesis);
// final Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(sender, status);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
Assert.assertEquals(1, sender.getGetBlockMessages().size());
final Message message = sender.getGetBlockMessages().get(0);
Assert.assertNotNull(message);
Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, message.getMessageType());
final GetBlockMessage gbMessage = (GetBlockMessage) message;
Assert.assertArrayEquals(block.getHash().getBytes(), gbMessage.getBlockHash());
Assert.assertEquals(0, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockSavingInStore.
@Test
public void processBlockSavingInStore() throws UnknownHostException {
final BlockStore store = new BlockStore();
final MessageChannel sender = new SimpleMessageChannel();
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockGenerator blockGenerator = new BlockGenerator();
final Block parent = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Block orphan = blockGenerator.createChildBlock(parent);
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.assertTrue(processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size() == 1);
Assert.assertTrue(store.hasBlock(orphan));
Assert.assertEquals(1, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeMessageHandlerTest method processGetBlockMessageUsingEmptyStore.
@Test
public void processGetBlockMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, null, new DummyBlockValidationRule());
final SimpleMessageChannel sender = new SimpleMessageChannel();
handler.processMessage(sender, new GetBlockMessage(block.getHash().getBytes()));
Assert.assertTrue(sender.getMessages().isEmpty());
}
Aggregations