use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method skipAdvancedBlock.
@Test
public void skipAdvancedBlock() throws UnknownHostException {
SimplePeer sender = new SimplePeer();
PeerScoringManager scoring = createPeerScoringManager();
SimpleBlockProcessor sbp = new SimpleBlockProcessor();
sbp.setBlockGap(100000);
NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
Block block = new BlockGenerator().createBlock(200000, 0);
Message message = new BlockMessage(block);
processor.processMessage(sender, message);
Assert.assertNotNull(sbp.getBlocks());
Assert.assertEquals(0, sbp.getBlocks().size());
Assert.assertTrue(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertTrue(pscoring.isEmpty());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method postBlockMessageFromBannedMiner.
@Test
public void postBlockMessageFromBannedMiner() {
RskSystemProperties config = spy(this.config);
Peer sender = new SimplePeer();
PeerScoringManager scoring = createPeerScoringManager();
SimpleBlockProcessor sbp = new SimpleBlockProcessor();
Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
Message message = new BlockMessage(block);
RskAddress bannedMiner = block.getCoinbase();
doReturn(Collections.singletonList(bannedMiner.toHexString())).when(config).bannedMinerList();
NodeMessageHandler nodeMessageHandler = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
nodeMessageHandler.postMessage(sender, message);
Assert.assertEquals(0, nodeMessageHandler.getMessageQueueSize());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveLowerDifficulty.
@Test
public void doesntStartSyncingIfAllPeersHaveLowerDifficulty() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
Blockchain blockchain = mock(Blockchain.class);
PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
syncState.newPeerStatus();
syncState.tick(Duration.ofMinutes(2));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveBadReputation.
@Test
public void doesntStartSyncingIfAllPeersHaveBadReputation() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
Blockchain blockchain = mock(Blockchain.class);
PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
syncState.newPeerStatus();
syncState.tick(Duration.ofMinutes(2));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingWith1PeerBeforeTimeout.
@Test
public void doesntStartSyncingWith1PeerBeforeTimeout() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
Blockchain blockchain = mock(Blockchain.class);
PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
syncState.newPeerStatus();
syncState.tick(syncConfiguration.getTimeoutWaitingPeers().minusSeconds(1L));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
Aggregations