mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Fix tests
This commit is contained in:
@@ -51,6 +51,7 @@ namespace BTCPayServer.Tests
|
|||||||
user.RegisterDerivationScheme(cryptoCode);
|
user.RegisterDerivationScheme(cryptoCode);
|
||||||
user.RegisterDerivationScheme("LTC");
|
user.RegisterDerivationScheme("LTC");
|
||||||
user.RegisterLightningNode(cryptoCode, LightningConnectionType.CLightning);
|
user.RegisterLightningNode(cryptoCode, LightningConnectionType.CLightning);
|
||||||
|
user.SetLNUrl("BTC", false);
|
||||||
var btcNetwork = tester.PayTester.Networks.GetNetwork<BTCPayNetwork>(cryptoCode);
|
var btcNetwork = tester.PayTester.Networks.GetNetwork<BTCPayNetwork>(cryptoCode);
|
||||||
var invoice = await user.BitPay.CreateInvoiceAsync(
|
var invoice = await user.BitPay.CreateInvoiceAsync(
|
||||||
new Invoice
|
new Invoice
|
||||||
|
|||||||
@@ -45,13 +45,6 @@ namespace BTCPayServer.Tests
|
|||||||
s.Driver.FindElement(By.Id("Save")).Click();
|
s.Driver.FindElement(By.Id("Save")).Click();
|
||||||
Assert.Contains("Store successfully updated", s.FindAlertMessage().Text);
|
Assert.Contains("Store successfully updated", s.FindAlertMessage().Text);
|
||||||
|
|
||||||
// Enable LNURL, which we will need for (non-)presence checks throughout this test
|
|
||||||
s.GoToHome();
|
|
||||||
s.GoToLightningSettings();
|
|
||||||
s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true);
|
|
||||||
s.Driver.FindElement(By.Id("save")).Click();
|
|
||||||
Assert.Contains("BTC Lightning settings successfully updated", s.FindAlertMessage().Text);
|
|
||||||
|
|
||||||
s.GoToStore(StoreNavPages.CheckoutAppearance);
|
s.GoToStore(StoreNavPages.CheckoutAppearance);
|
||||||
s.Driver.WaitForAndClick(By.Id("Presets"));
|
s.Driver.WaitForAndClick(By.Id("Presets"));
|
||||||
s.Driver.WaitForAndClick(By.Id("Presets_InStore"));
|
s.Driver.WaitForAndClick(By.Id("Presets_InStore"));
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
public async Task<PayResponse> SendLightningPaymentAsync(Invoice invoice)
|
public async Task<PayResponse> SendLightningPaymentAsync(Invoice invoice)
|
||||||
{
|
{
|
||||||
var bolt11 = invoice.CryptoInfo.Where(o => o.PaymentUrls.BOLT11 != null).First().PaymentUrls.BOLT11;
|
var bolt11 = invoice.CryptoInfo.Where(o => o.PaymentUrls?.BOLT11 != null).First().PaymentUrls.BOLT11;
|
||||||
bolt11 = bolt11.Replace("lightning:", "", StringComparison.OrdinalIgnoreCase);
|
bolt11 = bolt11.Replace("lightning:", "", StringComparison.OrdinalIgnoreCase);
|
||||||
return await CustomerLightningD.Pay(bolt11);
|
return await CustomerLightningD.Pay(bolt11);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,13 @@ namespace BTCPayServer.Tests
|
|||||||
get => GenerateWalletResponseV.DerivationScheme;
|
get => GenerateWalletResponseV.DerivationScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetLNUrl(string cryptoCode, bool activated)
|
||||||
|
{
|
||||||
|
var lnSettingsVm = GetController<UIStoresController>().LightningSettings(StoreId, cryptoCode).AssertViewModel<LightningSettingsViewModel>();
|
||||||
|
lnSettingsVm.LNURLEnabled = activated;
|
||||||
|
Assert.IsType<RedirectToActionResult>(GetController<UIStoresController>().LightningSettings(lnSettingsVm).Result);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task RegisterAsync(bool isAdmin = false)
|
private async Task RegisterAsync(bool isAdmin = false)
|
||||||
{
|
{
|
||||||
var account = parent.PayTester.GetController<UIAccountController>();
|
var account = parent.PayTester.GetController<UIAccountController>();
|
||||||
|
|||||||
@@ -1635,6 +1635,7 @@ namespace BTCPayServer.Tests
|
|||||||
var cryptoCode = "BTC";
|
var cryptoCode = "BTC";
|
||||||
user.GrantAccess(true);
|
user.GrantAccess(true);
|
||||||
user.RegisterLightningNode(cryptoCode, LightningConnectionType.Charge);
|
user.RegisterLightningNode(cryptoCode, LightningConnectionType.Charge);
|
||||||
|
user.SetLNUrl(cryptoCode, false);
|
||||||
var vm = user.GetController<UIStoresController>().CheckoutAppearance().AssertViewModel<CheckoutAppearanceViewModel>();
|
var vm = user.GetController<UIStoresController>().CheckoutAppearance().AssertViewModel<CheckoutAppearanceViewModel>();
|
||||||
var criteria = Assert.Single(vm.PaymentMethodCriteria);
|
var criteria = Assert.Single(vm.PaymentMethodCriteria);
|
||||||
Assert.Equal(new PaymentMethodId(cryptoCode, LightningPaymentType.Instance).ToString(), criteria.PaymentMethod);
|
Assert.Equal(new PaymentMethodId(cryptoCode, LightningPaymentType.Instance).ToString(), criteria.PaymentMethod);
|
||||||
@@ -1649,15 +1650,12 @@ namespace BTCPayServer.Tests
|
|||||||
Price = 1.5m,
|
Price = 1.5m,
|
||||||
Currency = "USD"
|
Currency = "USD"
|
||||||
}, Facade.Merchant);
|
}, Facade.Merchant);
|
||||||
|
|
||||||
Assert.Single(invoice.CryptoInfo);
|
Assert.Single(invoice.CryptoInfo);
|
||||||
Assert.Equal(PaymentTypes.LightningLike.ToString(), invoice.CryptoInfo[0].PaymentType);
|
Assert.Equal(PaymentTypes.LightningLike.ToString(), invoice.CryptoInfo[0].PaymentType);
|
||||||
|
|
||||||
// Activating LNUrl, we should still have only 1 payment criteria that can be set.
|
// Activating LNUrl, we should still have only 1 payment criteria that can be set.
|
||||||
user.RegisterLightningNode(cryptoCode, LightningConnectionType.Charge);
|
user.RegisterLightningNode(cryptoCode, LightningConnectionType.Charge);
|
||||||
var lnSettingsVm = user.GetController<UIStoresController>().LightningSettings(user.StoreId, cryptoCode).AssertViewModel<LightningSettingsViewModel>();
|
user.SetLNUrl(cryptoCode, true);
|
||||||
lnSettingsVm.LNURLEnabled = true;
|
|
||||||
Assert.IsType<RedirectToActionResult>(user.GetController<UIStoresController>().LightningSettings(lnSettingsVm).Result);
|
|
||||||
vm = user.GetController<UIStoresController>().CheckoutAppearance().AssertViewModel<CheckoutAppearanceViewModel>();
|
vm = user.GetController<UIStoresController>().CheckoutAppearance().AssertViewModel<CheckoutAppearanceViewModel>();
|
||||||
criteria = Assert.Single(vm.PaymentMethodCriteria);
|
criteria = Assert.Single(vm.PaymentMethodCriteria);
|
||||||
Assert.Equal(new PaymentMethodId(cryptoCode, LightningPaymentType.Instance).ToString(), criteria.PaymentMethod);
|
Assert.Equal(new PaymentMethodId(cryptoCode, LightningPaymentType.Instance).ToString(), criteria.PaymentMethod);
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ namespace BTCPayServer.Controllers
|
|||||||
if (displayedPaymentMethods.Contains(lnId) && displayedPaymentMethods.Contains(lnurlId))
|
if (displayedPaymentMethods.Contains(lnId) && displayedPaymentMethods.Contains(lnurlId))
|
||||||
displayedPaymentMethods.Remove(lnurlId);
|
displayedPaymentMethods.Remove(lnurlId);
|
||||||
|
|
||||||
if (paymentMethodId is not null && displayedPaymentMethods.Contains(paymentMethodId))
|
if (paymentMethodId is not null && !displayedPaymentMethods.Contains(paymentMethodId))
|
||||||
paymentMethodId = null;
|
paymentMethodId = null;
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,49 +50,21 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
BTCPayNetwork network, object preparePaymentObject, IEnumerable<PaymentMethodId> invoicePaymentMethods)
|
BTCPayNetwork network, object preparePaymentObject, IEnumerable<PaymentMethodId> invoicePaymentMethods)
|
||||||
{
|
{
|
||||||
var lnPmi = new PaymentMethodId(supportedPaymentMethod.CryptoCode, PaymentTypes.LightningLike);
|
var lnPmi = new PaymentMethodId(supportedPaymentMethod.CryptoCode, PaymentTypes.LightningLike);
|
||||||
if (string.IsNullOrEmpty(paymentMethod.ParentEntity.Id))
|
var lnSupported = store.GetSupportedPaymentMethods(_networkProvider)
|
||||||
|
.OfType<LightningSupportedPaymentMethod>()
|
||||||
|
.SingleOrDefault(method => method.PaymentId == lnPmi);
|
||||||
|
if (lnSupported is null)
|
||||||
{
|
{
|
||||||
var lnSupported = store.GetSupportedPaymentMethods(_networkProvider)
|
throw new PaymentMethodUnavailableException("LNURL requires a lightning node to be configured for the store.");
|
||||||
.OfType<LightningSupportedPaymentMethod>().SingleOrDefault(method =>
|
|
||||||
method.PaymentId.CryptoCode == supportedPaymentMethod.CryptoCode &&
|
|
||||||
method.PaymentId.PaymentType == LightningPaymentType.Instance);
|
|
||||||
|
|
||||||
if (lnSupported is null)
|
|
||||||
{
|
|
||||||
throw new PaymentMethodUnavailableException("LNURL requires a lightning node to be configured for the store.");
|
|
||||||
}
|
|
||||||
using var cts = new CancellationTokenSource(LightningLikePaymentHandler.LightningTimeout);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var client = lnSupported.CreateLightningClient(network, Options.Value, _lightningClientFactoryService);
|
|
||||||
await client.GetInfo(cts.Token);
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException) when (cts.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
throw new PaymentMethodUnavailableException("The lightning node did not reply in a timely manner");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LNURLPayPaymentMethodDetails()
|
|
||||||
{
|
|
||||||
Activated = false,
|
|
||||||
LightningSupportedPaymentMethod = lnSupported
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var client = lnSupported.CreateLightningClient(network, Options.Value, _lightningClientFactoryService);
|
||||||
|
var nodeInfo = (await _lightningLikePaymentHandler.GetNodeInfo(lnSupported, _networkProvider.GetNetwork<BTCPayNetwork>(supportedPaymentMethod.CryptoCode), logs, paymentMethod.PreferOnion)).FirstOrDefault();
|
||||||
|
|
||||||
var lnLightningSupportedPaymentMethod =
|
return new LNURLPayPaymentMethodDetails()
|
||||||
((LNURLPayPaymentMethodDetails)paymentMethod.GetPaymentMethodDetails()).LightningSupportedPaymentMethod;
|
|
||||||
|
|
||||||
NodeInfo? nodeInfo = null;
|
|
||||||
if (lnLightningSupportedPaymentMethod != null)
|
|
||||||
{
|
|
||||||
nodeInfo = (await _lightningLikePaymentHandler.GetNodeInfo(lnLightningSupportedPaymentMethod, _networkProvider.GetNetwork<BTCPayNetwork>(supportedPaymentMethod.CryptoCode), logs, paymentMethod.PreferOnion)).FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LNURLPayPaymentMethodDetails
|
|
||||||
{
|
{
|
||||||
Activated = true,
|
Activated = true,
|
||||||
LightningSupportedPaymentMethod = lnLightningSupportedPaymentMethod,
|
LightningSupportedPaymentMethod = lnSupported,
|
||||||
Bech32Mode = supportedPaymentMethod.UseBech32Scheme,
|
Bech32Mode = supportedPaymentMethod.UseBech32Scheme,
|
||||||
NodeInfo = nodeInfo?.ToString()
|
NodeInfo = nodeInfo?.ToString()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -213,12 +213,18 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
}
|
}
|
||||||
var paymentDestination = details.GetPaymentDestination();
|
var paymentDestination = details.GetPaymentDestination();
|
||||||
string address = GetDestination(paymentMethod);
|
string address = GetDestination(paymentMethod);
|
||||||
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
|
if (address != null)
|
||||||
{
|
{
|
||||||
InvoiceDataId = invoice.Id,
|
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
|
||||||
CreatedTime = DateTimeOffset.UtcNow,
|
{
|
||||||
}.Set(address, paymentMethod.GetId()));
|
InvoiceDataId = invoice.Id,
|
||||||
textSearch.Add(paymentDestination);
|
CreatedTime = DateTimeOffset.UtcNow,
|
||||||
|
}.Set(address, paymentMethod.GetId()));
|
||||||
|
}
|
||||||
|
if (paymentDestination != null)
|
||||||
|
{
|
||||||
|
textSearch.Add(paymentDestination);
|
||||||
|
}
|
||||||
textSearch.Add(paymentMethod.Calculate().TotalDue.ToString());
|
textSearch.Add(paymentMethod.Calculate().TotalDue.ToString());
|
||||||
}
|
}
|
||||||
await context.PendingInvoices.AddAsync(new PendingInvoiceData() { Id = invoice.Id });
|
await context.PendingInvoices.AddAsync(new PendingInvoiceData() { Id = invoice.Id });
|
||||||
|
|||||||
Reference in New Issue
Block a user