DBConsensusManager { public OpBlockChain saveMainBlockchain(OpBlockChain blc) { OpBlockChain lastNotSaved = null; OpBlockChain beforeLast = null; boolean parentInOrphanedList = true; while (!blc.isNullBlock() && !blc.isDbAccessed()) { beforeLast = lastNotSaved; lastNotSaved = blc; if (parentInOrphanedList) { for (OpBlock header : blc.getSuperblockHeaders()) { OpBlock existing = orphanedBlocks.remove(header.getRawHash()); if (existing == null) { parentInOrphanedList = false; break; } } } blc = blc.getParent(); } if (lastNotSaved != null && lastNotSaved.getSuperblockSize() >= settingsManager.OPENDB_SUPERBLOCK_SIZE.get()) { OpBlockChain saved = saveSuperblock(lastNotSaved); if (beforeLast != null) { if (!beforeLast.changeToEqualParent(saved)) { throw new IllegalStateException( "Can't change parent " + lastNotSaved.getSuperBlockHash() + " " + saved.getSuperBlockHash()); } } else { return saved; } } return blc; }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices();  }
@Test public void testSaveMainBlockchain() throws FailedVerificationException { OpBlockChain opBlockChain = dbConsensusManager.init(metadataDb); generateMore30Blocks(formatter, opBlockChain, dbConsensusManager, BOOTSTRAP_LIST); final long[] amount = new long[1]; jdbcTemplate.query("SELECT COUNT(*) FROM " + BLOCKS_TABLE + " WHERE superblock is NOT NULL", rs -> { amount[0] = rs.getLong(1); }); assertEquals(0, amount[0]); dbConsensusManager.saveMainBlockchain(opBlockChain); jdbcTemplate.query("SELECT COUNT(*) FROM " + BLOCKS_TABLE + " WHERE superblock is NOT NULL", rs -> { amount[0] = rs.getLong(1); }); assertEquals(40, amount[0]); }