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();
}
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());
}
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());
}
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());
}
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());
}
Aggregations