public void PruneService_Blockstore_Height_Below_AmountofBlockstoKeep_PruneAborted()
        {
            var block         = this.Network.CreateBlock();
            var genesisHeader = new ChainedHeader(block.Header, block.GetHash(), 0);

            var blockRepository = new Mock <IBlockRepository>();

            blockRepository.Setup(x => x.TipHashAndHeight).Returns(new HashHeightPair(genesisHeader));

            this.chainState.Setup(c => c.BlockStoreTip).Returns(genesisHeader);

            this.prunedBlockRepository = new Mock <IPrunedBlockRepository>();
            this.prunedBlockRepository.Setup(x => x.PrunedTip).Returns(new HashHeightPair(genesisHeader));

            var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
            {
                AmountOfBlocksToKeep = 2880
            };

            var service = new PruneBlockStoreService(this.asyncProvider, blockRepository.Object, this.prunedBlockRepository.Object, this.chainState.Object, this.LoggerFactory.Object, this.nodeLifetime, storeSettings);

            service.Initialize();

            service.PruneBlocks();

            Assert.Equal(genesisHeader, service.PrunedUpToHeaderTip);
        }
        public void PruneService_Triggered_MidChain_Respect_AmountOfBlocksToKeep()
        {
            var chain = this.BuildProvenHeaderChain(50);

            var storeTipAt45 = chain.GetAncestor(45);

            var blockRepository = new Mock <IBlockRepository>();

            blockRepository.Setup(x => x.TipHashAndHeight).Returns(new HashHeightPair(storeTipAt45));

            this.chainState.Setup(c => c.BlockStoreTip).Returns(storeTipAt45);

            var prunedUptoHeaderTipAt10 = chain.GetAncestor(10);

            this.prunedBlockRepository = new Mock <IPrunedBlockRepository>();
            this.prunedBlockRepository.Setup(x => x.PrunedTip).Returns(new HashHeightPair(prunedUptoHeaderTipAt10));

            var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
            {
                AmountOfBlocksToKeep = 20
            };

            var service = new PruneBlockStoreService(this.asyncProvider, blockRepository.Object, this.prunedBlockRepository.Object, this.chainState.Object, this.LoggerFactory.Object, this.nodeLifetime, storeSettings);

            service.Initialize();

            service.PruneBlocks();

            Assert.Equal(25, service.PrunedUpToHeaderTip.Height);
        }