public async Task PruneService_Triggered_MidChain_Respect_AmountOfBlocksToKeepAsync()
        {
            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();

            await service.PruneBlocksAsync();

            Assert.Equal(25, service.PrunedUpToHeaderTip.Height);
        }
        public async Task PruneService_Blockstore_Height_Below_AmountofBlockstoKeep_PruneAbortedAsync()
        {
            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();

            await service.PruneBlocksAsync();

            Assert.Equal(genesisHeader, service.PrunedUpToHeaderTip);
        }
Exemplo n.º 3
0
        public async Task PruneService_Blockstore_Height_Below_PrunedTip_Plus_AmountToKeep_PruneAbortedAsync()
        {
            var chain = this.BuildProvenHeaderChain(50);

            var storeTipAt25 = chain.GetAncestor(20);

            var blockRepository = new Mock <IBlockRepository>();

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

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

            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.asyncLoopFactory, blockRepository.Object, this.prunedBlockRepository.Object, this.chainState.Object, this.LoggerFactory.Object, this.nodeLifetime, storeSettings);

            service.Initialize();

            await service.PruneBlocksAsync();

            Assert.Equal(prunedUptoHeaderTipAt10, service.PrunedUpToHeaderTip);
        }