diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index f412fb37d..c83787d8c 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -70,42 +70,42 @@ namespace BTCPayServer.Tests Assert.Equal(3, invoice.CryptoInfo.Length); + // Setup Lightning var controller = user.GetController(); var lightningVm = (LightningNodeViewModel)Assert.IsType(await controller.SetupLightningNode(user.StoreId, cryptoCode)).Model; Assert.True(lightningVm.Enabled); var response = await controller.SetLightningNodeEnabled(user.StoreId, cryptoCode, false); Assert.IsType(response); - // Get enabled state from overview action - PaymentMethodsViewModel paymentMethodsModel; - response = controller.PaymentMethods(); - paymentMethodsModel = (PaymentMethodsViewModel)Assert.IsType(response).Model; - var lnNode = paymentMethodsModel.LightningNodes.Find(node => node.CryptoCode == cryptoCode); - Assert.NotNull(lnNode); - Assert.False(lnNode.Enabled); + // Get enabled state from settings + LightningSettingsViewModel lnSettingsModel; + response = controller.LightningSettings(user.StoreId, cryptoCode).GetAwaiter().GetResult(); + lnSettingsModel = (LightningSettingsViewModel)Assert.IsType(response).Model; + Assert.NotNull(lnSettingsModel?.ConnectionString); + Assert.False(lnSettingsModel.Enabled); + // Setup wallet WalletSetupViewModel setupVm; var storeId = user.StoreId; response = await controller.GenerateWallet(storeId, cryptoCode, WalletSetupMethod.GenerateOptions, new WalletSetupRequest()); Assert.IsType(response); - // Get enabled state from overview action - response = controller.PaymentMethods(); - paymentMethodsModel = (PaymentMethodsViewModel)Assert.IsType(response).Model; - var derivationScheme = paymentMethodsModel.DerivationSchemes.Find(scheme => scheme.Crypto == cryptoCode); - Assert.NotNull(derivationScheme); - Assert.True(derivationScheme.Enabled); + // Get enabled state from settings + response = controller.WalletSettings(user.StoreId, cryptoCode).GetAwaiter().GetResult(); + var onchainSettingsModel = (WalletSettingsViewModel)Assert.IsType(response).Model; + Assert.NotNull(onchainSettingsModel?.DerivationScheme); + Assert.True(onchainSettingsModel.Enabled); // Disable wallet - response = controller.SetWalletEnabled(storeId, cryptoCode, false).GetAwaiter().GetResult(); + onchainSettingsModel.Enabled = false; + response = controller.UpdateWalletSettings(onchainSettingsModel).GetAwaiter().GetResult(); Assert.IsType(response); - response = controller.PaymentMethods(); - paymentMethodsModel = (PaymentMethodsViewModel)Assert.IsType(response).Model; - derivationScheme = paymentMethodsModel.DerivationSchemes.Find(scheme => scheme.Crypto == cryptoCode); - Assert.NotNull(derivationScheme); - Assert.False(derivationScheme.Enabled); + response = controller.WalletSettings(user.StoreId, cryptoCode).GetAwaiter().GetResult(); + onchainSettingsModel = (WalletSettingsViewModel)Assert.IsType(response).Model; + Assert.NotNull(onchainSettingsModel?.DerivationScheme); + Assert.False(onchainSettingsModel.Enabled); - var oldScheme = derivationScheme.Value; + var oldScheme = onchainSettingsModel.DerivationScheme; invoice = await user.BitPay.CreateInvoiceAsync( new Invoice @@ -430,7 +430,7 @@ namespace BTCPayServer.Tests s.GoToInvoiceCheckout(invoiceId); s.Driver.FindElement(By.ClassName("payment__currencies_noborder")); s.GoToHome(); - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); s.AddDerivationScheme("LTC"); s.AddLightningNode(LightningConnectionType.CLightning); //there should be three now diff --git a/BTCPayServer.Tests/CheckoutUITests.cs b/BTCPayServer.Tests/CheckoutUITests.cs index 4bf584d66..d42df0aac 100644 --- a/BTCPayServer.Tests/CheckoutUITests.cs +++ b/BTCPayServer.Tests/CheckoutUITests.cs @@ -204,7 +204,7 @@ namespace BTCPayServer.Tests s.GoToRegister(); s.RegisterNewUser(); s.CreateNewStore(); - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); s.AddDerivationScheme(); var invoiceId = s.CreateInvoice(0.001m, "BTC", "a@x.com"); var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId); diff --git a/BTCPayServer.Tests/PayJoinTests.cs b/BTCPayServer.Tests/PayJoinTests.cs index 20a75def8..e77104e39 100644 --- a/BTCPayServer.Tests/PayJoinTests.cs +++ b/BTCPayServer.Tests/PayJoinTests.cs @@ -289,7 +289,8 @@ namespace BTCPayServer.Tests .GetAttribute("href"); Assert.Contains($"{PayjoinClient.BIP21EndpointKey}=", bip21); - s.GoToWalletSettings(receiver.storeId, cryptoCode); + s.GoToStore(receiver.storeId); + s.GoToWalletSettings(cryptoCode); Assert.True(s.Driver.FindElement(By.Id("PayJoinEnabled")).Selected); var sender = s.CreateNewStore(); diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 779bbd477..63210c20b 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using BTCPayServer.Abstractions.Models; using BTCPayServer.BIP78.Sender; @@ -155,7 +156,7 @@ namespace BTCPayServer.Tests Driver.FindElement(By.Id("StoreNav-StoreSettings")).Click(); Driver.FindElement(By.Id($"SectionNav-{StoreNavPages.General.ToString()}")).Click(); var storeId = Driver.WaitForElement(By.Id("Id")).GetAttribute("value"); - Driver.FindElement(By.Id($"SectionNav-{StoreNavPages.PaymentMethods.ToString()}")).Click(); + Driver.FindElement(By.Id($"SectionNav-{StoreNavPages.Payment.ToString()}")).Click(); if (keepId) StoreId = storeId; return (name, storeId); @@ -164,7 +165,7 @@ namespace BTCPayServer.Tests public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) { var isImport = !string.IsNullOrEmpty(seed); - Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); + GoToWalletSettings(cryptoCode); // Replace previous wallet case if (Driver.PageSource.Contains("id=\"ChangeWalletLink\"")) @@ -228,10 +229,7 @@ namespace BTCPayServer.Tests /// public void AddDerivationScheme(string cryptoCode = "BTC", string derivationScheme = "xpub661MyMwAqRbcGABgHMUXDzPzH1tU7eZaAaJQXhDXsSxsqyQzQeU6kznNfSuAyqAK9UaWSaZaMFdNiY5BCF4zBPAzSnwfUAwUhwttuAKwfRX-[legacy]") { - if (Driver.PageSource.Contains($"id=\"Modify{cryptoCode}\"")) - { - Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); - } + GoToWalletSettings(cryptoCode); Driver.FindElement(By.Id("ImportWalletOptionsLink")).Click(); Driver.FindElement(By.Id("ImportXpubLink")).Click(); @@ -254,11 +252,7 @@ namespace BTCPayServer.Tests public void AddLightningNode(string cryptoCode = null, LightningConnectionType? connectionType = null, bool test = true) { cryptoCode ??= "BTC"; - if (Driver.PageSource.Contains($"id=\"Modify-Lightning{cryptoCode}\"")) - { - Driver.FindElement(By.Id($"Modify-Lightning{cryptoCode}")).Click(); - } - + Driver.FindElement(By.Id($"StoreNav-Lightning{cryptoCode}")).Click(); if (Driver.PageSource.Contains("id=\"SetupLightningNodeLink\"")) { Driver.FindElement(By.Id("SetupLightningNodeLink")).Click(); @@ -392,22 +386,18 @@ namespace BTCPayServer.Tests } } - public void GoToWalletSettings(string storeId, string cryptoCode = "BTC") + public void GoToWalletSettings(string cryptoCode = "BTC") { - try + Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click(); + if (Driver.PageSource.Contains("id=\"SectionNav-Settings\"")) { - GoToStore(storeId, StoreNavPages.PaymentMethods); - Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); - } - catch (NoSuchElementException) - { - GoToWallet(new WalletId(storeId, cryptoCode), WalletsNavPages.Settings); + Driver.FindElement(By.Id("SectionNav-Settings")).Click(); } } public void GoToLightningSettings(string cryptoCode = "BTC") { - GoToStore(StoreNavPages.PaymentMethods); + GoToStore(StoreNavPages.Payment); Driver.FindElement(By.Id($"StoreNav-Lightning{cryptoCode}")).Click(); // if Lightning is already set up we need to navigate to the settings if (Driver.PageSource.Contains("id=\"SectionNav-LightningSettings\"")) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 7797c349b..ba8352fcb 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -335,6 +335,7 @@ namespace BTCPayServer.Tests Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource); } + [Fact(Timeout = TestTimeout)] public async Task CanCreateInvoiceInUI() { @@ -402,18 +403,9 @@ namespace BTCPayServer.Tests var alice = s.RegisterNewUser(true); (string storeName, string storeId) = s.CreateNewStore(); var storeUrl = $"/stores/{storeId}"; - var onchainHint = "Set up your wallet to receive payments at your store."; - var offchainHint = "A connection to a Lightning node is required to receive Lightning payments."; - // verify that hints are displayed on the store page - Assert.True(s.Driver.PageSource.Contains(onchainHint), "Wallet hint not present"); - Assert.True(s.Driver.PageSource.Contains(offchainHint), "Lightning hint not present"); - - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); Assert.Contains(storeName, s.Driver.PageSource); - Assert.True(s.Driver.PageSource.Contains(onchainHint), "Wallet hint should be present at this point"); - Assert.True(s.Driver.PageSource.Contains(offchainHint), - "Lightning hint should be present at this point"); // verify steps for wallet setup are displayed correctly s.GoToStore(StoreNavPages.Dashboard); @@ -423,11 +415,8 @@ namespace BTCPayServer.Tests // setup onchain wallet s.Driver.FindElement(By.Id("SetupGuide-Wallet")).Click(); - Thread.Sleep(10000); s.AddDerivationScheme(); s.Driver.AssertNoError(); - Assert.False(s.Driver.PageSource.Contains(onchainHint), - "Wallet hint not dismissed on derivation scheme add"); s.GoToStore(StoreNavPages.Dashboard); Assert.True(s.Driver.FindElement(By.Id("SetupGuide-WalletDone")).Displayed); @@ -438,8 +427,6 @@ namespace BTCPayServer.Tests s.Driver.AssertNoError(); var successAlert = s.FindAlertMessage(); Assert.Contains("BTC Lightning node updated.", successAlert.Text); - Assert.False(s.Driver.PageSource.Contains(offchainHint), - "Lightning hint should be dismissed at this point"); s.ClickOnAllSectionLinks(); @@ -540,8 +527,8 @@ namespace BTCPayServer.Tests s.RegisterNewUser(); s.CreateNewStore(); s.AddDerivationScheme(); - - s.Driver.FindElement(By.Id("SectionNav-Tokens")).Click(); + + s.GoToStore(StoreNavPages.Tokens); s.Driver.FindElement(By.Id("CreateNewToken")).Click(); s.Driver.FindElement(By.Id("RequestPairing")).Click(); var pairingCode = AssertUrlHasPairingCode(s); @@ -794,7 +781,7 @@ namespace BTCPayServer.Tests Assert.Contains(server.ServerUri.AbsoluteUri, s.Driver.PageSource); TestLogs.LogInformation("Let's see if we can generate an event"); - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); s.AddDerivationScheme(); s.CreateInvoice(); var request = await server.GetNextRequest(); @@ -859,9 +846,9 @@ namespace BTCPayServer.Tests foreach (var isHotwallet in new[] { false, true }) { var cryptoCode = "BTC"; - (_, string storeId) = s.CreateNewStore(); + s.CreateNewStore(); s.GenerateWallet(cryptoCode, "melody lizard phrase voice unique car opinion merge degree evil swift cargo", privkeys: isHotwallet); - s.GoToWalletSettings(storeId, cryptoCode); + s.GoToWalletSettings(cryptoCode); if (isHotwallet) Assert.Contains("View seed", s.Driver.PageSource); else @@ -916,10 +903,8 @@ namespace BTCPayServer.Tests receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value"); //change the wallet and ensure old address is not there and generating a new one does not result in the prev one - s.GoToStore(storeId, StoreNavPages.PaymentMethods); s.GenerateWallet(cryptoCode, "", true); - s.Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click(); - s.Driver.FindElement(By.Id("SectionNav-Receive")).Click(); + s.GoToWallet(null, WalletsNavPages.Receive); s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value")); @@ -932,7 +917,7 @@ namespace BTCPayServer.Tests var result = await s.Server.ExplorerNode.GetAddressInfoAsync(BitcoinAddress.Create(address, Network.RegTest)); Assert.True(result.IsWatchOnly); - s.GoToStore(storeId, StoreNavPages.PaymentMethods); + s.GoToStore(storeId, StoreNavPages.Payment); var mnemonic = s.GenerateWallet(cryptoCode, "", true, true); //lets import and save private keys @@ -953,7 +938,7 @@ namespace BTCPayServer.Tests s.ClickOnAllSectionLinks(); // Make sure wallet info is correct - s.GoToWalletSettings(storeId, cryptoCode); + s.GoToWalletSettings(cryptoCode); Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(), s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value")); Assert.Contains("m/84'/1'/0'", @@ -1011,7 +996,7 @@ namespace BTCPayServer.Tests Assert.Equal(parsedBip21.Address.ToString(), s.Driver.FindElement(By.Id("Outputs_0__DestinationAddress")).GetAttribute("value")); - s.GoToWalletSettings(storeId, cryptoCode); + s.GoToWalletSettings(cryptoCode); var settingsUrl = s.Driver.Url; s.Driver.FindElement(By.Id("ActionsDropdownToggle")).Click(); s.Driver.FindElement(By.Id("ViewSeed")).Click(); @@ -1035,12 +1020,12 @@ namespace BTCPayServer.Tests using var s = CreateSeleniumTester(); await s.StartAsync(); s.RegisterNewUser(true); - (_, string storeId) = s.CreateNewStore(); + s.CreateNewStore(); const string cryptoCode = "BTC"; var mnemonic = s.GenerateWallet(cryptoCode, "click chunk owner kingdom faint steak safe evidence bicycle repeat bulb wheel"); // Make sure wallet info is correct - s.GoToWalletSettings(storeId, cryptoCode); + s.GoToWalletSettings(cryptoCode); Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(), s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value")); Assert.Contains("m/84'/1'/0'", @@ -1305,7 +1290,7 @@ namespace BTCPayServer.Tests s.RegisterNewUser(true); s.CreateNewStore(); - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); s.AddLightningNode(LightningConnectionType.CLightning, false); s.GoToLightningSettings(); s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true); @@ -1348,7 +1333,7 @@ namespace BTCPayServer.Tests s.RegisterNewUser(true); (_, string storeId) = s.CreateNewStore(); var network = s.Server.NetworkProvider.GetNetwork(cryptoCode).NBitcoinNetwork; - s.GoToStore(StoreNavPages.PaymentMethods); + s.GoToStore(StoreNavPages.Payment); s.AddLightningNode(LightningConnectionType.CLightning, false); s.GoToLightningSettings(); // LNURL is false by default @@ -1561,7 +1546,7 @@ namespace BTCPayServer.Tests //ensure ln address is not available as Lightning is not enable s.Driver.AssertElementNotFound(By.Id("StoreNav-LightningAddress")); - s.GoToStore(s.StoreId, StoreNavPages.PaymentMethods); + s.GoToStore(s.StoreId, StoreNavPages.Payment); s.AddLightningNode(LightningConnectionType.LndREST, false); //ensure ln address is not available as lnurl is not configured s.Driver.AssertElementNotFound(By.Id("StoreNav-LightningAddress")); diff --git a/BTCPayServer.Tests/TestAccount.cs b/BTCPayServer.Tests/TestAccount.cs index 275665494..49466193b 100644 --- a/BTCPayServer.Tests/TestAccount.cs +++ b/BTCPayServer.Tests/TestAccount.cs @@ -133,13 +133,13 @@ namespace BTCPayServer.Tests }); } - public async Task ModifyPayment(Action modify) + public async Task ModifyPayment(Action modify) { var storeController = GetController(); - var response = storeController.PaymentMethods(); - PaymentMethodsViewModel paymentMethods = (PaymentMethodsViewModel)((ViewResult)response).Model; - modify(paymentMethods); - await storeController.PaymentMethods(paymentMethods); + var response = storeController.Payment(); + PaymentViewModel payment = (PaymentViewModel)((ViewResult)response).Model; + modify(payment); + await storeController.Payment(payment); } public async Task ModifyWalletSettings(Action modify) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 06cc3c311..84b34be67 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -275,11 +275,11 @@ namespace BTCPayServer.Tests // Set tolerance to 50% var stores = user.GetController(); - var response = stores.PaymentMethods(); - var vm = Assert.IsType(Assert.IsType(response).Model); + var response = stores.Payment(); + var vm = Assert.IsType(Assert.IsType(response).Model); Assert.Equal(0.0, vm.PaymentTolerance); vm.PaymentTolerance = 50.0; - Assert.IsType(stores.PaymentMethods(vm).Result); + Assert.IsType(stores.Payment(vm).Result); var invoice = user.BitPay.CreateInvoice( new Invoice() @@ -417,7 +417,7 @@ namespace BTCPayServer.Tests var user = tester.NewAccount(); user.GrantAccess(true); var storeController = user.GetController(); - var storeResponse = storeController.PaymentMethods(); + var storeResponse = storeController.Payment(); Assert.IsType(storeResponse); Assert.IsType(await storeController.SetupLightningNode(user.StoreId, "BTC")); @@ -441,11 +441,11 @@ namespace BTCPayServer.Tests new LightningNodeViewModel { ConnectionString = tester.MerchantCharge.Client.Uri.AbsoluteUri }, "save", "BTC").GetAwaiter().GetResult()); - storeResponse = storeController.PaymentMethods(); + storeResponse = storeController.LightningSettings(user.StoreId, "BTC").GetAwaiter().GetResult(); var storeVm = - Assert.IsType(Assert + Assert.IsType(Assert .IsType(storeResponse).Model); - Assert.Single(storeVm.LightningNodes.Where(l => !string.IsNullOrEmpty(l.Address))); + Assert.NotEmpty(storeVm.ConnectionString); } [Fact(Timeout = 60 * 2 * 1000)] diff --git a/BTCPayServer/Components/MainNav/Default.cshtml b/BTCPayServer/Components/MainNav/Default.cshtml index 670049da8..c834fc4c7 100644 --- a/BTCPayServer/Components/MainNav/Default.cshtml +++ b/BTCPayServer/Components/MainNav/Default.cshtml @@ -35,7 +35,7 @@