Search in sources :

Example 26 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class SyncProcessorTest method noPeers.

@Test
public void noPeers() {
    final NetBlockStore store = new NetBlockStore();
    Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final EthereumListener listener = mock(EthereumListener.class);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, getPeerScoringManager()), mock(Genesis.class), listener);
    Assert.assertEquals(0, processor.getPeersCount());
    Assert.assertEquals(0, processor.getNoAdvancedPeers());
    Assert.assertTrue(processor.getKnownPeersNodeIDs().isEmpty());
    verify(listener, never()).onLongSyncStarted();
    verify(listener, never()).onLongSyncDone();
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 27 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class SyncProcessorTest method processBlockHeadersResponseWithEmptyList.

@Test
public void processBlockHeadersResponseWithEmptyList() {
    Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, new NetBlockStore(), blockchain, new BlockNodeInformation(), syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    List<BlockHeader> headers = new ArrayList<>();
    BlockHeadersResponseMessage response = new BlockHeadersResponseMessage(new Random().nextLong(), headers);
    processor.registerExpectedMessage(response);
    processor.processBlockHeadersResponse(sender, response);
    Assert.assertEquals(0, sender.getMessages().size());
    Assert.assertEquals(0, processor.getExpectedResponses().size());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 28 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class SyncProcessorTest method processBlockResponseAddsToBlockchain.

@Test
public void processBlockResponseAddsToBlockchain() {
    final NetBlockStore store = new NetBlockStore();
    Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
    Assert.assertEquals(11, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    BlockResponseMessage response = new BlockResponseMessage(new Random().nextLong(), block);
    processor.registerExpectedMessage(response);
    processor.processBlockResponse(sender, response);
    Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 29 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class SyncProcessorTest method processBodyResponseRejectsNonSolicitedMessages.

@Test
public void processBodyResponseRejectsNonSolicitedMessages() {
    Blockchain blockchain = new BlockChainBuilder().ofSize(3);
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, new NetBlockStore(), blockchain, new BlockNodeInformation(), syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    BodyResponseMessage response = new BodyResponseMessage(new Random().nextLong(), null, null);
    processor.registerExpectedMessage(response);
    processor.processBodyResponse(sender, response);
    Assert.assertTrue(sender.getMessages().isEmpty());
    Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 30 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class SyncProcessorTest method findConnectionPointBlockchainWith30BlocksVsBlockchainWith100Blocks.

@Test
public void findConnectionPointBlockchainWith30BlocksVsBlockchainWith100Blocks() {
    BlockChainBuilder builder = new BlockChainBuilder();
    Blockchain blockchain = builder.ofSize(30);
    org.ethereum.db.BlockStore blockStore = builder.getBlockStore();
    Blockchain advancedBlockchain = BlockChainBuilder.copyAndExtend(blockchain, 70);
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    final ChannelManager channelManager = mock(ChannelManager.class);
    when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(sender));
    NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, blockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(channelManager, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    Status status = StatusUtils.fromBlockchain(advancedBlockchain);
    processor.processStatus(sender, status);
    List<Message> messages = sender.getMessages();
    BlockHeadersRequestMessage requestMessage = (BlockHeadersRequestMessage) messages.get(0);
    processor.processBlockHeadersResponse(sender, new BlockHeadersResponseMessage(requestMessage.getId(), Collections.singletonList(advancedBlockchain.getBestBlock().getHeader())));
    long[] binarySearchHeights = new long[] { 50, 25, 37, 31, 28, 29, 30, 30 };
    for (int k = 0; k < binarySearchHeights.length; k++) {
        Assert.assertEquals(k + 2, messages.size());
        Message message = messages.get(k + 1);
        Assert.assertEquals(MessageType.BLOCK_HASH_REQUEST_MESSAGE, message.getMessageType());
        BlockHashRequestMessage request = (BlockHashRequestMessage) message;
        long requestId = request.getId();
        Assert.assertEquals(binarySearchHeights[k], request.getHeight());
        Block block = advancedBlockchain.getBlockByNumber(binarySearchHeights[k]);
        processor.processBlockHashResponse(sender, new BlockHashResponseMessage(requestId, block.getHash().getBytes()));
    }
    Assert.assertEquals(binarySearchHeights.length + 2, messages.size());
    Message message = messages.get(messages.size() - 1);
    Assert.assertEquals(MessageType.SKELETON_REQUEST_MESSAGE, message.getMessageType());
    SkeletonRequestMessage request = (SkeletonRequestMessage) message;
    Assert.assertEquals(30, request.getStartNumber());
    Assert.assertEquals(1, processor.getExpectedResponses().size());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ChannelManager(org.ethereum.net.server.ChannelManager) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Aggregations

TestSystemProperties (co.rsk.config.TestSystemProperties)158 Test (org.junit.Test)130 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)109 Blockchain (org.ethereum.core.Blockchain)78 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)75 SimplePeer (co.rsk.net.simples.SimplePeer)69 Block (org.ethereum.core.Block)69 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)56 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)23 EthereumListener (org.ethereum.listener.EthereumListener)23 BlockStore (org.ethereum.db.BlockStore)21 RskSystemProperties (co.rsk.config.RskSystemProperties)17 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)16 Keccak256 (co.rsk.crypto.Keccak256)13 RepositoryLocator (co.rsk.db.RepositoryLocator)10 World (co.rsk.test.World)10 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)9 Ignore (org.junit.Ignore)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)8