Search in sources :

Example 1 with SimpleTransactionPool

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

the class NodeMessageHandlerTest method processTransactionsMessageUsingTransactionPool.

@Test
public void processTransactionsMessageUsingTransactionPool() throws UnknownHostException {
    final SimpleTransactionPool transactionPool = new SimpleTransactionPool();
    final SimpleChannelManager channelManager = new SimpleChannelManager();
    TxHandler txmock = mock(TxHandler.class);
    BlockProcessor blockProcessor = mock(BlockProcessor.class);
    Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
    final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, transactionPool, txmock, RskMockFactory.getPeerScoringManager(), new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    sender.setPeerNodeID(new NodeID(new byte[] { 1 }));
    final SimpleMessageChannel sender2 = new SimpleMessageChannel();
    sender2.setPeerNodeID(new NodeID(new byte[] { 2 }));
    final List<Transaction> txs = TransactionUtils.getTransactions(10);
    Mockito.when(txmock.retrieveValidTxs(any(List.class))).thenReturn(txs);
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Assert.assertNotNull(channelManager.getTransactions());
    Assert.assertEquals(10, channelManager.getTransactions().size());
    for (int k = 0; k < 10; k++) Assert.assertSame(txs.get(k), channelManager.getTransactions().get(k));
    Assert.assertNotNull(channelManager.getLastSkip());
    Assert.assertEquals(1, channelManager.getLastSkip().size());
    Assert.assertTrue(channelManager.getLastSkip().contains(sender.getPeerNodeID()));
    channelManager.setLastSkip(null);
    handler.processMessage(sender2, message);
    Assert.assertNull(channelManager.getLastSkip());
}
Also used : TxHandler(co.rsk.net.handler.TxHandler) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) SimpleTransactionPool(co.rsk.net.simples.SimpleTransactionPool) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) Test(org.junit.Test)

Aggregations

TxHandler (co.rsk.net.handler.TxHandler)1 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)1 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)1 SimpleTransactionPool (co.rsk.net.simples.SimpleTransactionPool)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)1 Test (org.junit.Test)1