Search in sources :

Example 1 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor in project rskj by rsksmart.

the class NodeMessageHandlerTest method skipProcessGenesisBlock.

@Test
public void skipProcessGenesisBlock() throws UnknownHostException {
    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 BlockGenerator().getGenesisBlock();
    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());
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 2 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor in project rskj by rsksmart.

the class NodeMessageHandlerTest method postBlockMessageUsingProcessor.

@Test
public void postBlockMessageUsingProcessor() throws InterruptedException, UnknownHostException {
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, mock(StatusResolver.class));
    Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    processor.start();
    processor.postMessage(new SimplePeer(), message);
    Thread.sleep(1000);
    processor.stop();
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(1, sbp.getBlocks().size());
    Assert.assertSame(block, sbp.getBlocks().get(0));
}
Also used : SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 3 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor 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());
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 4 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor 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());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimplePeer(co.rsk.net.simples.SimplePeer) RskAddress(co.rsk.core.RskAddress) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RskSystemProperties(co.rsk.config.RskSystemProperties) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 5 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor in project rskj by rsksmart.

the class Web3ImplTest method eth_syncing_returnSyncingResultWhenSyncing.

@Test
public void eth_syncing_returnSyncingResultWhenSyncing() {
    World world = new World();
    SimpleBlockProcessor nodeProcessor = new SimpleBlockProcessor();
    Web3Impl web3 = createWeb3(world, nodeProcessor, null);
    doReturn(true).when(syncProcessor).isSyncing();
    doReturn(5L).when(syncProcessor).getHighestBlockNumber();
    Object result = web3.eth_syncing();
    assertTrue("Node is syncing, must return sync manager", result instanceof SyncingResult);
    assertEquals("Highest block is 5", 0, ((SyncingResult) result).getHighestBlock().compareTo("0x5"));
    assertEquals("Simple blockchain starts from genesis block", 0, ((SyncingResult) result).getCurrentBlock().compareTo("0x0"));
}
Also used : SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) World(co.rsk.test.World) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)14 Test (org.junit.Test)13 SimplePeer (co.rsk.net.simples.SimplePeer)12 PeerScoringManager (co.rsk.scoring.PeerScoringManager)8 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)7 PeerScoring (co.rsk.scoring.PeerScoring)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 RskSystemProperties (co.rsk.config.RskSystemProperties)2 RskAddress (co.rsk.core.RskAddress)2 World (co.rsk.test.World)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Ignore (org.junit.Ignore)1