use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainWithUnclesAndSynchronize.
@Test
public void buildBlockchainWithUnclesAndSynchronize() throws InterruptedException {
SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(10, true, true);
SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
node1.sendFullStatusTo(node2);
// find connection point
node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(10, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// get blocks
node2.waitExactlyNTasksWithTimeout(10);
node2.sendFullStatusTo(node1);
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertEquals(10, node1.getBestBlock().getNumber());
Assert.assertEquals(10, node2.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainPartialAndSynchronize.
@Test
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10, 0, false, true, null);
for (Block block : blocks) {
BlockMessage message = new BlockMessage(block);
node1.receiveMessageFrom(null, message);
node1.waitExactlyNTasksWithTimeout(1);
if (block.getNumber() <= 5) {
node2.receiveMessageFrom(null, message);
node2.waitExactlyNTasksWithTimeout(1);
}
}
Assert.assertEquals(10, node1.getBestBlock().getNumber());
Assert.assertEquals(5, node2.getBestBlock().getNumber());
node1.sendFullStatusTo(node2);
// find connection point
node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(10, 5, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// get blocks
node2.waitExactlyNTasksWithTimeout(5);
// drain node 1 for next test
node1.clearQueue();
node2.sendFullStatusTo(node1);
// receive status, do nothing
node1.waitExactlyNTasksWithTimeout(1);
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertEquals(10, node1.getBestBlock().getNumber());
Assert.assertEquals(10, node2.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Aggregations