use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processBlockMessageUsingProcessor.
@Test
public void processBlockMessageUsingProcessor() {
SimplePeer sender = new SimplePeer();
PeerScoringManager scoring = createPeerScoringManager();
SimpleBlockProcessor sbp = new SimpleBlockProcessor();
NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
Message message = new BlockMessage(block);
processor.processMessage(sender, message);
Assert.assertNotNull(sbp.getBlocks());
Assert.assertEquals(1, sbp.getBlocks().size());
Assert.assertSame(block, sbp.getBlocks().get(0));
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
pscoring = scoring.getPeerScoring(sender.getAddress());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processStatusMessageWithKnownBestBlock.
@Test
public void processStatusMessageWithKnownBestBlock() {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
final SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), null, new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, syncProcessor, null, null, null, mock(StatusResolver.class));
BlockGenerator blockGenerator = new BlockGenerator();
final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), blockchain.getTotalDifficulty());
final Message message = new StatusMessage(status);
store.saveBlock(block);
handler.processMessage(sender, message);
Assert.assertNotNull(sender.getMessages());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method postBlockMessageTwice.
@Test
public void postBlockMessageTwice() throws InterruptedException, UnknownHostException {
Peer sender = new SimplePeer();
PeerScoringManager scoring = createPeerScoringManager();
SimpleBlockProcessor sbp = new SimpleBlockProcessor();
NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
Message message = new BlockMessage(block);
processor.postMessage(sender, message);
processor.postMessage(sender, message);
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.REPEATED_MESSAGE));
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processStatusMessageUsingNodeBlockProcessor.
@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void processStatusMessageUsingNodeBlockProcessor() throws UnknownHostException {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, mock(StatusResolver.class));
BlockGenerator blockGenerator = new BlockGenerator();
final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Status status = new Status(block.getNumber(), block.getHash().getBytes());
final Message message = new StatusMessage(status);
handler.processMessage(sender, message);
Assert.assertNotNull(sender.getGetBlockMessages());
Assert.assertEquals(1, sender.getGetBlockMessages().size());
final Message msg = sender.getGetBlockMessages().get(0);
Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, msg.getMessageType());
final GetBlockMessage gbMessage = (GetBlockMessage) msg;
Assert.assertArrayEquals(block.getHash().getBytes(), gbMessage.getBlockHash());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockRequestMessageUsingBlockInStore.
@Test
public void processBlockRequestMessageUsingBlockInStore() {
final Block block = new BlockGenerator().getBlock(3);
final Keccak256 blockHash = block.getHash();
final NetBlockStore store = new NetBlockStore();
store.saveBlock(block);
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.processBlockRequest(sender, 100, 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_RESPONSE_MESSAGE, message.getMessageType());
final BlockResponseMessage bMessage = (BlockResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
Aggregations