Search in sources :

Example 16 with ChannelManager

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());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ChannelManager(org.ethereum.net.server.ChannelManager) BlockStore(org.ethereum.db.BlockStore) SimplePeer(co.rsk.net.simples.SimplePeer) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 17 with ChannelManager

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());
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ChannelManager(org.ethereum.net.server.ChannelManager) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Aggregations

ChannelManager (org.ethereum.net.server.ChannelManager)17 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)12 Test (org.junit.Test)12 SimplePeer (co.rsk.net.simples.SimplePeer)10 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)9 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)9 BlockStore (org.ethereum.db.BlockStore)9 EthereumListener (org.ethereum.listener.EthereumListener)9 TestSystemProperties (co.rsk.config.TestSystemProperties)7 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)5 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)5 Web3RskImpl (co.rsk.rpc.Web3RskImpl)5 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)5 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)5 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)5 MinerClient (co.rsk.mine.MinerClient)4 DebugModule (co.rsk.rpc.modules.debug.DebugModule)4 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)4 EthModule (co.rsk.rpc.modules.eth.EthModule)4 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)4