use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class SyncProcessorTest method processSkeletonResponseWithConnectionPoint.
@Test
public void processSkeletonResponseWithConnectionPoint() {
Blockchain blockchain = new BlockChainBuilder().ofSize(25);
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
final ChannelManager channelManager = mock(ChannelManager.class);
Peer channel = mock(Peer.class);
when(channel.getPeerNodeID()).thenReturn(sender.getPeerNodeID());
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(channel));
SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(channelManager, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
int connectionPoint = 25;
int step = 10;
int linkCount = 10;
processor.startDownloadingSkeleton(connectionPoint, sender);
List<BlockIdentifier> blockIdentifiers = buildSkeleton(blockchain, connectionPoint, step, linkCount);
SkeletonResponseMessage response = new SkeletonResponseMessage(new Random().nextLong(), blockIdentifiers);
processor.registerExpectedMessage(response);
processor.processSkeletonResponse(sender, response);
Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_REQUEST_MESSAGE, message.getMessageType());
BlockHeadersRequestMessage request = (BlockHeadersRequestMessage) message;
Assert.assertEquals(5, request.getCount());
Assert.assertArrayEquals(blockIdentifiers.get(1).getHash(), request.getHash());
Assert.assertEquals(1, processor.getExpectedResponses().size());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class NodeMessageHandlerTest method processStatusMessageUsingSyncProcessor.
@Test()
public void processStatusMessageUsingSyncProcessor() {
final SimplePeer sender = new SimplePeer();
final ChannelManager channelManager = mock(ChannelManager.class);
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(sender));
final NodeMessageHandler handler = NodeMessageHandlerUtil.createHandlerWithSyncProcessor(SyncConfiguration.IMMEDIATE_FOR_TESTING, channelManager);
BlockGenerator blockGenerator = new BlockGenerator();
final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), new BlockDifficulty(BigInteger.TEN));
final Message message = new StatusMessage(status);
handler.processMessage(sender, message);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(MessageType.BLOCK_HEADERS_REQUEST_MESSAGE, sender.getMessages().get(0).getMessageType());
}
Aggregations