use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockHeadersRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(100);
final Block block = blockchain.getBlockByNumber(60);
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
processor.processBlockHeadersRequest(sender, 100, block.getHash().getBytes(), 20);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());
final BlockHeadersResponseMessage response = (BlockHeadersResponseMessage) message;
Assert.assertEquals(100, response.getId());
Assert.assertNotNull(response.getBlockHeaders());
Assert.assertEquals(20, response.getBlockHeaders().size());
for (int k = 0; k < 20; k++) {
Assert.assertEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processGetBlockMessageUsingEmptyStore.
@Test
public void processGetBlockMessageUsingEmptyStore() {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
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 AsyncNodeBlockProcessorTest method processBlockHashRequestMessageUsingEmptyStore.
@Test
public void processBlockHashRequestMessageUsingEmptyStore() {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processBlockRequest(sender, 100, block.getHash().getBytes());
Assert.assertFalse(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.simples.SimplePeer 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.SimplePeer in project rskj by rsksmart.
the class NodeMessageHandlerTest method processTooMuchGasTransactionMessage.
@Test
public void processTooMuchGasTransactionMessage() throws UnknownHostException {
PeerScoringManager scoring = createPeerScoringManager();
final SimpleChannelManager channelManager = new SimpleChannelManager();
TransactionGateway transactionGateway = mock(TransactionGateway.class);
BlockProcessor blockProcessor = mock(BlockProcessor.class);
Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, transactionGateway, scoring, mock(StatusResolver.class));
final SimplePeer sender = new SimplePeer();
final List<Transaction> txs = new ArrayList<>();
BigInteger value = BigInteger.ONE;
BigInteger nonce = BigInteger.ZERO;
BigInteger gasPrice = BigInteger.ONE;
BigInteger gasLimit = BigDecimal.valueOf(Math.pow(2, 60)).add(BigDecimal.ONE).toBigInteger();
txs.add(TransactionUtils.createTransaction(TransactionUtils.getPrivateKeyBytes(), TransactionUtils.getAddress(), value, nonce, gasPrice, gasLimit));
final TransactionsMessage message = new TransactionsMessage(txs);
handler.processMessage(sender, message);
Assert.assertNotNull(channelManager.getTransactions());
Assert.assertEquals(0, channelManager.getTransactions().size());
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
// besides this
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_TRANSACTION));
}
Aggregations