use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class SyncProcessorTest method processBlockHeadersResponseRejectsNonSolicitedMessages.
@Test
public void processBlockHeadersResponseRejectsNonSolicitedMessages() {
Blockchain blockchain = new BlockChainBuilder().ofSize(3);
Block block = blockchain.getBlockByNumber(2);
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<>();
headers.add(block.getHeader());
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 processSkeletonResponseWithoutBlockIdentifiers.
@Test
public void processSkeletonResponseWithoutBlockIdentifiers() {
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<BlockIdentifier> blockIdentifiers = new ArrayList<>();
SkeletonResponseMessage response = new SkeletonResponseMessage(new Random().nextLong(), blockIdentifiers);
processor.registerExpectedMessage(response);
processor.processSkeletonResponse(sender, response);
Assert.assertFalse(processor.isSyncing());
Assert.assertTrue(sender.getMessages().isEmpty());
Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method noSyncingWithEmptyBlockchain.
@Test
public void noSyncingWithEmptyBlockchain() {
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);
Assert.assertFalse(processor.hasBetterBlockToSync());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method advancedBlock.
@Test
public void advancedBlock() {
final NetBlockStore store = new NetBlockStore();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final long advancedBlockNumber = syncConfiguration.getChunkSize() * syncConfiguration.getMaxSkeletonChunks() + blockchain.getBestBlock().getNumber() + 1;
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);
Assert.assertTrue(processor.isAdvancedBlock(advancedBlockNumber));
Assert.assertFalse(processor.isAdvancedBlock(advancedBlockNumber - 1));
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessagesAndAddThemToBlockchain.
@Test
public void sendBlockMessagesAndAddThemToBlockchain() {
for (int i = 0; i < 50; i += 5) {
Blockchain blockchain = new BlockChainBuilder().ofSize(10 * i);
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);
Assert.assertEquals(10 * i, blockchain.getBestBlock().getNumber());
List<Block> extendedChain = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), i);
for (Block block : extendedChain) {
blockSyncService.processBlock(block, null, false);
Assert.assertEquals(block.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(block.getHash(), blockchain.getBestBlock().getHash());
}
}
}
Aggregations