use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method mineBlockWhilePlayingBlocks.
@Test
public void mineBlockWhilePlayingBlocks() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
RskImplForTest rsk = new RskImplForTest() {
@Override
public boolean hasBetterBlockToSync() {
return false;
}
@Override
public boolean isPlayingBlocks() {
return true;
}
};
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(rsk, minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
Assert.assertFalse(minerClient.mineBlock());
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method doWork.
@Test
public void doWork() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
minerClient.doWork();
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method doWorkInThread.
@Test
public void doWorkInThread() throws Exception {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
Thread thread = minerClient.createDoWorkThread();
thread.start();
try {
Awaitility.await().timeout(Duration.FIVE_SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return minerClient.isMining();
}
});
Assert.assertTrue(minerClient.isMining());
} finally {
// enought ?
thread.interrupt();
minerClient.stop();
}
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method doWorkEvenWithoutMinerServer.
@Test
public void doWorkEvenWithoutMinerServer() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(null);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
minerClient.doWork();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BlockSyncServiceTest method sendBlockMessagesAndAddThemToBlockchainInReverseOrder.
@Test
public void sendBlockMessagesAndAddThemToBlockchainInReverseOrder() {
for (int i = 1; i < 52; 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());
Block initialBestBlock = blockchain.getBestBlock();
List<Block> extendedChain = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), i);
Collections.reverse(extendedChain);
for (int j = 0; j < extendedChain.size() - 1; j++) {
Block block = extendedChain.get(j);
blockSyncService.processBlock(block, null, false);
// we don't have all the parents, so we wait to update the best chain
Assert.assertEquals(initialBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(initialBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
// the chain is complete, we have a new best block
Block closingBlock = extendedChain.get(extendedChain.size() - 1);
Block newBestBlock = extendedChain.get(0);
blockSyncService.processBlock(closingBlock, null, false);
Assert.assertEquals(newBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertEquals(newBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
}
Aggregations