diff --git a/BTCPayServer.Common/BTCPayServer.Common.csproj b/BTCPayServer.Common/BTCPayServer.Common.csproj index ac003c2de..5a39ed787 100644 --- a/BTCPayServer.Common/BTCPayServer.Common.csproj +++ b/BTCPayServer.Common/BTCPayServer.Common.csproj @@ -2,7 +2,7 @@ - + diff --git a/BTCPayServer.Tests/Extensions.cs b/BTCPayServer.Tests/Extensions.cs index 6dd12f455..7a86df3c5 100644 --- a/BTCPayServer.Tests/Extensions.cs +++ b/BTCPayServer.Tests/Extensions.cs @@ -19,6 +19,19 @@ namespace BTCPayServer.Tests { public static class Extensions { + public static Task WaitReceive(this NBXplorer.WebsocketNotificationSession notifications, DerivationStrategyBase target, Func predicate = null, CancellationToken cancellationToken = default) + => WaitNext(notifications, e => e.DerivationStrategy == target && (predicate is null || predicate(e)), cancellationToken); + public static async Task WaitNext(this NBXplorer.WebsocketNotificationSession notifications, Func predicate, CancellationToken cancellationToken = default) where TEvent : NewEventBase + { + retry: + var evt = await notifications.NextEventAsync(cancellationToken); + if (evt is TEvent { } e) + { + if (predicate(e)) + return e; + } + goto retry; + } public static Task ReserveAddressAsync(this BTCPayWallet wallet, DerivationStrategyBase derivationStrategyBase) { return wallet.ReserveAddressAsync(null, derivationStrategyBase, "test"); diff --git a/BTCPayServer.Tests/PayJoinTests.cs b/BTCPayServer.Tests/PayJoinTests.cs index f37663fb1..472b29659 100644 --- a/BTCPayServer.Tests/PayJoinTests.cs +++ b/BTCPayServer.Tests/PayJoinTests.cs @@ -426,7 +426,6 @@ namespace BTCPayServer.Tests var notifications = await nbx.CreateWebsocketNotificationSessionAsync(); var alice = tester.NewAccount(); await alice.RegisterDerivationSchemeAsync("BTC", ScriptPubKeyType.Segwit, true); - await notifications.ListenDerivationSchemesAsync(new[] { alice.DerivationScheme }); BitcoinAddress address = null; for (int i = 0; i < 5; i++) @@ -434,7 +433,7 @@ namespace BTCPayServer.Tests address = (await nbx.GetUnusedAsync(alice.DerivationScheme, DerivationFeature.Deposit)).Address; await tester.ExplorerNode.GenerateAsync(1); tester.ExplorerNode.SendToAddress(address, Money.Coins(1.0m)); - await notifications.NextEventAsync(); + await notifications.WaitReceive(alice.DerivationScheme); } var paymentAddress = new Key().PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.RegTest); var otherAddress = new Key().PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.RegTest); @@ -569,10 +568,9 @@ namespace BTCPayServer.Tests await notifications.DisposeAsync(); notifications = await nbx.CreateWebsocketNotificationSessionAsync(); - await notifications.ListenDerivationSchemesAsync(new[] { bob.DerivationScheme }); address = (await nbx.GetUnusedAsync(bob.DerivationScheme, DerivationFeature.Deposit)).Address; tester.ExplorerNode.SendToAddress(address, Money.Coins(1.1m)); - await notifications.NextEventAsync(); + await notifications.WaitReceive(bob.DerivationScheme); await bob.ModifyOnchainPaymentSettings(p => p.PayJoinEnabled = true); var invoice = bob.BitPay.CreateInvoice( new Invoice { Price = 0.1m, Currency = "BTC", FullNotifications = true }); @@ -603,7 +601,7 @@ namespace BTCPayServer.Tests proposal = proposal.SignAll(derivationSchemeSettings.AccountDerivation, alice.GenerateWalletResponseV.AccountHDKey, signingAccount.GetRootedKeyPath()); proposal.Finalize(); await tester.ExplorerNode.SendRawTransactionAsync(proposal.ExtractTransaction()); - await notifications.NextEventAsync(); + await notifications.WaitReceive(bob.DerivationScheme); TestLogs.LogInformation("Abusing minFeeRate should give not enough money error"); invoice = bob.BitPay.CreateInvoice( diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 160f6bb12..1ef34386d 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -32,6 +32,7 @@ using Microsoft.EntityFrameworkCore; using NBitcoin; using NBitcoin.DataEncoders; using NBitcoin.Payment; +using NBXplorer.Models; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OpenQA.Selenium; @@ -1884,11 +1885,9 @@ namespace BTCPayServer.Tests //send money to addr and ensure it changed var sess = await s.Server.ExplorerClient.CreateWebsocketNotificationSessionAsync(); - await sess.ListenAllTrackedSourceAsync(); - var nextEvent = sess.NextEventAsync(); await s.Server.ExplorerNode.SendToAddressAsync(BitcoinAddress.Create(receiveAddr, Network.RegTest), Money.Parse("0.1")); - await nextEvent; + await sess.WaitNext(e => e.Outputs.FirstOrDefault()?.Address.ToString() == receiveAddr); await Task.Delay(200); s.Driver.Navigate().Refresh(); s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); @@ -1898,6 +1897,7 @@ namespace BTCPayServer.Tests // Check the label is applied to the tx s.Driver.WaitWalletTransactionsLoaded(); + // Sometimes this fails in local, but not CI Assert.Equal("label2", s.Driver.FindElement(By.XPath("//*[@id=\"WalletTransactionsList\"]//*[contains(@class, 'transaction-label')]")).Text); //change the wallet and ensure old address is not there and generating a new one does not result in the prev one diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index b28b523e6..645266b0d 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -967,7 +967,6 @@ namespace BTCPayServer.Tests using (var cts = new CancellationTokenSource(10000)) using (var listener = tester.ExplorerClient.CreateWebsocketNotificationSession()) { - listener.ListenAllDerivationSchemes(); var replaced = tester.ExplorerNode.SignRawTransaction(tx); Thread.Sleep(1000); // Make sure the replacement has a different timestamp var tx2 = tester.ExplorerNode.SendRawTransaction(replaced); diff --git a/BTCPayServer.Tests/docker-compose.altcoins.yml b/BTCPayServer.Tests/docker-compose.altcoins.yml index 3f3e09f31..2449f7680 100644 --- a/BTCPayServer.Tests/docker-compose.altcoins.yml +++ b/BTCPayServer.Tests/docker-compose.altcoins.yml @@ -98,7 +98,7 @@ services: custom: nbxplorer: - image: nicolasdorier/nbxplorer:2.5.16 + image: nicolasdorier/nbxplorer:2.5.22 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer.Tests/docker-compose.mutinynet.yml b/BTCPayServer.Tests/docker-compose.mutinynet.yml index f68ae4093..745b5dd4f 100644 --- a/BTCPayServer.Tests/docker-compose.mutinynet.yml +++ b/BTCPayServer.Tests/docker-compose.mutinynet.yml @@ -62,7 +62,7 @@ services: custom: nbxplorer: - image: nicolasdorier/nbxplorer:2.5.16 + image: nicolasdorier/nbxplorer:2.5.22 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer.Tests/docker-compose.testnet.yml b/BTCPayServer.Tests/docker-compose.testnet.yml index 7fdc50083..a7dade08e 100644 --- a/BTCPayServer.Tests/docker-compose.testnet.yml +++ b/BTCPayServer.Tests/docker-compose.testnet.yml @@ -57,7 +57,7 @@ services: custom: nbxplorer: - image: nicolasdorier/nbxplorer:2.5.16 + image: nicolasdorier/nbxplorer:2.5.22 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index fb621a576..17791cf14 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -95,7 +95,7 @@ services: custom: nbxplorer: - image: nicolasdorier/nbxplorer:2.5.16 + image: nicolasdorier/nbxplorer:2.5.22 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs index c34b35588..4cd761e28 100644 --- a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs +++ b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs @@ -128,7 +128,7 @@ namespace BTCPayServer.Payments.Bitcoin return; if (_Cts.IsCancellationRequested) return; - var session = await client.CreateWebsocketNotificationSessionAsync(_Cts.Token).ConfigureAwait(false); + var session = await client.CreateWebsocketNotificationSessionLegacyAsync(_Cts.Token).ConfigureAwait(false); if (!_SessionsByCryptoCode.TryAdd(network.CryptoCode, session)) { await session.DisposeAsync();