Search in sources :

Example 1 with PeerScoringInformation

use of co.rsk.scoring.PeerScoringInformation in project rskj by rsksmart.

the class Web3ImplScoringTest method getPeerList.

@Test
public void getPeerList() throws UnknownHostException {
    NodeID node = generateNodeID();
    InetAddress address = generateNonLocalIPAddressV4();
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
    peerScoringManager.recordEvent(node, address, EventType.VALID_TRANSACTION);
    peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
    Web3Impl web3 = createWeb3(peerScoringManager);
    PeerScoringInformation[] result = web3.sco_peerList();
    Assert.assertNotNull(result);
    Assert.assertEquals(2, result.length);
    PeerScoringInformation info = result[0];
    Assert.assertEquals(Hex.toHexString(node.getID()).substring(0, 8), info.getId());
    Assert.assertEquals(2, info.getValidBlocks());
    Assert.assertEquals(0, info.getInvalidBlocks());
    Assert.assertEquals(1, info.getValidTransactions());
    Assert.assertEquals(0, info.getInvalidTransactions());
    Assert.assertTrue(info.getScore() > 0);
    info = result[1];
    Assert.assertEquals(address.getHostAddress(), info.getId());
    Assert.assertEquals(2, info.getValidBlocks());
    Assert.assertEquals(0, info.getInvalidBlocks());
    Assert.assertEquals(1, info.getValidTransactions());
    Assert.assertEquals(0, info.getInvalidTransactions());
    Assert.assertTrue(info.getScore() > 0);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) PeerScoringInformation(co.rsk.scoring.PeerScoringInformation) NodeID(co.rsk.net.NodeID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with PeerScoringInformation

use of co.rsk.scoring.PeerScoringInformation in project rskj by rsksmart.

the class Web3ImplScoringTest method getEmptyPeerList.

@Test
public void getEmptyPeerList() {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    PeerScoringInformation[] result = web3.sco_peerList();
    Assert.assertNotNull(result);
    Assert.assertEquals(0, result.length);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) PeerScoringInformation(co.rsk.scoring.PeerScoringInformation) Test(org.junit.Test)

Aggregations

PeerScoringInformation (co.rsk.scoring.PeerScoringInformation)2 PeerScoringManager (co.rsk.scoring.PeerScoringManager)2 Test (org.junit.Test)2 NodeID (co.rsk.net.NodeID)1 InetAddress (java.net.InetAddress)1