use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method failIfProcessBlockHeadersRequestCountHigher.
@Test
public void failIfProcessBlockHeadersRequestCountHigher() {
final Peer sender = mock(Peer.class);
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
store.saveBlock(block);
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final Integer size = syncConfiguration.getChunkSize() + 1;
processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), size);
verify(sender, never()).sendMessage(any());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.
@Test
public void processGetBlockHeaderMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
store.saveBlock(block);
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
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());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockMessageUsingBlockInBlockchain.
@Test
public void processGetBlockMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
final Keccak256 blockHash = block.getHash();
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_MESSAGE, message.getMessageType());
final BlockMessage bMessage = (BlockMessage) message;
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTwoBlockListsAddingToBlockchainWithFork.
@Test
public void processTwoBlockListsAddingToBlockchainWithFork() {
NetBlockStore store = new NetBlockStore();
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
Block genesis = blockchain.getBestBlock();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
List<Block> blocks2 = blockGenerator.getBlockChain(blocks.get(4), 20);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
for (Block b : blocks2) processor.processBlock(null, b);
Assert.assertEquals(25, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method noSyncingWithEmptyBlockchainAndLowBestBlock.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void noSyncingWithEmptyBlockchainAndLowBestBlock() {
NetBlockStore store = new NetBlockStore();
Block block = new BlockGenerator().createBlock(10, 0);
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertFalse(processor.hasBetterBlockToSync());
Status status = new Status(block.getNumber(), block.getHash().getBytes());
// processor.processStatus(new SimpleNodeChannel(null, null), status);
Assert.assertFalse(processor.hasBetterBlockToSync());
}
Aggregations