Search in sources :

Example 31 with SimplePeer

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());
    }
}
Also used : Blockchain(org.ethereum.core.Blockchain) 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 32 with SimplePeer

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) 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)

Example 33 with SimplePeer

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) 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)

Example 34 with SimplePeer

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());
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 35 with SimplePeer

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));
}
Also used : SimplePeer(co.rsk.net.simples.SimplePeer) PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BigInteger(java.math.BigInteger) 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