use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBodyRequestMessageUsingBlockInBlockchain.
@Test
public void processBodyRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(10);
final Block block = blockchain.getBlockByNumber(3);
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
processor.processBodyRequest(sender, 100, block.getHash().getBytes());
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BODY_RESPONSE_MESSAGE, message.getMessageType());
final BodyResponseMessage bMessage = (BodyResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Assert.assertEquals(block.getTransactionsList(), bMessage.getTransactions());
Assert.assertEquals(block.getUncleList(), bMessage.getUncles());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusHavingBestBlockInStore.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockInStore() throws UnknownHostException {
final BlockStore store = new BlockStore();
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
BlockGenerator blockGenerator = new BlockGenerator();
final Block genesis = blockGenerator.getGenesisBlock();
final Block block = blockGenerator.createChildBlock(genesis);
store.saveBlock(block);
// final Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(sender, status);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
Assert.assertEquals(1, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockAddingToBlockchain.
@Test
public void processBlockAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(10);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
BlockStore store = new BlockStore();
Block genesis = blockchain.getBlockByNumber(0);
store.saveBlock(genesis);
Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
Assert.assertEquals(11, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, block);
Assert.assertFalse(store.hasBlock(block));
Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertEquals(1, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method noSyncingWithEmptyBlockchain.
@Test
public void noSyncingWithEmptyBlockchain() {
BlockStore store = new BlockStore();
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertFalse(processor.hasBetterBlockToSync());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method canBeIgnoredForUncles.
@Test
public void canBeIgnoredForUncles() throws UnknownHostException {
final BlockStore store = new BlockStore();
final MessageChannel sender = new SimpleMessageChannel();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final Blockchain blockchain = BlockChainBuilder.ofSize(15);
final RskSystemProperties config = new RskSystemProperties();
int uncleGenerationLimit = config.getBlockchainConfig().getCommonConstants().getUncleGenerationLimit();
final long blockNumberThatCanBeIgnored = blockchain.getBestBlock().getNumber() - 1 - uncleGenerationLimit;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertTrue(processor.canBeIgnoredForUnclesRewards(blockNumberThatCanBeIgnored));
Assert.assertFalse(processor.canBeIgnoredForUnclesRewards(blockNumberThatCanBeIgnored + 1));
}
Aggregations