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="Selenium.Support" 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.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>

View File

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

View File

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

View File

@ -102,7 +102,12 @@ namespace BTCPayServer.Tests
IWebElement el;
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)
{
@ -110,6 +115,8 @@ namespace BTCPayServer.Tests
}
if (el is null)
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;
}

View File

@ -114,28 +114,29 @@ namespace BTCPayServer.Tests
var tester = s.Server;
var u1 = tester.NewAccount();
u1.GrantAccess();
await u1.GrantAccessAsync();
await u1.MakeAdmin(false);
var u2 = tester.NewAccount();
u2.GrantAccess();
await u2.GrantAccessAsync();
await u2.MakeAdmin(false);
s.GoToLogin();
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")).SendKeys(u2.RegisterDetails.Email);
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();
var changedEmail = Guid.NewGuid() + "@lol.com";
s.Driver.FindElement(By.Id("Email")).SendKeys(changedEmail);
s.Driver.FindElement(By.Id("save")).Click();
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
s.FindAlertMessage();
var manager = tester.PayTester.GetService<UserManager<ApplicationUser>>();
Assert.NotNull(await manager.FindByNameAsync(changedEmail));
@ -1014,8 +1015,9 @@ namespace BTCPayServer.Tests
public async Task CanUsePullPaymentsViaUI()
{
using var s = CreateSeleniumTester();
s.Server.ActivateLightning();
s.Server.ActivateLightning(LightningConnectionType.LndREST);
await s.StartAsync();
await s.Server.EnsureChannelsSetup();
s.RegisterNewUser(true);
s.CreateNewStore();
s.GenerateWallet("BTC", "", true, true);
@ -1165,8 +1167,15 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id($"{PayoutState.InProgress}-view")).Click();
Assert.Contains(tx.ToString(), s.Driver.PageSource);
//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();
s.AddLightningNode("BTC");
//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("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")).SendKeys("BTC");
s.Driver.FindElement(By.Id("Create")).Click();
s.Driver.FindElement(By.LinkText("View")).Click();
var bolt = (await s.Server.MerchantLnd.Client.CreateInvoice(
LightMoney.FromUnit(0.00001m, LightMoneyUnit.BTC),
var bolt = (await s.Server.CustomerLightningD.CreateInvoice(
payoutAmount,
$"LN payout test {DateTime.Now.Ticks}",
TimeSpan.FromHours(1), CancellationToken.None)).BOLT11;
s.Driver.FindElement(By.Id("Destination")).SendKeys(bolt);
@ -1201,8 +1210,8 @@ namespace BTCPayServer.Tests
//we do not allow short-life bolts.
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error);
bolt = (await s.Server.MerchantLnd.Client.CreateInvoice(
LightMoney.FromUnit(0.00001m, LightMoneyUnit.BTC),
bolt = (await s.Server.CustomerLightningD.CreateInvoice(
payoutAmount,
$"LN payout test {DateTime.Now.Ticks}",
TimeSpan.FromDays(31), CancellationToken.None)).BOLT11;
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}-approve-pay")).Click();
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();
//lightning config in tests is very unstable so we can just go ahead and handle it as both
s.FindAlertMessage(new[]
{
StatusMessageModel.StatusSeverity.Error, StatusMessageModel.StatusSeverity.Success
});
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
s.GoToStore(newStore.storeId, StoreNavPages.Payouts);
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();
var network = s.Server.NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode).NBitcoinNetwork;
s.GoToStore(storeId);
s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning);
s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning, false);
s.GoToLightningSettings(storeId, cryptoCode);
// LNURL is false by default
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
// 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);
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);
s.GoToInvoiceCheckout(i);

View File

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

View File

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

View File

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

View File

@ -123,7 +123,7 @@
</div>
@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">
<vc:icon symbol="close" />
</button>