use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.
the class NodeMessageHandlerTest method processTransactionsMessage.
@Test
public void processTransactionsMessage() throws UnknownHostException {
PeerScoringManager scoring = createPeerScoringManager();
final SimpleChannelManager channelManager = new SimpleChannelManager();
TxHandler txmock = mock(TxHandler.class);
TransactionPool state = mock(TransactionPool.class);
Mockito.when(state.addTransactions(any())).thenAnswer(i -> i.getArguments()[0]);
BlockProcessor blockProcessor = mock(BlockProcessor.class);
Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, state, txmock, scoring, 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()));
handler.processMessage(sender2, message);
Assert.assertNotNull(channelManager.getLastSkip());
Assert.assertEquals(2, channelManager.getLastSkip().size());
Assert.assertTrue(channelManager.getLastSkip().contains(sender.getPeerNodeID()));
Assert.assertTrue(channelManager.getLastSkip().contains(sender2.getPeerNodeID()));
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(10, pscoring.getTotalEventCounter());
Assert.assertEquals(10, pscoring.getEventCounter(EventType.VALID_TRANSACTION));
pscoring = scoring.getPeerScoring(sender2.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
Assert.assertEquals(10, pscoring.getTotalEventCounter());
Assert.assertEquals(10, pscoring.getEventCounter(EventType.VALID_TRANSACTION));
}
use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.
the class OneAsyncNodeTest method createNode.
private static SimpleAsyncNode createNode() {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
RskSystemProperties config = new RskSystemProperties();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
SimpleChannelManager channelManager = new SimpleChannelManager();
SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), channelManager, syncConfiguration, new DummyBlockValidationRule(), new DifficultyCalculator(config));
NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, RskMockFactory.getPeerScoringManager(), new DummyBlockValidationRule());
return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
Aggregations