use of co.rsk.blockchain.utils.BlockGenerator 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.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method syncingWithEmptyBlockchainAndHighBestBlock.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingWithEmptyBlockchainAndHighBestBlock() {
BlockStore store = new BlockStore();
Block block = new BlockGenerator().createBlock(30, 0);
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());
// Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(new SimpleNodeChannel(null, null), status);
Assert.assertTrue(processor.hasBetterBlockToSync());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method syncingThenNoSyncing.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingThenNoSyncing() {
BlockStore store = new BlockStore();
Block block = new BlockGenerator().createBlock(30, 0);
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());
// Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(new SimpleNodeChannel(null, null), status);
Assert.assertTrue(processor.hasBetterBlockToSync());
Assert.assertTrue(processor.hasBetterBlockToSync());
blockchain.setBestBlock(block);
blockchain.setTotalDifficulty(new BlockDifficulty(BigInteger.valueOf(30)));
Assert.assertFalse(processor.hasBetterBlockToSync());
Assert.assertFalse(processor.hasBetterBlockToSync());
Block block2 = new BlockGenerator().createBlock(60, 0);
// Status status2 = new Status(block2.getNumber(), block2.getHash());
// processor.processStatus(new SimpleNodeChannel(null, null), status2);
Assert.assertTrue(processor.hasBetterBlockToSync());
Assert.assertFalse(processor.hasBetterBlockToSync());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.
@Test
public void processGetBlockHeaderMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final BlockStore store = new BlockStore();
store.saveBlock(block);
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();
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.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockMessageUsingBlockInStore.
@Test
public void processGetBlockMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final Keccak256 blockHash = block.getHash();
final BlockStore store = new BlockStore();
store.saveBlock(block);
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();
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
processor.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
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());
}
Aggregations