use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.
@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(skeletonStep / 2);
final Block blockStart = blockchain.getBlockByNumber(5);
final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
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 genesis = blockchain.getBlockByNumber(0);
Block bestBlock = blockchain.getBestBlock();
BlockIdentifier[] expected = { new BlockIdentifier(genesis.getHash().getBytes(), genesis.getNumber()), new BlockIdentifier(bestBlock.getHash().getBytes(), bestBlock.getNumber()) };
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockAddingToBlockchainUsingItsParent.
@Test
public void processBlockAddingToBlockchainUsingItsParent() {
BlockStore store = new BlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
store.saveBlock(genesis);
Blockchain blockchain = BlockChainBuilder.ofSize(10);
Block parent = blockGenerator.createChildBlock(blockchain.getBlockByNumber(10));
Block block = blockGenerator.createChildBlock(parent);
Assert.assertEquals(11, parent.getNumber());
Assert.assertEquals(12, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), parent.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.assertTrue(store.hasBlock(block));
Assert.assertNull(blockchain.getBlockByHash(block.getHash().getBytes()));
processor.processBlock(null, parent);
Assert.assertFalse(store.hasBlock(block));
Assert.assertFalse(store.hasBlock(parent));
Assert.assertEquals(12, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertEquals(1, store.size());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockWithTooMuchHeight.
@Test
public void processBlockWithTooMuchHeight() throws UnknownHostException {
final BlockStore store = new BlockStore();
final MessageChannel sender = new SimpleMessageChannel();
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
final Block orphan = new BlockGenerator().createBlock(1000, 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);
processor.processBlock(sender, orphan);
Assert.assertFalse(processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size() == 1);
Assert.assertFalse(store.hasBlock(orphan));
Assert.assertEquals(0, store.size());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.
@Test
public void processSkeletonRequestNotIncludingGenesis() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(400);
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, skeletonStep + 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(skeletonStep);
Block b2 = blockchain.getBlockByNumber(2 * 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 processTenBlocksInverseOrderAddingToBlockchain.
@Test
public void processTenBlocksInverseOrderAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
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);
for (int k = 0; k < 10; k++) processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
Aggregations