use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method refreshWorkRunOnce.
@Test
public void refreshWorkRunOnce() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
MinerClientImpl.RefreshWork refreshWork = minerClient.createRefreshWork();
Assert.assertNotNull(refreshWork);
try {
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
refreshWork.run();
Assert.assertTrue(minerClient.mineBlock());
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
} finally {
refreshWork.cancel();
}
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessageAndAddItToBlockchainWithCommonAncestors.
@Test
public void sendBlockMessageAndAddItToBlockchainWithCommonAncestors() {
Blockchain blockchain = BlockChainBuilder.ofSize(10);
BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Block initialBestBlock = blockchain.getBestBlock();
Assert.assertEquals(10, initialBestBlock.getNumber());
Block branchingPoint = blockchain.getBlockByNumber(7);
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> extendedChain = blockGenerator.getBlockChain(branchingPoint, 10, 1000000l);
// we have just surpassed the best branch
for (int i = 0; i < extendedChain.size(); i++) {
Block newBestBlock = extendedChain.get(i);
blockSyncService.processBlock(newBestBlock, null, false);
Assert.assertEquals(newBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(newBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessagesAndAddThemToBlockchain.
@Test
public void sendBlockMessagesAndAddThemToBlockchain() {
for (int i = 0; i < 50; i += 5) {
Blockchain blockchain = BlockChainBuilder.ofSize(10 * i);
BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(10 * i, blockchain.getBestBlock().getNumber());
List<Block> extendedChain = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), i);
for (Block block : extendedChain) {
blockSyncService.processBlock(block, null, false);
Assert.assertEquals(block.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(block.getHash(), blockchain.getBestBlock().getHash());
}
}
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockMessageUsingEmptyStore.
@Test
public void processGetBlockMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
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.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHashRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHashRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
final Keccak256 blockHash = block.getHash();
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();
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
processor.processBlockRequest(sender, 100, 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_RESPONSE_MESSAGE, message.getMessageType());
final BlockResponseMessage bMessage = (BlockResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
Aggregations