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());
}
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));
}
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());
}
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());
}
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"));
}
Aggregations