use of co.rsk.test.World 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 co.rsk.test.World 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 co.rsk.test.World 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 co.rsk.test.World in project rskj by rsksmart.
the class MinerServerTest method setUp.
@Before
public void setUp() {
World world = new World();
blockchain = world.getBlockChain();
}
use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerTest method processBlockHeaderRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHeaderRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final BlockStore store = new BlockStore();
List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), 10);
for (Block b : blocks) blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
SimpleMessageChannel sender = new SimpleMessageChannel();
handler.processMessage(sender, new BlockHeadersRequestMessage(1, blocks.get(4).getHash().getBytes(), 1));
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());
BlockHeadersResponseMessage bMessage = (BlockHeadersResponseMessage) message;
Assert.assertEquals(blocks.get(4).getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
Aggregations