use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method getPeersInformationFromManagerWithOneEvent.
@Test
public void getPeersInformationFromManagerWithOneEvent() throws UnknownHostException {
PeerScoringManager manager = createPeerScoringManager();
NodeID node = generateNodeID();
InetAddress address = generateIPAddressV4();
manager.recordEvent(node, address, EventType.VALID_BLOCK);
List<PeerScoringInformation> result = manager.getPeersInformation();
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(2, result.size());
PeerScoringInformation info = result.get(0);
Assert.assertEquals(Hex.toHexString(node.getID()).substring(0, 8), info.getId());
Assert.assertEquals(1, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(0, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertEquals(0, info.getPunishments());
Assert.assertEquals(0, info.getSuccessfulHandshakes());
Assert.assertTrue(info.getScore() > 0);
info = result.get(1);
Assert.assertEquals(address.getHostAddress(), info.getId());
Assert.assertEquals(1, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(0, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertEquals(0, info.getPunishments());
Assert.assertEquals(0, info.getSuccessfulHandshakes());
Assert.assertTrue(info.getScore() > 0);
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method recordEventUsingNodeID.
@Test
public void recordEventUsingNodeID() {
NodeID id = generateNodeID();
PeerScoringManager manager = createPeerScoringManager();
manager.recordEvent(id, null, EventType.INVALID_BLOCK);
PeerScoring result = manager.getPeerScoring(id);
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
Assert.assertEquals(1, result.getTotalEventCounter());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method managesOnlyThreeNodes.
@Test
public void managesOnlyThreeNodes() {
PeerScoringManager manager = createPeerScoringManager(3);
NodeID node1 = generateNodeID();
NodeID node2 = generateNodeID();
NodeID node3 = generateNodeID();
manager.recordEvent(node1, null, EventType.INVALID_BLOCK);
Assert.assertFalse(manager.getPeerScoring(node1).hasGoodReputation());
manager.recordEvent(node2, null, EventType.INVALID_BLOCK);
manager.recordEvent(node3, null, EventType.INVALID_BLOCK);
NodeID node4 = generateNodeID();
manager.recordEvent(node4, null, EventType.INVALID_BLOCK);
Assert.assertTrue(manager.getPeerScoring(node1).hasGoodReputation());
Assert.assertFalse(manager.getPeerScoring(node2).hasGoodReputation());
Assert.assertFalse(manager.getPeerScoring(node3).hasGoodReputation());
Assert.assertFalse(manager.getPeerScoring(node4).hasGoodReputation());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method recordEventUsingNodeIDAndAddress.
@Test
public void recordEventUsingNodeIDAndAddress() throws UnknownHostException {
NodeID id = generateNodeID();
InetAddress address = generateIPAddressV4();
PeerScoringManager manager = createPeerScoringManager();
manager.recordEvent(id, address, EventType.INVALID_BLOCK);
PeerScoring result = manager.getPeerScoring(id);
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
Assert.assertEquals(1, result.getTotalEventCounter());
result = manager.getPeerScoring(address);
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
Assert.assertEquals(1, result.getTotalEventCounter());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method newNodeHasGoodReputation.
@Test
public void newNodeHasGoodReputation() {
NodeID id = generateNodeID();
PeerScoringManager manager = createPeerScoringManager();
Assert.assertTrue(manager.hasGoodReputation(id));
}
Aggregations