use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.
the class OneNodeTest method buildBlockchain.
@Test
public void buildBlockchain() {
SimpleNode node = SimpleNode.createNode();
List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
for (Block block : blocks) node.receiveMessageFrom(null, new BlockMessage(block));
Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.
the class TwoAsyncNodeTest method buildBlockchainPartialAndSynchronize.
@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
SimpleAsyncNode node1 = createNode(0);
SimpleAsyncNode node2 = createNode(0);
List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
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);
}
}
node1.sendStatusTo(node2);
node2.waitUntilNTasksWithTimeout(1);
node1.waitExactlyNTasksWithTimeout(5);
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertEquals(10, node1.getBestBlock().getNumber());
Assert.assertEquals(10, node2.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
}
use of co.rsk.net.messages.BlockMessage 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