Test improvement exposing failing test (#3120)

* Test improvement exposing failing test

* Test fixes

* Fix test

* update alt compose

* Fix test CanUsePullPaymentsViaUI

* Fix CanChangeUserMail

Co-authored-by: Kukks <evilkukka@gmail.com>
Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
d11n 2021-11-26 07:02:30 +01:00 committed by GitHub
parent 9b730e784f
commit e9074a8ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 46 deletions

View File

@ -23,7 +23,7 @@
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" /> <PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="Selenium.Support" Version="3.141.0" /> <PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" /> <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="94.0.4606.6100" /> <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="96.0.4664.4500" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View File

@ -131,7 +131,7 @@ namespace BTCPayServer.Tests
var el = driver.FindElement(selector); var el = driver.FindElement(selector);
wait.Until(d => el.Displayed && el.Enabled); wait.Until(d => el.Displayed && el.Enabled);
driver.ScrollTo(selector); driver.ScrollTo(selector);
el.Click(); driver.FindElement(selector).Click();
} }
catch (ElementClickInterceptedException) when (retriesLeft > 0) catch (ElementClickInterceptedException) when (retriesLeft > 0)
{ {

View File

@ -1,4 +1,5 @@
using System; using System;
using BTCPayServer.Lightning;
using BTCPayServer.Lightning.LND; using BTCPayServer.Lightning.LND;
using NBitcoin; using NBitcoin;
@ -19,7 +20,7 @@ namespace BTCPayServer.Tests.Lnd
} }
public LndSwaggerClient Swagger { get; set; } public LndSwaggerClient Swagger { get; set; }
public LndClient Client { get; set; } public ILightningClient Client { get; set; }
public string P2PHost { get; } public string P2PHost { get; }
} }
} }

View File

@ -102,7 +102,12 @@ namespace BTCPayServer.Tests
IWebElement el; IWebElement el;
try try
{ {
el = Driver.FindElement(By.CssSelector(className)); var elements = Driver.FindElements(By.CssSelector(className));
el = elements.FirstOrDefault(e => e.Displayed);
if (el is null)
el = elements.FirstOrDefault();
if (el is null)
el = Driver.WaitForElement(By.CssSelector(className));
} }
catch (NoSuchElementException) catch (NoSuchElementException)
{ {
@ -110,6 +115,8 @@ namespace BTCPayServer.Tests
} }
if (el is null) if (el is null)
throw new NoSuchElementException($"Unable to find {className}"); throw new NoSuchElementException($"Unable to find {className}");
if (!el.Displayed)
throw new ElementNotVisibleException($"{className} is present, but not displayed: {el.GetAttribute("id")} - Text: {el.Text}");
return el; return el;
} }

View File

@ -114,28 +114,29 @@ namespace BTCPayServer.Tests
var tester = s.Server; var tester = s.Server;
var u1 = tester.NewAccount(); var u1 = tester.NewAccount();
u1.GrantAccess(); await u1.GrantAccessAsync();
await u1.MakeAdmin(false); await u1.MakeAdmin(false);
var u2 = tester.NewAccount(); var u2 = tester.NewAccount();
u2.GrantAccess(); await u2.GrantAccessAsync();
await u2.MakeAdmin(false); await u2.MakeAdmin(false);
s.GoToLogin(); s.GoToLogin();
s.Login(u1.RegisterDetails.Email, u1.RegisterDetails.Password); s.Login(u1.RegisterDetails.Email, u1.RegisterDetails.Password);
s.GoToProfile(ManageNavPages.Index); s.GoToProfile();
s.Driver.FindElement(By.Id("Email")).Clear(); s.Driver.FindElement(By.Id("Email")).Clear();
s.Driver.FindElement(By.Id("Email")).SendKeys(u2.RegisterDetails.Email); s.Driver.FindElement(By.Id("Email")).SendKeys(u2.RegisterDetails.Email);
s.Driver.FindElement(By.Id("save")).Click(); s.Driver.FindElement(By.Id("save")).Click();
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error); Assert.Contains("The email address is already in use with an other account.",
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error).Text);
s.GoToProfile(ManageNavPages.Index); s.GoToProfile();
s.Driver.FindElement(By.Id("Email")).Clear(); s.Driver.FindElement(By.Id("Email")).Clear();
var changedEmail = Guid.NewGuid() + "@lol.com"; var changedEmail = Guid.NewGuid() + "@lol.com";
s.Driver.FindElement(By.Id("Email")).SendKeys(changedEmail); s.Driver.FindElement(By.Id("Email")).SendKeys(changedEmail);
s.Driver.FindElement(By.Id("save")).Click(); s.Driver.FindElement(By.Id("save")).Click();
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success); s.FindAlertMessage();
var manager = tester.PayTester.GetService<UserManager<ApplicationUser>>(); var manager = tester.PayTester.GetService<UserManager<ApplicationUser>>();
Assert.NotNull(await manager.FindByNameAsync(changedEmail)); Assert.NotNull(await manager.FindByNameAsync(changedEmail));
@ -1014,8 +1015,9 @@ namespace BTCPayServer.Tests
public async Task CanUsePullPaymentsViaUI() public async Task CanUsePullPaymentsViaUI()
{ {
using var s = CreateSeleniumTester(); using var s = CreateSeleniumTester();
s.Server.ActivateLightning(); s.Server.ActivateLightning(LightningConnectionType.LndREST);
await s.StartAsync(); await s.StartAsync();
await s.Server.EnsureChannelsSetup();
s.RegisterNewUser(true); s.RegisterNewUser(true);
s.CreateNewStore(); s.CreateNewStore();
s.GenerateWallet("BTC", "", true, true); s.GenerateWallet("BTC", "", true, true);
@ -1165,8 +1167,15 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id($"{PayoutState.InProgress}-view")).Click(); s.Driver.FindElement(By.Id($"{PayoutState.InProgress}-view")).Click();
Assert.Contains(tx.ToString(), s.Driver.PageSource); Assert.Contains(tx.ToString(), s.Driver.PageSource);
//lightning tests //lightning tests
// Since the merchant is sending on lightning, it needs some liquidity from the client
var payoutAmount = LightMoney.Satoshis(1000);
var minimumReserve = LightMoney.Satoshis(167773m);
var inv = await s.Server.MerchantLnd.Client.CreateInvoice(minimumReserve + payoutAmount, "Donation to merchant", TimeSpan.FromHours(1), default);
var resp = await s.Server.CustomerLightningD.Pay(inv.BOLT11);
Assert.Equal(PayResult.Ok, resp.Result);
newStore = s.CreateNewStore(); newStore = s.CreateNewStore();
s.AddLightningNode("BTC"); s.AddLightningNode("BTC");
//Currently an onchain wallet is required to use the Lightning payouts feature.. //Currently an onchain wallet is required to use the Lightning payouts feature..
@ -1181,14 +1190,14 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("Name")).SendKeys("Lightning Test"); s.Driver.FindElement(By.Id("Name")).SendKeys("Lightning Test");
s.Driver.FindElement(By.Id("Amount")).Clear(); s.Driver.FindElement(By.Id("Amount")).Clear();
s.Driver.FindElement(By.Id("Amount")).SendKeys("0.00001"); s.Driver.FindElement(By.Id("Amount")).SendKeys(payoutAmount.ToString());
s.Driver.FindElement(By.Id("Currency")).Clear(); s.Driver.FindElement(By.Id("Currency")).Clear();
s.Driver.FindElement(By.Id("Currency")).SendKeys("BTC"); s.Driver.FindElement(By.Id("Currency")).SendKeys("BTC");
s.Driver.FindElement(By.Id("Create")).Click(); s.Driver.FindElement(By.Id("Create")).Click();
s.Driver.FindElement(By.LinkText("View")).Click(); s.Driver.FindElement(By.LinkText("View")).Click();
var bolt = (await s.Server.MerchantLnd.Client.CreateInvoice( var bolt = (await s.Server.CustomerLightningD.CreateInvoice(
LightMoney.FromUnit(0.00001m, LightMoneyUnit.BTC), payoutAmount,
$"LN payout test {DateTime.Now.Ticks}", $"LN payout test {DateTime.Now.Ticks}",
TimeSpan.FromHours(1), CancellationToken.None)).BOLT11; TimeSpan.FromHours(1), CancellationToken.None)).BOLT11;
s.Driver.FindElement(By.Id("Destination")).SendKeys(bolt); s.Driver.FindElement(By.Id("Destination")).SendKeys(bolt);
@ -1201,8 +1210,8 @@ namespace BTCPayServer.Tests
//we do not allow short-life bolts. //we do not allow short-life bolts.
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error); s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error);
bolt = (await s.Server.MerchantLnd.Client.CreateInvoice( bolt = (await s.Server.CustomerLightningD.CreateInvoice(
LightMoney.FromUnit(0.00001m, LightMoneyUnit.BTC), payoutAmount,
$"LN payout test {DateTime.Now.Ticks}", $"LN payout test {DateTime.Now.Ticks}",
TimeSpan.FromDays(31), CancellationToken.None)).BOLT11; TimeSpan.FromDays(31), CancellationToken.None)).BOLT11;
s.Driver.FindElement(By.Id("Destination")).Clear(); s.Driver.FindElement(By.Id("Destination")).Clear();
@ -1224,14 +1233,10 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-actions")).Click(); s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-actions")).Click();
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-approve-pay")).Click(); s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-approve-pay")).Click();
Assert.Contains(bolt, s.Driver.PageSource); Assert.Contains(bolt, s.Driver.PageSource);
Assert.Contains("0.00001 BTC", s.Driver.PageSource); Assert.Contains($"{payoutAmount.ToString()} BTC", s.Driver.PageSource);
s.Driver.FindElement(By.CssSelector("#pay-invoices-form")).Submit(); s.Driver.FindElement(By.CssSelector("#pay-invoices-form")).Submit();
//lightning config in tests is very unstable so we can just go ahead and handle it as both
s.FindAlertMessage(new[] s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
{
StatusMessageModel.StatusSeverity.Error, StatusMessageModel.StatusSeverity.Success
});
s.GoToStore(newStore.storeId, StoreNavPages.Payouts); s.GoToStore(newStore.storeId, StoreNavPages.Payouts);
s.Driver.FindElement(By.Id($"{new PaymentMethodId("BTC", PaymentTypes.LightningLike)}-view")).Click(); s.Driver.FindElement(By.Id($"{new PaymentMethodId("BTC", PaymentTypes.LightningLike)}-view")).Click();
@ -1313,7 +1318,7 @@ namespace BTCPayServer.Tests
(string storeName, string storeId) = s.CreateNewStore(); (string storeName, string storeId) = s.CreateNewStore();
var network = s.Server.NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode).NBitcoinNetwork; var network = s.Server.NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode).NBitcoinNetwork;
s.GoToStore(storeId); s.GoToStore(storeId);
s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning); s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning, false);
s.GoToLightningSettings(storeId, cryptoCode); s.GoToLightningSettings(storeId, cryptoCode);
// LNURL is false by default // LNURL is false by default
Assert.False(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected); Assert.False(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected);
@ -1420,10 +1425,13 @@ namespace BTCPayServer.Tests
//TODO: DisableBolt11PaymentMethod is actually disabled because LNURLStandardInvoiceEnabled is disabled //TODO: DisableBolt11PaymentMethod is actually disabled because LNURLStandardInvoiceEnabled is disabled
// checkboxes is not good choice here, in next release we should have multi choice instead // checkboxes is not good choice here, in next release we should have multi choice instead
Assert.False(s.Driver.FindElement(By.Id("DisableBolt11PaymentMethod")).Selected);
Assert.False(s.Driver.FindElement(By.Id("LNURLStandardInvoiceEnabled")).Selected);
Assert.False(s.Driver.FindElement(By.Id("LNURLBech32Mode")).Selected); Assert.False(s.Driver.FindElement(By.Id("LNURLBech32Mode")).Selected);
s.CreateInvoice(storeName, 0.0000001m, cryptoCode,"",null, expectedSeverity: StatusMessageModel.StatusSeverity.Error); Assert.False(s.Driver.FindElement(By.Id("LNURLStandardInvoiceEnabled")).Selected);
//even though we set DisableBolt11PaymentMethod to true, logic when saving it turns it back off as otherwise no lightning option is available at all!
Assert.False(s.Driver.FindElement(By.Id("DisableBolt11PaymentMethod")).Selected);
// Invoice creation should fail, because it is a standard invoice with amount, but DisableBolt11PaymentMethod = true and LNURLStandardInvoiceEnabled = false
s.CreateInvoice(storeName, 0.0000001m, cryptoCode,"",null, expectedSeverity: StatusMessageModel.StatusSeverity.Success);
i = s.CreateInvoice(storeName, null, cryptoCode); i = s.CreateInvoice(storeName, null, cryptoCode);
s.GoToInvoiceCheckout(i); s.GoToInvoiceCheckout(i);

View File

@ -234,7 +234,7 @@ services:
- "5432" - "5432"
merchant_lnd: merchant_lnd:
image: btcpayserver/lnd:v0.14.0-beta image: btcpayserver/lnd:v0.14.1-beta
restart: unless-stopped restart: unless-stopped
environment: environment:
LND_CHAIN: "btc" LND_CHAIN: "btc"
@ -268,7 +268,7 @@ services:
- bitcoind - bitcoind
customer_lnd: customer_lnd:
image: btcpayserver/lnd:v0.14.0-beta image: btcpayserver/lnd:v0.14.1-beta
restart: unless-stopped restart: unless-stopped
environment: environment:
LND_CHAIN: "btc" LND_CHAIN: "btc"

View File

@ -222,7 +222,7 @@ services:
- "5432" - "5432"
merchant_lnd: merchant_lnd:
image: btcpayserver/lnd:v0.14.0-beta image: btcpayserver/lnd:v0.14.1-beta
restart: unless-stopped restart: unless-stopped
environment: environment:
LND_CHAIN: "btc" LND_CHAIN: "btc"
@ -256,7 +256,7 @@ services:
- bitcoind - bitcoind
customer_lnd: customer_lnd:
image: btcpayserver/lnd:v0.14.0-beta image: btcpayserver/lnd:v0.14.1-beta
restart: unless-stopped restart: unless-stopped
environment: environment:
LND_CHAIN: "btc" LND_CHAIN: "btc"

View File

@ -2,23 +2,24 @@
@model System.Collections.Generic.List<BTCPayServer.Data.Payouts.LightningLike.LightningLikePayoutController.ResultVM> @model System.Collections.Generic.List<BTCPayServer.Data.Payouts.LightningLike.LightningLikePayoutController.ResultVM>
@{ @{
Layout = "_Layout"; Layout = "_Layout";
ViewData["Title"] = $"Lightning Payout Result"; ViewData["Title"] = "Lightning Payout Result";
} }
<section> <section>
<div class="container"> <div class="container">
<h2 class="mb-4">@ViewData["Title"]</h2> <h2 class="mb-4">@ViewData["Title"]</h2>
<div class="row"> @foreach (var item in Model)
<div class="col-md-12"> {
<ul class="list-group"> <div class="alert alert-@(item.Result == PayResult.Ok ? "success" : "danger") d-flex justify-content-between align-items-center mb-3" role="alert">
@foreach (var item in Model) @if (item.Result == PayResult.Ok)
{ {
<li class="list-group-item d-flex justify-content-between align-items-center @(item.Result == PayResult.Ok ? "bg-success" : "bg-danger")"> <div class="text-break me-3" title="@item.Destination">@item.Destination</div>
<div class="text-break" title="@item.Destination">@item.Destination</div> }
<span class="badge bg-secondary">@(item.Result == PayResult.Ok ? "Sent" : "Failed")</span> else
</li> {
} <div class="text-break me-3" title="@item.Destination">@item.Destination: @item.Message (@item.Result)</div>
</ul> }
<span class="badge fs-5">@(item.Result == PayResult.Ok ? "Sent" : "Failed")</span>
</div> </div>
</div> }
</div> </div>
</section> </section>

View File

@ -123,7 +123,7 @@
</div> </div>
@if (!Env.IsSecure) @if (!Env.IsSecure)
{ {
<div class="alert alert-danger alert-dismissible" style="position:absolute; top:75px;" role="alert"> <div id="insecureEnv" class="alert alert-danger alert-dismissible" style="position:absolute; top:75px;" role="alert">
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
<vc:icon symbol="close" /> <vc:icon symbol="close" />
</button> </button>