public void GetMaturedBlockDeposits_Fails_When_Block_Height_Greater_Than_Minimum_Deposit_Confirmations_Async() { ChainedHeader tip = ChainedHeadersHelper.CreateConsecutiveHeaders(5, null, true).Last(); this.consensusManager.Tip.Returns(tip); // Minimum deposit confirmations : 2 IFederatedPegSettings federatedPegSettings = Substitute.For <IFederatedPegSettings>(); federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(2); FederationGatewayController controller = this.CreateController(federatedPegSettings); int maturedHeight = (int)(tip.Height - 2); // Back online at block height : 3 // 0 - 1 - 2 - 3 ChainedHeader earlierBlock = tip.GetAncestor(maturedHeight + 1); // Mature height = 2 (Chain header height (4) - Minimum deposit confirmations (2)) IActionResult result = controller.GetMaturedBlockDeposits(earlierBlock.Height); // Block height (3) > Mature height (2) - returns error message var maturedBlockDepositsResult = (result as JsonResult).Value as SerializableResult <List <MaturedBlockDepositsModel> >; maturedBlockDepositsResult.Should().NotBeNull(); maturedBlockDepositsResult.Value.Count().Should().Be(0); maturedBlockDepositsResult.Message.Should().Contain(string.Format("The submitted block height of {0} is not mature enough for '{1}' deposits, blocks below {2} can be returned.", earlierBlock.Height, DepositRetrievalType.Normal, maturedHeight)); }
public void GetMaturedBlockDeposits_Fails_When_Block_Height_Greater_Than_Minimum_Deposit_Confirmations_Async() { ChainedHeader tip = ChainedHeadersHelper.CreateConsecutiveHeaders(5, null, true).Last(); this.consensusManager.Tip.Returns(tip); FederationGatewayController controller = this.CreateController(); // Minimum deposit confirmations : 2 this.depositExtractor.MinimumDepositConfirmations.Returns((uint)2); int maturedHeight = (int)(tip.Height - this.depositExtractor.MinimumDepositConfirmations); // Back online at block height : 3 // 0 - 1 - 2 - 3 ChainedHeader earlierBlock = tip.GetAncestor(maturedHeight + 1); // Mature height = 2 (Chain header height (4) - Minimum deposit confirmations (2)) IActionResult result = controller.GetMaturedBlockDeposits(new MaturedBlockRequestModel(earlierBlock.Height, 1000)); // Block height (3) > Mature height (2) - returns error message var maturedBlockDepositsResult = (result as JsonResult).Value as SerializableResult <List <MaturedBlockDepositsModel> >; maturedBlockDepositsResult.Should().NotBeNull(); maturedBlockDepositsResult.IsSuccess.Should().Be(false); maturedBlockDepositsResult.Message.Should().Be(string.Format(MaturedBlocksProvider.RetrieveBlockHeightHigherThanMaturedTipMessage, earlierBlock.Height, maturedHeight)); }
public void GetMaturedBlockDeposits_Gets_All_Matured_Block_Deposits() { ChainedHeader tip = ChainedHeadersHelper.CreateConsecutiveHeaders(10, null, true).Last(); this.consensusManager.Tip.Returns(tip); int minConfirmations = 2; // Minimum deposit confirmations : 2 IFederatedPegSettings federatedPegSettings = Substitute.For <IFederatedPegSettings>(); federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(minConfirmations); FederationGatewayController controller = this.CreateController(federatedPegSettings); ChainedHeader earlierBlock = tip.GetAncestor(minConfirmations); int depositExtractorCallCount = 0; this.depositExtractor.ExtractDepositsFromBlock(Arg.Any <Block>(), Arg.Any <int>(), Arg.Any <DepositRetrievalType[]>()).Returns(new List <IDeposit>()); this.depositExtractor.When(x => x.ExtractDepositsFromBlock(Arg.Any <Block>(), Arg.Any <int>(), Arg.Any <DepositRetrievalType[]>())).Do(info => { depositExtractorCallCount++; }); this.consensusManager.GetBlocksAfterBlock(Arg.Any <ChainedHeader>(), MaturedBlocksProvider.MaturedBlocksBatchSize, Arg.Any <CancellationTokenSource>()).Returns(delegate(CallInfo info) { var chainedHeader = (ChainedHeader)info[0]; var blocks = new List <ChainedHeaderBlock>(); int startHeight = (chainedHeader == null) ? 0 : (chainedHeader.Height + 1); for (int i = startHeight; i <= this.consensusManager.Tip.Height; i++) { blocks.Add(new ChainedHeaderBlock(new Block(), tip.GetAncestor(i))); } return(blocks); }); IActionResult result = controller.GetMaturedBlockDeposits(earlierBlock.Height); result.Should().BeOfType <JsonResult>(); var maturedBlockDepositsResult = (result as JsonResult).Value as SerializableResult <List <MaturedBlockDepositsModel> >; maturedBlockDepositsResult.Should().NotBeNull(); maturedBlockDepositsResult.Message.Should().Be(string.Empty); // Heights 0 to 10. depositExtractorCallCount.Should().Be(11); }
public void GetMaturedBlockDeposits_Gets_All_Matured_Block_Deposits() { ChainedHeader tip = ChainedHeadersHelper.CreateConsecutiveHeaders(10, null, true).Last(); this.consensusManager.Tip.Returns(tip); int minConfirmations = 2; // Minimum deposit confirmations : 2 IFederatedPegSettings federatedPegSettings = Substitute.For <IFederatedPegSettings>(); federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(minConfirmations); FederationGatewayController controller = this.CreateController(federatedPegSettings); ChainedHeader earlierBlock = tip.GetAncestor(minConfirmations); int depositExtractorCallCount = 0; this.depositExtractor.ExtractBlockDeposits(Arg.Any <ChainedHeaderBlock>(), DepositRetrievalType.Normal).Returns(new MaturedBlockDepositsModel(null, null)); this.depositExtractor.When(x => x.ExtractBlockDeposits(Arg.Any <ChainedHeaderBlock>(), DepositRetrievalType.Normal)).Do(info => { depositExtractorCallCount++; }); this.consensusManager.GetBlockData(Arg.Any <List <uint256> >()).ReturnsForAnyArgs((x) => { List <uint256> hashes = x.ArgAt <List <uint256> >(0); return(hashes.Select((h) => new ChainedHeaderBlock(new Block(), earlierBlock)).ToArray()); }); IActionResult result = controller.GetMaturedBlockDeposits(earlierBlock.Height); result.Should().BeOfType <JsonResult>(); var maturedBlockDepositsResult = (result as JsonResult).Value as SerializableResult <List <MaturedBlockDepositsModel> >; maturedBlockDepositsResult.Should().NotBeNull(); maturedBlockDepositsResult.Message.Should().Be(string.Empty); // If the minConfirmations == 0 and this.chain.Height == earlierBlock.Height then expectedCallCount must be 1. int expectedCallCount = (tip.Height - minConfirmations) - earlierBlock.Height + 1; depositExtractorCallCount.Should().Be(expectedCallCount); }