use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHashRequestMessageUsingEmptyStore.
@Test
public void processBlockHashRequestMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final Keccak256 blockHash = block.getHash();
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();
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
processor.processBlockRequest(sender, 100, block.getHash().getBytes());
Assert.assertFalse(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTwoBlockListsAddingToBlockchain.
@Test
public void processTwoBlockListsAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
List<Block> blocks2 = blockGenerator.getBlockChain(genesis, 20);
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, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
for (Block b : blocks2) processor.processBlock(null, b);
Assert.assertEquals(20, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processSkeletonRequestWithThreeResults.
@Test
public void processSkeletonRequestWithThreeResults() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(300);
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.processSkeletonRequest(sender, 100, 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block b1 = blockchain.getBlockByNumber(0);
Block b2 = blockchain.getBlockByNumber(skeletonStep);
Block b3 = blockchain.getBestBlock();
BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusHavingBestBlockAsBestBlockInBlockchain.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockAsBestBlockInBlockchain() throws UnknownHostException {
final BlockStore store = new BlockStore();
final Blockchain blockchain = BlockChainBuilder.ofSize(2);
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();
final Block block = blockchain.getBestBlock();
final Keccak256 blockHash = block.getHash();
// final Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(sender, status);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
Assert.assertEquals(0, sender.getGetBlockMessages().size());
Assert.assertEquals(0, store.size());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHeadersRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(100);
final Block block = blockchain.getBlockByNumber(60);
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.processBlockHeadersRequest(sender, 100, block.getHash().getBytes(), 20);
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 response = (BlockHeadersResponseMessage) message;
Assert.assertEquals(100, response.getId());
Assert.assertNotNull(response.getBlockHeaders());
Assert.assertEquals(20, response.getBlockHeaders().size());
for (int k = 0; k < 20; k++) Assert.assertEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
Aggregations