use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.
@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() {
int skeletonStep = 192;
final Blockchain blockchain = new BlockChainBuilder().ofSize(skeletonStep / 2);
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, 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.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processGetBlockHeaderMessageUsingEmptyStore.
@Test
public void processGetBlockHeaderMessageUsingEmptyStore() {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
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.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockWithTooMuchHeight.
@Test
public void processBlockWithTooMuchHeight() {
final NetBlockStore store = new NetBlockStore();
final Peer sender = new SimplePeer();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final Block orphan = new BlockGenerator().createBlock(1000, 0);
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.assertNotEquals(1, processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size());
Assert.assertFalse(store.hasBlock(orphan));
Assert.assertEquals(0, store.size());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class MessageCounterTest method decrement_toBelowOne_thenRemoveKey.
@Test
public void decrement_toBelowOne_thenRemoveKey() {
SimplePeer sender = new SimplePeer(new NodeID(new byte[] { 1 }));
MessageCounter counter = new MessageCounter();
counter.increment(sender);
counter.decrement(sender);
Assert.assertFalse(counter.hasCounter(sender));
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHeadersRequestMessageUsingUnknownHash.
@Test
public void processBlockHeadersRequestMessageUsingUnknownHash() throws UnknownHostException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(100);
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.processBlockHeadersRequest(sender, 100, HashUtil.randomHash(), 20);
Assert.assertTrue(sender.getMessages().isEmpty());
}
Aggregations