From db976a64086df4fde969b34395f617f8bc4bf672 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 23 Sep 2022 16:23:14 +0200 Subject: [PATCH] Fix unit test and build warning --- BTCPayServer.Tests/ThirdPartyTests.cs | 23 +++++++++++++++---- BTCPayServer.Tests/UnitTest1.cs | 4 ++-- .../UILightningLikePayoutController.cs | 3 ++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/BTCPayServer.Tests/ThirdPartyTests.cs b/BTCPayServer.Tests/ThirdPartyTests.cs index 4b0f6ed8a..3190df52d 100644 --- a/BTCPayServer.Tests/ThirdPartyTests.cs +++ b/BTCPayServer.Tests/ThirdPartyTests.cs @@ -75,11 +75,11 @@ namespace BTCPayServer.Tests public async Task CanQueryDirectProviders() { // TODO: Check once in a while whether or not they are working again - string[] brokenShitcoinCasinos = { }; + string[] brokenShitcoinCasinos = {}; + var skipped = 0; var factory = FastTests.CreateBTCPayRateFactory(); var directlySupported = factory.GetSupportedExchanges().Where(s => s.Source == RateSource.Direct) .Select(s => s.Id).ToHashSet(); - var all = string.Join("\r\n", factory.GetSupportedExchanges().Select(e => e.Id).ToArray()); foreach (var result in factory .Providers .Where(p => p.Value is BackgroundFetcherRateProvider bf && @@ -91,14 +91,26 @@ namespace BTCPayServer.Tests var name = result.ExpectedName; if (brokenShitcoinCasinos.Contains(name)) { - TestLogs.LogInformation($"Skipping {name}"); + TestLogs.LogInformation($"Skipping {name}: Broken shitcoin casino"); + skipped++; continue; } TestLogs.LogInformation($"Testing {name}"); result.Fetcher.InvalidateCache(); - var exchangeRates = new ExchangeRates(name, result.ResultAsync.Result); + + ExchangeRates exchangeRates = null; + try + { + exchangeRates = new ExchangeRates(name, result.ResultAsync.Result); + } + catch (Exception exception) + { + TestLogs.LogInformation($"Skipping {name}: {exception.Message}"); + skipped++; + continue; + } result.Fetcher.InvalidateCache(); Assert.NotNull(exchangeRates); Assert.NotEmpty(exchangeRates); @@ -160,11 +172,12 @@ namespace BTCPayServer.Tests // Kraken emit one request only after first GetRates factory.Providers["kraken"].GetRatesAsync(default).GetAwaiter().GetResult(); - var p = new KrakenExchangeRateProvider(); var rates = await p.GetRatesAsync(default); Assert.Contains(rates, e => e.CurrencyPair == new CurrencyPair("XMR", "BTC") && e.BidAsk.Bid < 1.0m); + // Check we didn't skip too many exchanges + Assert.InRange(skipped, 0, 3); } [Fact] diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 809be4d57..82272e293 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -1753,7 +1753,7 @@ namespace BTCPayServer.Tests await user.GrantAccessAsync(); user.RegisterDerivationScheme("BTC"); await user.SetNetworkFeeMode(NetworkFeeMode.Always); - var invoice = user.BitPay.CreateInvoice( + var invoice = await user.BitPay.CreateInvoiceAsync( new Invoice { Price = 10, @@ -1768,7 +1768,7 @@ namespace BTCPayServer.Tests var jsonResult = user.GetController().Export("json").GetAwaiter().GetResult(); var result = Assert.IsType(jsonResult); Assert.Equal("application/json", result.ContentType); - Assert.Equal(1, JArray.Parse(result.Content).Count); + Assert.Single(JArray.Parse(result.Content)); var cashCow = tester.ExplorerNode; var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, cashCow.Network); diff --git a/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs b/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs index 0b20496f2..4f5029dc8 100644 --- a/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs +++ b/BTCPayServer/Data/Payouts/LightningLike/UILightningLikePayoutController.cs @@ -301,8 +301,9 @@ namespace BTCPayServer.Data.Payouts.LightningLike var payment = await lightningClient.GetPayment(bolt11PaymentRequest.PaymentHash.ToString()); proofBlob.Preimage = payment.Preimage; } - catch (Exception e) + catch (Exception) { + // ignored } }