use of co.rsk.test.builders.BlockChainBuilder 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 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();
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.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockRetrievingParentUsingSender.
@Test
public void processBlockRetrievingParentUsingSender() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
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();
BlockGenerator blockGenerator = new BlockGenerator();
final Block genesis = blockGenerator.getGenesisBlock();
final Block parent = blockGenerator.createChildBlock(genesis);
final Block block = blockGenerator.createChildBlock(parent);
processor.processBlock(sender, block);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
Assert.assertTrue(store.hasBlock(block));
Assert.assertEquals(1, sender.getMessages().size());
Assert.assertEquals(1, store.size());
final Message message = sender.getMessages().get(0);
Assert.assertNotNull(message);
Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, message.getMessageType());
final GetBlockMessage gbMessage = (GetBlockMessage) message;
Assert.assertArrayEquals(block.getParentHash().getBytes(), gbMessage.getBlockHash());
}
use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method syncingThenNoSyncing.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingThenNoSyncing() {
NetBlockStore store = new NetBlockStore();
Block block = new BlockGenerator().createBlock(30, 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());
// processor.processStatus(new SimpleNodeChannel(null, null), status);
Assert.assertTrue(processor.hasBetterBlockToSync());
Assert.assertTrue(processor.hasBetterBlockToSync());
blockchain.setStatus(block, 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.test.builders.BlockChainBuilder 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 NetBlockStore store = new NetBlockStore();
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();
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.test.builders.BlockChainBuilder in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusHavingBestBlockInBlockchainStore.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockInBlockchainStore() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(2);
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();
final Block block = blockchain.getBlockByNumber(1);
final Keccak256 blockHash = block.getHash();
store.saveBlock(block);
// final Status status = new Status(block.getNumber(), block.getHash());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
// processor.processStatus(sender, status);
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertEquals(0, sender.getGetBlockMessages().size());
}
Aggregations