public async Task PruneRepository_PruneAndCompact_OnShutDownAsync() { var posBlocks = CreatePosBlocks(50); var chainedHeaderTip = BuildProvenHeaderChainFromBlocks(posBlocks); var dataFolderPath = CreateTestDir(this); var dataFolder = new DataFolder(dataFolderPath); var dBreezeSerializer = new DBreezeSerializer(this.Network); var blockRepository = new BlockRepository(this.Network, dataFolder, this.LoggerFactory.Object, dBreezeSerializer); await blockRepository.PutAsync(new HashHeightPair(posBlocks.Last().GetHash(), 50), posBlocks); var storeSettings = new StoreSettings(NodeSettings.Default(this.Network)) { AmountOfBlocksToKeep = 10 }; var prunedBlockRepository = new PrunedBlockRepository(blockRepository, dBreezeSerializer, this.LoggerFactory.Object, storeSettings); await prunedBlockRepository.InitializeAsync(); // Delete blocks 30 to 0 from the repo, this would have been done by the service before shutdown was initiated. await blockRepository.DeleteBlocksAsync(posBlocks.Take(30).Select(b => b.GetHash()).ToList()); prunedBlockRepository.UpdatePrunedTip(chainedHeaderTip.GetAncestor(30)); // Ensure that the block has been deleted from disk. Assert.Null(await blockRepository.GetBlockAsync(chainedHeaderTip.GetAncestor(29).HashBlock)); // On shutdown the database will only be compacted. await prunedBlockRepository.PruneAndCompactDatabase(chainedHeaderTip.GetAncestor(50), this.Network, false); Assert.Equal(chainedHeaderTip.GetAncestor(30).HashBlock, prunedBlockRepository.PrunedTip.Hash); Assert.Equal(chainedHeaderTip.GetAncestor(30).Height, prunedBlockRepository.PrunedTip.Height); Assert.Null(await blockRepository.GetBlockAsync(chainedHeaderTip.GetAncestor(29).HashBlock)); }