From b422e79896c4f9434fe6a1d9694bba1aacd20a45 Mon Sep 17 00:00:00 2001 From: d11n Date: Mon, 4 Jul 2022 14:59:46 +0200 Subject: [PATCH] Add test cases for wallet send wizard links (#3927) --- BTCPayServer.Tests/SeleniumTests.cs | 41 +++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 78b01b83f..567dd6ce7 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -1036,26 +1036,32 @@ namespace BTCPayServer.Tests // then try to use the seed to sign the transaction s.GenerateWallet(cryptoCode, "", true); - //let's test quickly the receive wallet page + //let's test quickly the wallet send page s.Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click(); s.Driver.FindElement(By.Id("WalletNav-Send")).Click(); - s.Driver.FindElement(By.Id("SignTransaction")).Click(); - //you cannot use the Sign with NBX option without saving private keys when generating the wallet. Assert.DoesNotContain("nbx-seed", s.Driver.PageSource); - + Assert.True(s.Driver.ElementDoesNotExist(By.Id("GoBack"))); + s.Driver.FindElement(By.Id("SignTransaction")).Click(); + Assert.Contains("Destination Address field is required", s.Driver.PageSource); + Assert.True(s.Driver.ElementDoesNotExist(By.Id("GoBack"))); s.Driver.FindElement(By.Id("CancelWizard")).Click(); s.Driver.FindElement(By.Id("WalletNav-Receive")).Click(); + //generate a receiving address s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); Assert.True(s.Driver.FindElement(By.CssSelector("#address-tab .qr-container")).Displayed); + // no previous page in the wizard, hence no back button + Assert.True(s.Driver.ElementDoesNotExist(By.Id("GoBack"))); var receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value"); + //unreserve s.Driver.FindElement(By.CssSelector("button[value=unreserve-current-address]")).Click(); //generate it again, should be the same one as before as nothing got used in the meantime s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click(); Assert.True(s.Driver.FindElement(By.CssSelector("#address-tab .qr-container")).Displayed); Assert.Equal(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value")); + Assert.True(s.Driver.ElementDoesNotExist(By.Id("GoBack"))); //send money to addr and ensure it changed var sess = await s.Server.ExplorerClient.CreateWebsocketNotificationSessionAsync(); @@ -1075,7 +1081,6 @@ namespace BTCPayServer.Tests s.GenerateWallet(cryptoCode, "", true); 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")); var invoiceId = s.CreateInvoice(storeId); @@ -1120,21 +1125,26 @@ namespace BTCPayServer.Tests // Check the tx sent earlier arrived s.Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click(); - - var walletTransactionLink = s.Driver.Url; Assert.Contains(tx.ToString(), s.Driver.PageSource); + var walletTransactionUri = new Uri(s.Driver.Url); // Send to bob s.Driver.FindElement(By.Id("WalletNav-Send")).Click(); var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest); SetTransactionOutput(s, 0, bob, 1); s.Driver.FindElement(By.Id("SignTransaction")).Click(); + // Back button should lead back to the previous page inside the send wizard + var backUrl = s.Driver.FindElement(By.Id("GoBack")).GetAttribute("href"); + Assert.EndsWith($"/send?returnUrl={walletTransactionUri.AbsolutePath}", backUrl); + // Cancel button should lead to the page that referred to the send wizard + var cancelUrl = s.Driver.FindElement(By.Id("CancelWizard")).GetAttribute("href"); + Assert.EndsWith(walletTransactionUri.AbsolutePath, cancelUrl); // Broadcast Assert.Contains(bob.ToString(), s.Driver.PageSource); Assert.Contains("1.00000000", s.Driver.PageSource); s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click(); - Assert.Equal(walletTransactionLink, s.Driver.Url); + Assert.Equal(walletTransactionUri.ToString(), s.Driver.Url); s.Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click(); s.Driver.FindElement(By.Id("WalletNav-Send")).Click(); @@ -1147,7 +1157,7 @@ namespace BTCPayServer.Tests Assert.Contains("0.01000000", s.Driver.PageSource); Assert.EndsWith("psbt/ready", s.Driver.Url); s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click(); - Assert.Equal(walletTransactionLink, s.Driver.Url); + Assert.Equal(walletTransactionUri.ToString(), s.Driver.Url); var bip21 = invoice.EntityToDTO().CryptoInfo.First().PaymentUrls.BIP21; //let's make bip21 more interesting @@ -1166,7 +1176,7 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("CancelWizard")).Click(); s.GoToWalletSettings(cryptoCode); - var settingsUrl = s.Driver.Url; + var settingsUri = new Uri(s.Driver.Url); s.Driver.FindElement(By.Id("ActionsDropdownToggle")).Click(); s.Driver.FindElement(By.Id("ViewSeed")).Click(); @@ -1180,7 +1190,16 @@ namespace BTCPayServer.Tests // No confirmation, just a link to return to the wallet Assert.Empty(s.Driver.FindElements(By.Id("confirm"))); s.Driver.FindElement(By.Id("proceed")).Click(); - Assert.Equal(settingsUrl, s.Driver.Url); + Assert.Equal(settingsUri.ToString(), s.Driver.Url); + + // Once more, test the cancel link of the wallet send page leads back to the previous page + s.Driver.FindElement(By.Id("WalletNav-Send")).Click(); + cancelUrl = s.Driver.FindElement(By.Id("CancelWizard")).GetAttribute("href"); + Assert.EndsWith(settingsUri.AbsolutePath, cancelUrl); + // no previous page in the wizard, hence no back button + Assert.True(s.Driver.ElementDoesNotExist(By.Id("GoBack"))); + s.Driver.FindElement(By.Id("CancelWizard")).Click(); + Assert.Equal(settingsUri.ToString(), s.Driver.Url); // Transactions list contains export and action, ensure functions are present. s.Driver.FindElement(By.Id($"StoreNav-Wallet{cryptoCode}")).Click();