### Question:
BlockServiceConsumer implements BlockConsumer<T> { @Override public List<ConsensusBlock<T>> syncBlock(BranchId branchId, long offset, long limit) { long curBestBlock = branchGroup.getLastIndex(branchId); List<ConsensusBlock<T>> blockList = new ArrayList<>(); if (curBestBlock == 0) { return blockList; } if (isNeedBlockSync(curBestBlock, offset)) { if (listener != null) { listener.catchUpRequest(branchId, offset); } } else { updateBlockList(branchId, offset, limit, blockList); } return blockList; } BlockServiceConsumer(BranchGroup branchGroup); @Override void setListener(CatchUpSyncEventListener listener); @Override List<ConsensusBlock<T>> syncBlock(BranchId branchId, long offset, long limit); @Override void broadcastBlock(ConsensusBlock<T> block);  }### Answer:
@Test public void syncBlock() { BlockChainTestUtils.generateBlock(branchGroup, branchId); Assert.assertEquals(1, blockChainManager.getLastIndex()); blockServiceConsumer.setListener(BlockChainSyncManagerMock.mock); List<ConsensusBlock<PbftProto.PbftBlock>> blockList = blockServiceConsumer.syncBlock(branchId, 1, 10); Assert.assertEquals(1, blockList.size()); Assert.assertEquals(1, blockChainManager.getLastIndex()); }
@Test public void syncBlockByPassingTheLimitSize() { TestConstants.SlowTest.apply(); int height = 110; List<ConsensusBlock<PbftProto.PbftBlock>> blockList = BlockChainTestUtils.createBlockListWithTxs(height, 100, branch.getContractManager()); blockList.forEach(b -> branch.addBlock(b, false)); Assert.assertEquals(height, blockChainManager.getLastIndex()); List<ConsensusBlock<PbftProto.PbftBlock>> received = blockServiceConsumer.syncBlock(branchId, 1, height); Assert.assertTrue(height > received.size()); }
@Test public void syncBLockRequestingCatchUp() { BlockChainTestUtils.setBlockHeightOfBlockChain(branch, 10); List<ConsensusBlock<PbftProto.PbftBlock>> blockList = blockServiceConsumer.syncBlock(branchId, 3, 10); Assert.assertEquals(8, blockList.size()); Assert.assertEquals(10, blockChainManager.getLastIndex()); }