use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockMessageUsingEmptyStore.
@Test
public void processGetBlockMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusRetrievingBestBlockUsingSender.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusRetrievingBestBlockUsingSender() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
BlockGenerator blockGenerator = new BlockGenerator();
final Block genesis = blockGenerator.getGenesisBlock();
final Block block = blockGenerator.createChildBlock(genesis);
// final Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(sender, status);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
Assert.assertEquals(1, sender.getGetBlockMessages().size());
final Message message = sender.getGetBlockMessages().get(0);
Assert.assertNotNull(message);
Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, message.getMessageType());
final GetBlockMessage gbMessage = (GetBlockMessage) message;
Assert.assertArrayEquals(block.getHash().getBytes(), gbMessage.getBlockHash());
Assert.assertEquals(0, store.size());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processMissingPoWBlockMessageUsingProcessor.
@Test
public void processMissingPoWBlockMessageUsingProcessor() 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));
BlockGenerator blockGenerator = new BlockGenerator();
Block block = blockGenerator.getGenesisBlock();
for (int i = 0; i < 50; i++) {
block = blockGenerator.createChildBlock(block);
}
Message message = new BlockMessage(block);
processor.processMessage(sender, message);
Assert.assertNotNull(sbp.getBlocks());
Assert.assertEquals(1, sbp.getBlocks().size());
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
Assert.assertEquals(0, pscoring.getEventCounter(EventType.INVALID_BLOCK));
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method postBlockMessageFromNonBannedMiner.
@Test
public void postBlockMessageFromNonBannedMiner() {
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 coinbase = block.getCoinbase();
RskAddress bannedMiner = new RskAddress("0000000000000000000000000000000000000023");
Assert.assertNotEquals(coinbase, bannedMiner);
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(1, nodeMessageHandler.getMessageQueueSize());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processInvalidPoWMessageUsingProcessor.
// TODO: Difficulty in RegTest is so small that this test will sometimes pass and other times fail
// This should be executed in a special mode where difficulty is high.
@Ignore
public void processInvalidPoWMessageUsingProcessor() 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 BlockChainBuilder().ofSize(1, true).getBestBlock();
byte[] mergedMiningHeader = block.getBitcoinMergedMiningHeader();
// change merged mining nonce.
mergedMiningHeader[76] += 3;
Message message = new BlockMessage(block);
processor.processMessage(sender, message);
Assert.assertNotNull(sbp.getBlocks());
Assert.assertEquals(0, sbp.getBlocks().size());
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.INVALID_BLOCK));
}
Aggregations