use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockSavingInStore.
@Test
public void processBlockSavingInStore() {
final NetBlockStore store = new NetBlockStore();
final Peer sender = new SimplePeer();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final BlockGenerator blockGenerator = new BlockGenerator();
final Block parent = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Block orphan = blockGenerator.createChildBlock(parent);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
processor.processBlock(sender, orphan);
Assert.assertEquals(1, processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size());
Assert.assertTrue(store.hasBlock(orphan));
Assert.assertEquals(1, store.size());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockHashRequestMessageUsingOutOfBoundsHeight.
@Test
public void processBlockHashRequestMessageUsingOutOfBoundsHeight() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
processor.processBlockHashRequest(sender, 100, 99999);
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockHeadersRequestMessageUsingUnknownHash.
@Test
public void processBlockHeadersRequestMessageUsingUnknownHash() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(100);
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
processor.processBlockHeadersRequest(sender, 100, HashUtil.randomHash(), 20);
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processGetBlockMessageUsingBlockInBlockchain.
@Test
public void processGetBlockMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
final Keccak256 blockHash = block.getHash();
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_MESSAGE, message.getMessageType());
final BlockMessage bMessage = (BlockMessage) message;
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.
@Test
public void processSkeletonRequestNotIncludingGenesis() {
final int skeletonStep = 192;
final Blockchain blockchain = new BlockChainBuilder().ofSize(400);
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
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());
final Block b1 = blockchain.getBlockByNumber(skeletonStep);
final Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
final Block b3 = blockchain.getBestBlock();
final 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