Search in sources :

Example 36 with SimplePeer

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

the class NodeMessageHandlerTest method processTransactionsMessageUsingTransactionPool.

@Test
public void processTransactionsMessageUsingTransactionPool() throws UnknownHostException {
    TransactionGateway transactionGateway = mock(TransactionGateway.class);
    BlockProcessor blockProcessor = mock(BlockProcessor.class);
    Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
    final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, null, transactionGateway, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
    final SimplePeer sender = new SimplePeer(new NodeID(new byte[] { 1 }));
    final SimplePeer sender2 = new SimplePeer(new NodeID(new byte[] { 2 }));
    final List<Transaction> txs = TransactionUtils.getTransactions(10);
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Mockito.verify(transactionGateway, times(1)).receiveTransactionsFrom(txs, Collections.singleton(sender.getPeerNodeID()));
    handler.processMessage(sender2, message);
    Mockito.verify(transactionGateway, times(1)).receiveTransactionsFrom(txs, Collections.singleton(sender2.getPeerNodeID()));
}
Also used : SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 37 with SimplePeer

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

the class NodeMessageHandlerTest method processRejectedTransactionsMessage.

@Test
public void processRejectedTransactionsMessage() 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 = TransactionUtils.getTransactions(0);
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Assert.assertNotNull(channelManager.getTransactions());
    Assert.assertEquals(0, channelManager.getTransactions().size());
    Assert.assertTrue(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertTrue(pscoring.isEmpty());
    Assert.assertEquals(0, pscoring.getTotalEventCounter());
    Assert.assertEquals(0, pscoring.getEventCounter(EventType.INVALID_TRANSACTION));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 38 with SimplePeer

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

the class AsyncNodeBlockProcessorTest method invalidBlock.

@Test
public void invalidBlock() {
    final NetBlockStore store = new NetBlockStore();
    final Peer sender = new SimplePeer();
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    final BlockGenerator blockGenerator = new BlockGenerator();
    final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
    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.INVALID_RESULT_INSTANCE, DummyBlockValidator.INVALID_RESULT_INSTANCE);
    BlockProcessResult blockProcessResult = processor.processBlock(sender, block);
    Assert.assertFalse(blockProcessResult.isScheduledForProcessing());
    Assert.assertFalse(blockProcessResult.wasBlockAdded(block));
    Assert.assertTrue(blockProcessResult.isInvalidBlock());
}
Also used : SimplePeer(co.rsk.net.simples.SimplePeer) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 39 with SimplePeer

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

the class AsyncNodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.

@Test
public void processGetBlockHeaderMessageUsingBlockInStore() {
    final Block block = new BlockGenerator().getBlock(3);
    final NetBlockStore store = new NetBlockStore();
    store.saveBlock(block);
    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();
    processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
    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 bMessage = (BlockHeadersResponseMessage) message;
    Assert.assertEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 40 with SimplePeer

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

the class AsyncNodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInBlockchain.

@Test
public void processGetBlockHeaderMessageUsingBlockInBlockchain() {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    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, 1, block.getHash().getBytes(), 1);
    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 bMessage = (BlockHeadersResponseMessage) message;
    Assert.assertEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Aggregations

SimplePeer (co.rsk.net.simples.SimplePeer)109 Test (org.junit.Test)108 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)81 TestSystemProperties (co.rsk.config.TestSystemProperties)68 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)54 Blockchain (org.ethereum.core.Blockchain)49 Block (org.ethereum.core.Block)46 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)41 BlockStore (org.ethereum.db.BlockStore)28 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)26 EthereumListener (org.ethereum.listener.EthereumListener)26 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)19 PeerScoringManager (co.rsk.scoring.PeerScoringManager)16 Keccak256 (co.rsk.crypto.Keccak256)13 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)13 ChannelManager (org.ethereum.net.server.ChannelManager)11 PeerScoring (co.rsk.scoring.PeerScoring)10 World (co.rsk.test.World)8 Ignore (org.junit.Ignore)7 BlockBuilder (co.rsk.test.builders.BlockBuilder)6