use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method refreshWorkRunTwice.
@Test
public void refreshWorkRunTwice() {
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());
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
refreshWork.run();
Assert.assertTrue(minerClient.mineBlock());
Assert.assertEquals(2, blockchain.getBestBlock().getNumber());
} finally {
refreshWork.cancel();
}
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method mineBlockWhileSyncingBlocks.
@Test
public void mineBlockWhileSyncingBlocks() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
RskImplForTest rsk = new RskImplForTest() {
@Override
public boolean hasBetterBlockToSync() {
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 mineBlockTwiceReusingTheSameWork.
@Test
public void mineBlockTwiceReusingTheSameWork() {
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);
MinerWork minerWork = minerServer.getWork();
Assert.assertNotNull(minerWork);
Assert.assertTrue(minerClient.mineBlock());
Block bestBlock = blockchain.getBestBlock();
Assert.assertNotNull(bestBlock);
Assert.assertEquals(1, bestBlock.getNumber());
// reuse the same work
Assert.assertNotNull(minerServer.getWork());
Assert.assertTrue(minerClient.mineBlock());
List<Block> blocks = blockchain.getBlocksByNumber(1);
Assert.assertNotNull(blocks);
Assert.assertEquals(2, blocks.size());
Assert.assertFalse(blocks.get(0).getHash().equals(blocks.get(1).getHash()));
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method mineBlock.
@Test
public void mineBlock() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerManager manager = new MinerManager();
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
manager.mineBlock(blockchain, minerClient, minerServer);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertFalse(blockchain.getBestBlock().getTransactionsList().isEmpty());
SnapshotManager snapshotManager = new SnapshotManager();
snapshotManager.resetSnapshots(blockchain);
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
manager.mineBlock(blockchain, minerClient, minerServer);
manager.mineBlock(blockchain, minerClient, minerServer);
Assert.assertEquals(2, blockchain.getBestBlock().getNumber());
snapshotManager.resetSnapshots(blockchain);
Assert.assertTrue(blockchain.getTransactionPool().getPendingTransactions().isEmpty());
manager.mineBlock(blockchain, minerClient, minerServer);
Assert.assertTrue(blockchain.getTransactionPool().getPendingTransactions().isEmpty());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class MinerManagerTest method mineBlockUsingTimeTravel.
@Test
public void mineBlockUsingTimeTravel() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerManager manager = new MinerManager();
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
long currentTime = minerServer.getCurrentTimeInSeconds();
minerServer.increaseTime(10);
manager.mineBlock(blockchain, minerClient, minerServer);
Block block = blockchain.getBestBlock();
Assert.assertEquals(1, block.getNumber());
Assert.assertTrue(currentTime + 10 <= block.getTimestamp());
Assert.assertTrue(currentTime + 11 > block.getTimestamp());
}
Aggregations