2020-06-29 04:44:35 +02:00
|
|
|
using System;
|
2021-04-13 10:36:49 +02:00
|
|
|
using System.Collections.ObjectModel;
|
2020-06-28 10:55:27 +02:00
|
|
|
using System.Globalization;
|
2019-05-12 10:13:26 +02:00
|
|
|
using System.Linq;
|
2021-10-26 13:55:13 +02:00
|
|
|
using System.Net.Http;
|
2021-10-29 11:01:16 +02:00
|
|
|
using System.Net.Security;
|
|
|
|
using System.Security.Authentication;
|
2020-11-06 12:42:26 +01:00
|
|
|
using System.Text;
|
2019-10-12 13:35:30 +02:00
|
|
|
using System.Text.RegularExpressions;
|
2021-10-18 05:37:59 +02:00
|
|
|
using System.Threading;
|
2020-06-28 10:55:27 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-11-17 13:46:23 +01:00
|
|
|
using BTCPayServer.Abstractions.Models;
|
2020-11-06 12:42:26 +01:00
|
|
|
using BTCPayServer.Client.Models;
|
2020-03-25 07:59:30 +01:00
|
|
|
using BTCPayServer.Data;
|
2021-10-18 05:37:59 +02:00
|
|
|
using BTCPayServer.Lightning;
|
|
|
|
using BTCPayServer.Lightning.Charge;
|
2021-10-26 13:55:13 +02:00
|
|
|
using BTCPayServer.Lightning.CLightning;
|
2021-10-18 05:37:59 +02:00
|
|
|
using BTCPayServer.Lightning.LND;
|
|
|
|
using BTCPayServer.Payments;
|
2021-04-17 06:29:50 +02:00
|
|
|
using BTCPayServer.Services;
|
2021-10-26 13:55:13 +02:00
|
|
|
using BTCPayServer.Services.Invoices;
|
2020-03-25 07:59:30 +01:00
|
|
|
using BTCPayServer.Services.Wallets;
|
2020-06-28 10:55:27 +02:00
|
|
|
using BTCPayServer.Tests.Logging;
|
2021-02-12 04:21:29 +01:00
|
|
|
using BTCPayServer.Views.Manage;
|
2020-09-16 08:54:09 +02:00
|
|
|
using BTCPayServer.Views.Server;
|
2021-04-07 06:08:42 +02:00
|
|
|
using BTCPayServer.Views.Stores;
|
2020-04-28 08:06:28 +02:00
|
|
|
using BTCPayServer.Views.Wallets;
|
2021-10-26 13:55:13 +02:00
|
|
|
using LNURL;
|
2021-02-12 04:21:29 +01:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
2020-06-24 03:34:09 +02:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2020-06-28 10:55:27 +02:00
|
|
|
using NBitcoin;
|
2020-11-06 12:42:26 +01:00
|
|
|
using NBitcoin.DataEncoders;
|
2020-06-28 10:55:27 +02:00
|
|
|
using NBitcoin.Payment;
|
2020-11-06 12:42:26 +01:00
|
|
|
using Newtonsoft.Json.Linq;
|
2020-06-28 10:55:27 +02:00
|
|
|
using OpenQA.Selenium;
|
2020-11-06 12:42:26 +01:00
|
|
|
using OpenQA.Selenium.Support.Extensions;
|
|
|
|
using OpenQA.Selenium.Support.UI;
|
|
|
|
using Renci.SshNet.Security.Cryptography;
|
2020-06-28 10:55:27 +02:00
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
2021-10-18 05:37:59 +02:00
|
|
|
using CreateInvoiceRequest = BTCPayServer.Lightning.Charge.CreateInvoiceRequest;
|
2019-05-12 10:13:26 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer.Tests
|
|
|
|
{
|
2019-05-13 11:42:20 +02:00
|
|
|
[Trait("Selenium", "Selenium")]
|
2021-11-22 09:16:08 +01:00
|
|
|
public class ChromeTests : UnitTestBase
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-01-22 17:49:26 +01:00
|
|
|
private const int TestTimeout = TestUtils.TestTimeout;
|
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
public ChromeTests(ITestOutputHelper helper) : base(helper)
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanNavigateServerSettings()
|
2019-05-13 10:59:15 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser(true);
|
|
|
|
s.Driver.FindElement(By.Id("ServerSettings")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
s.ClickOnAllSideMenus();
|
2019-11-16 06:06:37 +01:00
|
|
|
s.Driver.FindElement(By.LinkText("Services")).Click();
|
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's check if we can access the logs");
|
2019-12-24 10:11:21 +01:00
|
|
|
s.Driver.FindElement(By.LinkText("Logs")).Click();
|
|
|
|
s.Driver.FindElement(By.PartialLinkText(".log")).Click();
|
|
|
|
Assert.Contains("Starting listening NBXplorer", s.Driver.PageSource);
|
|
|
|
s.Driver.Quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
[Trait("Lightning", "Lightning")]
|
|
|
|
public async Task CanUseLndSeedBackup()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-12-24 10:11:21 +01:00
|
|
|
{
|
|
|
|
s.Server.ActivateLightning();
|
|
|
|
await s.StartAsync();
|
|
|
|
s.RegisterNewUser(true);
|
|
|
|
s.Driver.FindElement(By.Id("ServerSettings")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
s.Driver.FindElement(By.LinkText("Services")).Click();
|
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's if we can access LND's seed");
|
2019-11-16 06:06:37 +01:00
|
|
|
Assert.Contains("server/services/lndseedbackup/BTC", s.Driver.PageSource);
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/lndseedbackup/BTC"));
|
|
|
|
s.Driver.FindElement(By.Id("details")).Click();
|
2021-05-19 04:39:27 +02:00
|
|
|
var seedEl = s.Driver.FindElement(By.Id("Seed"));
|
2019-11-16 06:06:37 +01:00
|
|
|
Assert.True(seedEl.Displayed);
|
|
|
|
Assert.Contains("about over million", seedEl.Text, StringComparison.OrdinalIgnoreCase);
|
2021-05-19 04:39:27 +02:00
|
|
|
var passEl = s.Driver.FindElement(By.Id("WalletPassword"));
|
2019-11-16 06:06:37 +01:00
|
|
|
Assert.True(passEl.Displayed);
|
|
|
|
Assert.Contains(passEl.Text, "hellorockstar", StringComparison.OrdinalIgnoreCase);
|
|
|
|
s.Driver.FindElement(By.Id("delete")).Click();
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("DELETE");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2021-05-19 04:39:27 +02:00
|
|
|
seedEl = s.Driver.FindElement(By.Id("Seed"));
|
2019-11-16 06:06:37 +01:00
|
|
|
Assert.Contains("Seed removed", seedEl.Text, StringComparison.OrdinalIgnoreCase);
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-05-13 10:59:15 +02:00
|
|
|
}
|
|
|
|
|
2021-02-12 04:21:29 +01:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
[Trait("Selenium", "Selenium")]
|
|
|
|
public async Task CanChangeUserMail()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2021-02-12 04:21:29 +01:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
|
|
|
|
var tester = s.Server;
|
|
|
|
var u1 = tester.NewAccount();
|
|
|
|
u1.GrantAccess();
|
|
|
|
await u1.MakeAdmin(false);
|
|
|
|
|
|
|
|
var u2 = tester.NewAccount();
|
|
|
|
u2.GrantAccess();
|
|
|
|
await u2.MakeAdmin(false);
|
|
|
|
|
|
|
|
s.GoToLogin();
|
|
|
|
s.Login(u1.RegisterDetails.Email, u1.RegisterDetails.Password);
|
|
|
|
s.GoToProfile(ManageNavPages.Index);
|
|
|
|
s.Driver.FindElement(By.Id("Email")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(u2.RegisterDetails.Email);
|
|
|
|
s.Driver.FindElement(By.Id("save")).Click();
|
|
|
|
|
2021-02-17 04:14:29 +01:00
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error);
|
2021-02-12 04:21:29 +01:00
|
|
|
|
|
|
|
s.GoToProfile(ManageNavPages.Index);
|
|
|
|
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);
|
|
|
|
|
|
|
|
var manager = tester.PayTester.GetService<UserManager<ApplicationUser>>();
|
|
|
|
Assert.NotNull(await manager.FindByNameAsync(changedEmail));
|
|
|
|
Assert.NotNull(await manager.FindByEmailAsync(changedEmail));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task NewUserLogin()
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-09-11 09:22:41 +02:00
|
|
|
//Register & Log Out
|
|
|
|
var email = s.RegisterNewUser();
|
2020-09-16 08:54:09 +02:00
|
|
|
s.Logout();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.AssertNoError();
|
2021-01-28 10:08:22 +01:00
|
|
|
Assert.Contains("/login", s.Driver.Url);
|
2019-09-11 09:22:41 +02:00
|
|
|
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
|
|
|
|
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
|
|
|
|
|
|
|
|
// We should be redirected to login
|
|
|
|
//Same User Can Log Back In
|
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
|
|
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
|
|
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
|
|
|
|
|
|
|
// We should be redirected to invoice
|
|
|
|
Assert.EndsWith("/invoices", s.Driver.Url);
|
|
|
|
|
|
|
|
// Should not be able to reach server settings
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/users"));
|
|
|
|
Assert.Contains("ReturnUrl=%2Fserver%2Fusers", s.Driver.Url);
|
|
|
|
|
|
|
|
//Change Password & Log Out
|
|
|
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ChangePassword")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("OldPassword")).SendKeys("123456");
|
|
|
|
s.Driver.FindElement(By.Id("NewPassword")).SendKeys("abc???");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("abc???");
|
|
|
|
s.Driver.FindElement(By.Id("UpdatePassword")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
|
|
|
|
//Log In With New Password
|
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
|
|
|
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
|
|
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
|
|
|
Assert.True(s.Driver.PageSource.Contains("Stores"), "Can't Access Stores");
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
|
|
|
s.ClickOnAllSideMenus();
|
|
|
|
|
2020-09-16 08:54:09 +02:00
|
|
|
//let's test invite link
|
|
|
|
s.Logout();
|
|
|
|
s.GoToRegister();
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser(true);
|
2020-09-16 08:54:09 +02:00
|
|
|
s.GoToServer(ServerNavPages.Users);
|
|
|
|
s.Driver.FindElement(By.Id("CreateUser")).Click();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2020-09-16 08:54:09 +02:00
|
|
|
var usr = RandomUtils.GetUInt256().ToString().Substring(64 - 20) + "@a.com";
|
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
|
|
|
s.Driver.FindElement(By.Id("Save")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
var url = s.FindAlertMessage().FindElement(By.TagName("a")).Text;
|
2021-01-25 14:10:19 +01:00
|
|
|
|
2020-09-16 08:54:09 +02:00
|
|
|
s.Logout();
|
|
|
|
s.Driver.Navigate().GoToUrl(url);
|
2020-11-06 12:42:26 +01:00
|
|
|
Assert.Equal("hidden", s.Driver.FindElement(By.Id("Email")).GetAttribute("type"));
|
|
|
|
Assert.Equal(usr, s.Driver.FindElement(By.Id("Email")).GetAttribute("value"));
|
|
|
|
|
2020-09-16 08:54:09 +02:00
|
|
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
|
|
|
|
s.Driver.FindElement(By.Id("SetPassword")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-09-16 08:54:09 +02:00
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
|
|
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
|
|
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
|
|
|
|
|
|
|
// We should be logged in now
|
|
|
|
s.Driver.FindElement(By.Id("mainNav"));
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-09 05:18:37 +02:00
|
|
|
//let's test delete user quickly while we're at it
|
|
|
|
s.GoToProfile();
|
|
|
|
s.Driver.FindElement(By.Id("delete-user")).Click();
|
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("DELETE");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-09 05:18:37 +02:00
|
|
|
Assert.Contains("/login", s.Driver.Url);
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
2019-05-14 16:33:46 +02:00
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-09-06 09:51:49 +02:00
|
|
|
public async Task CanUseSSHService()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-06 09:51:49 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2021-04-17 06:29:50 +02:00
|
|
|
var settings = s.Server.PayTester.GetService<SettingsRepository>();
|
|
|
|
var policies = await settings.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
|
|
|
|
policies.DisableSSHService = false;
|
|
|
|
await settings.UpdateSetting(policies);
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser(isAdmin: true);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
|
|
|
|
Assert.Contains("server/services/ssh", s.Driver.PageSource);
|
2021-10-29 11:01:16 +02:00
|
|
|
using (var client = await s.Server.PayTester.GetService<Configuration.BTCPayServerOptions>().SSHSettings
|
|
|
|
.ConnectAsync())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
|
|
|
var result = await client.RunBash("echo hello");
|
|
|
|
Assert.Equal(string.Empty, result.Error);
|
|
|
|
Assert.Equal("hello\n", result.Output);
|
|
|
|
Assert.Equal(0, result.ExitStatus);
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/ssh"));
|
|
|
|
s.Driver.AssertNoError();
|
2019-09-19 12:17:20 +02:00
|
|
|
s.Driver.FindElement(By.Id("SSHKeyFileContent")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("SSHKeyFileContent")).SendKeys("tes't\r\ntest2");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("submit")).Click();
|
2019-09-19 12:17:20 +02:00
|
|
|
s.Driver.AssertNoError();
|
|
|
|
|
|
|
|
var text = s.Driver.FindElement(By.Id("SSHKeyFileContent")).Text;
|
|
|
|
// Browser replace \n to \r\n, so it is hard to compare exactly what we want
|
|
|
|
Assert.Contains("tes't", text);
|
|
|
|
Assert.Contains("test2", text);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains("authorized_keys has been updated",
|
|
|
|
StringComparison.OrdinalIgnoreCase));
|
2019-09-20 12:41:59 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("SSHKeyFileContent")).Clear();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("submit")).Click();
|
2019-09-20 12:41:59 +02:00
|
|
|
|
|
|
|
text = s.Driver.FindElement(By.Id("SSHKeyFileContent")).Text;
|
|
|
|
Assert.DoesNotContain("test2", text);
|
2021-04-17 06:29:50 +02:00
|
|
|
|
|
|
|
// Let's try to disable it now
|
|
|
|
s.Driver.FindElement(By.Id("disable")).Click();
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("DISABLE");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2021-04-17 06:29:50 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/ssh"));
|
|
|
|
Assert.True(s.Driver.PageSource.Contains("404 - Page not found", StringComparison.OrdinalIgnoreCase));
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-09-07 04:55:53 +02:00
|
|
|
policies = await settings.GetSettingAsync<PoliciesSettings>();
|
|
|
|
Assert.True(policies.DisableSSHService);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-04-17 06:29:50 +02:00
|
|
|
policies.DisableSSHService = false;
|
|
|
|
await settings.UpdateSetting(policies);
|
2019-09-06 09:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 09:39:49 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanSetupEmailServer()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2020-10-05 09:39:49 +02:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser(isAdmin: true);
|
2020-10-05 09:39:49 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/emails"));
|
|
|
|
if (s.Driver.PageSource.Contains("Configured"))
|
|
|
|
{
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=\"ResetPassword\"]")).Submit();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-10-05 09:39:49 +02:00
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2020-10-05 09:39:49 +02:00
|
|
|
CanSetupEmailCore(s);
|
|
|
|
s.CreateNewStore();
|
|
|
|
s.GoToUrl($"stores/{s.StoreId}/emails");
|
|
|
|
CanSetupEmailCore(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanUseDynamicDns()
|
2019-07-25 12:07:56 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-07-25 12:07:56 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser(isAdmin: true);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
|
|
|
|
Assert.Contains("Dynamic DNS", s.Driver.PageSource);
|
|
|
|
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns"));
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
if (s.Driver.PageSource.Contains("pouet.hello.com"))
|
|
|
|
{
|
|
|
|
// Cleanup old test run
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
// We will just cheat for test purposes by only querying the server
|
|
|
|
s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/"));
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
Assert.Contains("The Dynamic DNS has been successfully queried", s.Driver.PageSource);
|
|
|
|
Assert.EndsWith("/server/services/dynamic-dns", s.Driver.Url);
|
|
|
|
|
|
|
|
// Try to do the same thing should fail (hostname already exists)
|
|
|
|
s.Driver.FindElement(By.Id("AddDynamicDNS")).Click();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/"));
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com");
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog");
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter);
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
Assert.Contains("This hostname already exists", s.Driver.PageSource);
|
|
|
|
|
|
|
|
// Delete it
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns"));
|
|
|
|
Assert.Contains("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource);
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete"));
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.AssertNoError();
|
|
|
|
|
|
|
|
Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource);
|
2019-07-25 12:07:56 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2021-03-31 13:23:36 +02:00
|
|
|
[Trait("Lightning", "Lightning")]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanCreateStores()
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2021-03-31 13:23:36 +02:00
|
|
|
s.Server.ActivateLightning();
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2021-03-31 13:23:36 +02:00
|
|
|
var alice = s.RegisterNewUser(true);
|
|
|
|
var (storeName, storeId) = s.CreateNewStore();
|
2020-12-02 07:45:00 +01:00
|
|
|
var onchainHint = "Set up your wallet to receive payments at your store.";
|
2020-11-06 11:14:00 +01:00
|
|
|
var offchainHint = "A connection to a Lightning node is required to receive Lightning payments.";
|
2020-10-23 17:15:07 +02:00
|
|
|
|
2020-10-17 22:03:28 +02:00
|
|
|
// verify that hints are displayed on the store page
|
2020-10-23 17:15:07 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains(onchainHint), "Wallet hint not present");
|
|
|
|
Assert.True(s.Driver.PageSource.Contains(offchainHint), "Lightning hint not present");
|
2020-10-17 22:03:28 +02:00
|
|
|
|
2020-10-17 22:53:07 +02:00
|
|
|
s.GoToStores();
|
2021-03-31 13:23:36 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains($"warninghint_{storeId}"), "Warning hint on list not present");
|
2020-10-17 22:53:07 +02:00
|
|
|
|
2021-03-31 13:23:36 +02:00
|
|
|
s.GoToStore(storeId);
|
|
|
|
Assert.Contains(storeName, s.Driver.PageSource);
|
2020-12-02 07:45:00 +01:00
|
|
|
Assert.True(s.Driver.PageSource.Contains(onchainHint), "Wallet hint should be present at this point");
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains(offchainHint),
|
|
|
|
"Lightning hint should be present at this point");
|
2020-12-02 07:45:00 +01:00
|
|
|
|
2021-03-31 13:23:36 +02:00
|
|
|
// setup onchain wallet
|
|
|
|
s.GoToStore(storeId);
|
|
|
|
s.AddDerivationScheme();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.AssertNoError();
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.False(s.Driver.PageSource.Contains(onchainHint),
|
|
|
|
"Wallet hint not dismissed on derivation scheme add");
|
2021-03-31 13:23:36 +02:00
|
|
|
|
|
|
|
// setup offchain wallet
|
|
|
|
s.GoToStore(storeId);
|
|
|
|
s.AddLightningNode();
|
|
|
|
s.Driver.AssertNoError();
|
|
|
|
var successAlert = s.FindAlertMessage();
|
2021-04-20 09:09:32 +02:00
|
|
|
Assert.Contains("BTC Lightning node updated.", successAlert.Text);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.False(s.Driver.PageSource.Contains(offchainHint),
|
|
|
|
"Lightning hint should be dismissed at this point");
|
2020-10-17 22:03:28 +02:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
var storeUrl = s.Driver.Url;
|
|
|
|
s.ClickOnAllSideMenus();
|
|
|
|
s.GoToInvoices();
|
2021-03-31 13:23:36 +02:00
|
|
|
var invoiceId = s.CreateInvoice(storeName);
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
|
|
|
var invoiceUrl = s.Driver.Url;
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-05-09 15:03:46 +02:00
|
|
|
//let's test archiving an invoice
|
2020-06-24 03:34:09 +02:00
|
|
|
Assert.DoesNotContain("Archived", s.Driver.FindElement(By.Id("btn-archive-toggle")).Text);
|
2020-05-09 15:03:46 +02:00
|
|
|
s.Driver.FindElement(By.Id("btn-archive-toggle")).Click();
|
2021-11-22 05:57:20 +01:00
|
|
|
Assert.Contains("Unarchive", s.Driver.FindElement(By.Id("btn-archive-toggle")).Text);
|
2020-05-09 15:03:46 +02:00
|
|
|
//check that it no longer appears in list
|
|
|
|
s.GoToInvoices();
|
2021-01-22 17:49:26 +01:00
|
|
|
|
2020-05-09 15:03:46 +02:00
|
|
|
Assert.DoesNotContain(invoiceId, s.Driver.PageSource);
|
|
|
|
//ok, let's unarchive and see that it shows again
|
|
|
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
|
|
|
s.Driver.FindElement(By.Id("btn-archive-toggle")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2021-11-22 05:57:20 +01:00
|
|
|
Assert.DoesNotContain("Unarchive", s.Driver.FindElement(By.Id("btn-archive-toggle")).Text);
|
2020-05-09 15:03:46 +02:00
|
|
|
s.GoToInvoices();
|
|
|
|
Assert.Contains(invoiceId, s.Driver.PageSource);
|
2019-09-11 09:22:41 +02:00
|
|
|
|
|
|
|
// When logout we should not be able to access store and invoice details
|
|
|
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
|
|
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
|
|
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2019-09-11 09:22:41 +02:00
|
|
|
// When logged we should not be able to access store and invoice details
|
|
|
|
var bob = s.RegisterNewUser();
|
|
|
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
|
|
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
|
|
|
s.AssertNotFound();
|
|
|
|
s.GoToHome();
|
|
|
|
s.Logout();
|
|
|
|
|
|
|
|
// Let's add Bob as a guest to alice's store
|
2021-01-22 17:49:26 +01:00
|
|
|
s.LogIn(alice);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(storeUrl + "/users");
|
|
|
|
s.Driver.FindElement(By.Id("Email")).SendKeys(bob + Keys.Enter);
|
|
|
|
Assert.Contains("User added successfully", s.Driver.PageSource);
|
|
|
|
s.Logout();
|
|
|
|
|
|
|
|
// Bob should not have access to store, but should have access to invoice
|
2021-01-22 17:49:26 +01:00
|
|
|
s.LogIn(bob);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
|
|
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
|
|
|
s.Driver.AssertNoError();
|
2019-10-26 16:35:55 +02:00
|
|
|
|
|
|
|
// Alice should be able to delete the store
|
|
|
|
s.Logout();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.LogIn(alice);
|
2019-10-26 16:35:55 +02:00
|
|
|
s.Driver.FindElement(By.Id("Stores")).Click();
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.FindElement(By.LinkText("Delete")).Click();
|
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("DELETE");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2019-10-26 16:35:55 +02:00
|
|
|
s.Driver.FindElement(By.Id("Stores")).Click();
|
|
|
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-05-13 10:59:15 +02:00
|
|
|
}
|
|
|
|
|
2019-10-12 13:35:30 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanUsePairing()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-10-12 13:35:30 +02:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/api-access-request"));
|
|
|
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
2019-11-06 06:31:45 +01:00
|
|
|
s.GoToRegister();
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser();
|
|
|
|
s.CreateNewStore();
|
2019-10-12 13:35:30 +02:00
|
|
|
s.AddDerivationScheme();
|
|
|
|
|
2021-10-29 08:25:43 +02:00
|
|
|
s.Driver.FindElement(By.Id("Nav-Tokens")).Click();
|
2019-10-12 13:35:30 +02:00
|
|
|
s.Driver.FindElement(By.Id("CreateNewToken")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("RequestPairing")).Click();
|
2021-01-25 14:10:19 +01:00
|
|
|
var pairingCode = AssertUrlHasPairingCode(s);
|
2019-10-12 13:35:30 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2019-10-12 13:35:30 +02:00
|
|
|
Assert.Contains(pairingCode, s.Driver.PageSource);
|
|
|
|
|
2021-09-22 14:31:44 +02:00
|
|
|
var client = new NBitpayClient.Bitpay(new Key(), s.ServerUri);
|
2019-10-12 13:35:30 +02:00
|
|
|
await client.AuthorizeClient(new NBitpayClient.PairingCode(pairingCode));
|
2021-10-29 11:01:16 +02:00
|
|
|
await client.CreateInvoiceAsync(
|
2021-11-15 05:48:07 +01:00
|
|
|
new NBitpayClient.Invoice() { Price = 1.000000012m, Currency = "USD", FullNotifications = true },
|
2021-10-29 11:01:16 +02:00
|
|
|
NBitpayClient.Facade.Merchant);
|
2019-10-12 13:35:30 +02:00
|
|
|
|
2021-09-22 14:31:44 +02:00
|
|
|
client = new NBitpayClient.Bitpay(new Key(), s.ServerUri);
|
2019-10-12 13:35:30 +02:00
|
|
|
|
|
|
|
var code = await client.RequestClientAuthorizationAsync("hehe", NBitpayClient.Facade.Merchant);
|
2021-09-22 14:31:44 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(code.CreateLink(s.ServerUri));
|
2019-10-12 13:35:30 +02:00
|
|
|
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
|
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
await client.CreateInvoiceAsync(
|
2021-11-15 05:48:07 +01:00
|
|
|
new NBitpayClient.Invoice() { Price = 1.000000012m, Currency = "USD", FullNotifications = true },
|
2021-10-29 11:01:16 +02:00
|
|
|
NBitpayClient.Facade.Merchant);
|
2019-11-03 08:16:52 +01:00
|
|
|
|
|
|
|
s.Driver.Navigate().GoToUrl(s.Link("/api-tokens"));
|
|
|
|
s.Driver.FindElement(By.Id("RequestPairing")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
|
|
|
|
AssertUrlHasPairingCode(s);
|
2019-10-12 13:35:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanCreateAppPoS()
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
2021-01-22 17:49:26 +01:00
|
|
|
var (storeName, _) = s.CreateNewStore();
|
2019-09-11 09:22:41 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("Apps")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
2021-10-29 12:29:02 +02:00
|
|
|
s.Driver.FindElement(By.Name("AppName")).SendKeys("PoS" + Guid.NewGuid());
|
2021-07-23 12:57:19 +02:00
|
|
|
s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("Point of Sale");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(storeName);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
2021-02-18 12:20:27 +01:00
|
|
|
s.Driver.FindElement(By.CssSelector(".template-item:nth-of-type(1) .btn-primary")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("BuyButtonText")).SendKeys("Take my money");
|
|
|
|
s.Driver.FindElement(By.Id("SaveItemChanges")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ToggleRawEditor")).Click();
|
|
|
|
|
|
|
|
var template = s.Driver.FindElement(By.Id("Template")).GetAttribute("value");
|
|
|
|
Assert.Contains("buyButtonText: Take my money", template);
|
|
|
|
|
2021-07-23 12:57:19 +02:00
|
|
|
s.Driver.FindElement(By.Id("DefaultView")).SendKeys("Item list and cart");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("SaveSettings")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ViewApp")).Click();
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-05-27 14:20:21 +02:00
|
|
|
var posBaseUrl = s.Driver.Url.Replace("/Cart", "");
|
2019-09-11 09:22:41 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains("Tea shop"), "Unable to create PoS");
|
2020-05-26 17:38:30 +02:00
|
|
|
Assert.True(s.Driver.PageSource.Contains("Cart"), "PoS not showing correct default view");
|
2021-02-18 12:20:27 +01:00
|
|
|
Assert.True(s.Driver.PageSource.Contains("Take my money"), "PoS not showing correct default view");
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-05-26 17:38:30 +02:00
|
|
|
s.Driver.Url = posBaseUrl + "/static";
|
|
|
|
Assert.False(s.Driver.PageSource.Contains("Cart"), "Static PoS not showing correct view");
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-05-26 17:38:30 +02:00
|
|
|
s.Driver.Url = posBaseUrl + "/cart";
|
|
|
|
Assert.True(s.Driver.PageSource.Contains("Cart"), "Cart PoS not showing correct view");
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2021-01-25 14:10:19 +01:00
|
|
|
public async Task CanCreateCrowdfundingApp()
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
2021-01-22 17:49:26 +01:00
|
|
|
var (storeName, _) = s.CreateNewStore();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.AddDerivationScheme();
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("Apps")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
2021-10-29 12:29:02 +02:00
|
|
|
s.Driver.FindElement(By.Name("AppName")).SendKeys("CF" + Guid.NewGuid());
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("Crowdfund");
|
|
|
|
s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(storeName);
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Title")).SendKeys("Kukkstarter");
|
|
|
|
s.Driver.FindElement(By.CssSelector("div.note-editable.card-block")).SendKeys("1BTC = 1BTC");
|
|
|
|
s.Driver.FindElement(By.Id("TargetCurrency")).SendKeys("JPY");
|
|
|
|
s.Driver.FindElement(By.Id("TargetAmount")).SendKeys("700");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("SaveSettings")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ViewApp")).Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal("currently active!",
|
|
|
|
s.Driver.FindElement(By.CssSelector("[data-test='time-state']")).Text);
|
2020-06-24 03:34:09 +02:00
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanCreatePayRequest()
|
2019-05-12 10:13:26 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-09-11 09:22:41 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.RegisterNewUser();
|
|
|
|
s.CreateNewStore();
|
|
|
|
s.AddDerivationScheme();
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("PaymentRequests")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("CreatePaymentRequest")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Title")).SendKeys("Pay123");
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("700");
|
|
|
|
s.Driver.FindElement(By.Id("Currency")).SendKeys("BTC");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("SaveButton")).Click();
|
|
|
|
s.Driver.FindElement(By.Name("ViewAppButton")).Click();
|
2019-09-11 09:22:41 +02:00
|
|
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
2021-01-22 17:49:26 +01:00
|
|
|
Assert.Equal("Amount due", s.Driver.FindElement(By.CssSelector("[data-test='amount-due-title']")).Text);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal("Pay Invoice",
|
|
|
|
s.Driver.FindElement(By.CssSelector("[data-test='pay-button']")).Text.Trim());
|
|
|
|
|
2021-08-31 08:07:54 +02:00
|
|
|
// expire
|
|
|
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.First());
|
|
|
|
s.Driver.ExecuteJavaScript("document.getElementById('ExpiryDate').value = '2021-01-21T21:00:00.000Z'");
|
|
|
|
s.Driver.FindElement(By.Id("SaveButton")).Click();
|
|
|
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
2021-09-28 05:20:40 +02:00
|
|
|
s.Driver.Navigate().Refresh();
|
2021-09-28 05:05:46 +02:00
|
|
|
Assert.Equal("Expired", s.Driver.WaitForElement(By.CssSelector("[data-test='status']")).Text);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-08-31 08:07:54 +02:00
|
|
|
// unexpire
|
|
|
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.First());
|
|
|
|
s.Driver.FindElement(By.Id("ClearExpiryDate")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("SaveButton")).Click();
|
|
|
|
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
2021-09-28 05:20:40 +02:00
|
|
|
s.Driver.Navigate().Refresh();
|
2021-08-31 08:07:54 +02:00
|
|
|
s.Driver.AssertElementNotFound(By.CssSelector("[data-test='status']"));
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal("Pay Invoice",
|
|
|
|
s.Driver.FindElement(By.CssSelector("[data-test='pay-button']")).Text.Trim());
|
2019-09-11 09:22:41 +02:00
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
2020-03-23 07:46:54 +01:00
|
|
|
|
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanUseCoinSelection()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2020-03-23 07:46:54 +01:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
2021-01-25 14:10:19 +01:00
|
|
|
s.RegisterNewUser(true);
|
|
|
|
var (_, storeId) = s.CreateNewStore();
|
2020-03-23 07:46:54 +01:00
|
|
|
s.GenerateWallet("BTC", "", false, true);
|
|
|
|
var walletId = new WalletId(storeId, "BTC");
|
2020-04-28 08:06:28 +02:00
|
|
|
s.GoToWallet(walletId, WalletsNavPages.Receive);
|
2020-03-23 07:46:54 +01:00
|
|
|
s.Driver.FindElement(By.Id("generateButton")).Click();
|
2020-12-22 03:18:51 +01:00
|
|
|
var addressStr = s.Driver.FindElement(By.Id("address")).GetProperty("value");
|
2021-10-29 11:01:16 +02:00
|
|
|
var address = BitcoinAddress.Create(addressStr,
|
|
|
|
((BTCPayNetwork)s.Server.NetworkProvider.GetNetwork("BTC")).NBitcoinNetwork);
|
2020-03-23 07:46:54 +01:00
|
|
|
await s.Server.ExplorerNode.GenerateAsync(1);
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
await s.Server.ExplorerNode.SendToAddressAsync(address, Money.Coins(1.0m));
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2020-03-23 07:46:54 +01:00
|
|
|
var targetTx = await s.Server.ExplorerNode.SendToAddressAsync(address, Money.Coins(1.2m));
|
|
|
|
var tx = await s.Server.ExplorerNode.GetRawTransactionAsync(targetTx);
|
2021-10-29 11:01:16 +02:00
|
|
|
var spentOutpoint = new OutPoint(targetTx,
|
|
|
|
tx.Outputs.FindIndex(txout => txout.Value == Money.Coins(1.2m)));
|
2020-03-25 07:59:30 +01:00
|
|
|
await TestUtils.EventuallyAsync(async () =>
|
|
|
|
{
|
|
|
|
var store = await s.Server.PayTester.StoreRepository.FindStore(storeId);
|
|
|
|
var x = store.GetSupportedPaymentMethods(s.Server.NetworkProvider)
|
|
|
|
.OfType<DerivationSchemeSettings>()
|
|
|
|
.Single(settings => settings.PaymentId.CryptoCode == walletId.CryptoCode);
|
2021-03-11 14:20:25 +01:00
|
|
|
var wallet = s.Server.PayTester.GetService<BTCPayWalletProvider>().GetWallet(walletId.CryptoCode);
|
|
|
|
wallet.InvalidateCache(x.AccountDerivation);
|
2020-03-25 07:59:30 +01:00
|
|
|
Assert.Contains(
|
2021-03-11 14:20:25 +01:00
|
|
|
await wallet.GetUnspentCoins(x.AccountDerivation),
|
2020-03-25 07:59:30 +01:00
|
|
|
coin => coin.OutPoint == spentOutpoint);
|
|
|
|
});
|
2020-03-23 07:46:54 +01:00
|
|
|
await s.Server.ExplorerNode.GenerateAsync(1);
|
2021-01-25 14:10:19 +01:00
|
|
|
s.GoToWallet(walletId);
|
2021-02-17 04:14:29 +01:00
|
|
|
s.Driver.WaitForAndClick(By.Id("toggleInputSelection"));
|
2021-10-09 03:39:34 +02:00
|
|
|
s.Driver.WaitForElement(By.Id(spentOutpoint.ToString()));
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal("true",
|
|
|
|
s.Driver.FindElement(By.Name("InputSelection")).GetAttribute("value").ToLowerInvariant());
|
2020-03-23 07:46:54 +01:00
|
|
|
var el = s.Driver.FindElement(By.Id(spentOutpoint.ToString()));
|
|
|
|
s.Driver.FindElement(By.Id(spentOutpoint.ToString())).Click();
|
2020-03-24 08:36:27 +01:00
|
|
|
var inputSelectionSelect = s.Driver.FindElement(By.Name("SelectedInputs"));
|
2020-03-25 07:59:30 +01:00
|
|
|
Assert.Single(inputSelectionSelect.FindElements(By.CssSelector("[selected]")));
|
2020-03-24 08:36:27 +01:00
|
|
|
|
2020-03-23 07:46:54 +01:00
|
|
|
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
|
|
|
SetTransactionOutput(s, 0, bob, 0.3m);
|
2021-06-14 07:06:56 +02:00
|
|
|
s.Driver.FindElement(By.Id("SignTransaction")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click();
|
|
|
|
var happyElement = s.FindAlertMessage();
|
2020-03-23 07:46:54 +01:00
|
|
|
var happyText = happyElement.Text;
|
|
|
|
var txid = Regex.Match(happyText, @"\((.*)\)").Groups[1].Value;
|
|
|
|
|
|
|
|
tx = await s.Server.ExplorerNode.GetRawTransactionAsync(new uint256(txid));
|
|
|
|
Assert.Single(tx.Inputs);
|
|
|
|
Assert.Equal(spentOutpoint, tx.Inputs[0].PrevOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 12:42:26 +01:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanUseWebhooks()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2020-11-06 12:42:26 +01:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
s.RegisterNewUser(true);
|
2021-01-22 17:49:26 +01:00
|
|
|
var (storeName, storeId) = s.CreateNewStore();
|
2021-05-19 04:39:27 +02:00
|
|
|
s.GoToStore(storeId, StoreNavPages.Webhooks);
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's create two webhooks");
|
2021-01-22 17:49:26 +01:00
|
|
|
for (var i = 0; i < 2; i++)
|
2020-11-06 12:42:26 +01:00
|
|
|
{
|
|
|
|
s.Driver.FindElement(By.Id("CreateWebhook")).Click();
|
|
|
|
s.Driver.FindElement(By.Name("PayloadUrl")).SendKeys($"http://127.0.0.1/callback{i}");
|
2021-05-19 04:39:27 +02:00
|
|
|
new SelectElement(s.Driver.FindElement(By.Id("Everything"))).SelectByValue("false");
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("InvoiceCreated")).Click();
|
2020-11-23 07:57:05 +01:00
|
|
|
s.Driver.FindElement(By.Id("InvoiceProcessing")).Click();
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.Name("add")).Click();
|
|
|
|
}
|
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's delete one of them");
|
2020-11-06 12:42:26 +01:00
|
|
|
var deletes = s.Driver.FindElements(By.LinkText("Delete"));
|
|
|
|
Assert.Equal(2, deletes.Count);
|
|
|
|
deletes[0].Click();
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("DELETE");
|
|
|
|
s.Driver.FindElement(By.Id("ConfirmContinue")).Click();
|
2020-11-06 12:42:26 +01:00
|
|
|
deletes = s.Driver.FindElements(By.LinkText("Delete"));
|
|
|
|
Assert.Single(deletes);
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's try to update one of them");
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.LinkText("Modify")).Click();
|
|
|
|
|
2020-11-13 06:01:51 +01:00
|
|
|
using FakeServer server = new FakeServer();
|
|
|
|
await server.Start();
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.Name("PayloadUrl")).Clear();
|
2020-11-13 06:01:51 +01:00
|
|
|
s.Driver.FindElement(By.Name("PayloadUrl")).SendKeys(server.ServerUri.AbsoluteUri);
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.Name("Secret")).Clear();
|
|
|
|
s.Driver.FindElement(By.Name("Secret")).SendKeys("HelloWorld");
|
|
|
|
s.Driver.FindElement(By.Name("update")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.LinkText("Modify")).Click();
|
|
|
|
foreach (var value in Enum.GetValues(typeof(WebhookEventType)))
|
|
|
|
{
|
|
|
|
// Here we make sure we did not forget an event type in the list
|
|
|
|
// However, maybe some event should not appear here because not at the store level.
|
|
|
|
// Fix as needed.
|
|
|
|
Assert.Contains($"value=\"{value}\"", s.Driver.PageSource);
|
|
|
|
}
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2020-11-06 12:42:26 +01:00
|
|
|
// This one should be checked
|
2020-11-23 07:57:05 +01:00
|
|
|
Assert.Contains($"value=\"InvoiceProcessing\" checked", s.Driver.PageSource);
|
2020-11-06 12:42:26 +01:00
|
|
|
Assert.Contains($"value=\"InvoiceCreated\" checked", s.Driver.PageSource);
|
|
|
|
// This one never been checked
|
|
|
|
Assert.DoesNotContain($"value=\"InvoiceReceivedPayment\" checked", s.Driver.PageSource);
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Name("update")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-11-13 06:01:51 +01:00
|
|
|
Assert.Contains(server.ServerUri.AbsoluteUri, s.Driver.PageSource);
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's see if we can generate an event");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.GoToStore(storeId);
|
2020-11-06 12:42:26 +01:00
|
|
|
s.AddDerivationScheme();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.CreateInvoice(storeName);
|
2020-11-06 12:42:26 +01:00
|
|
|
var request = await server.GetNextRequest();
|
2020-11-13 06:01:51 +01:00
|
|
|
var headers = request.Request.Headers;
|
2020-11-06 12:42:26 +01:00
|
|
|
var actualSig = headers["BTCPay-Sig"].First();
|
2020-11-13 06:01:51 +01:00
|
|
|
var bytes = await request.Request.Body.ReadBytesAsync((int)headers.ContentLength.Value);
|
2021-10-29 11:01:16 +02:00
|
|
|
var expectedSig =
|
|
|
|
$"sha256={Encoders.Hex.EncodeData(new HMACSHA256(Encoding.UTF8.GetBytes("HelloWorld")).ComputeHash(bytes))}";
|
2020-11-06 12:42:26 +01:00
|
|
|
Assert.Equal(expectedSig, actualSig);
|
2020-11-13 06:01:51 +01:00
|
|
|
request.Response.StatusCode = 200;
|
|
|
|
server.Done();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's make a failed event");
|
2021-01-22 17:49:26 +01:00
|
|
|
s.CreateInvoice(storeName);
|
2020-11-06 12:42:26 +01:00
|
|
|
request = await server.GetNextRequest();
|
2020-11-13 06:01:51 +01:00
|
|
|
request.Response.StatusCode = 404;
|
|
|
|
server.Done();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
|
|
|
// The delivery is done asynchronously, so small wait here
|
|
|
|
await Task.Delay(500);
|
2021-01-22 17:49:26 +01:00
|
|
|
s.GoToStore(storeId, Views.Stores.StoreNavPages.Webhooks);
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.LinkText("Modify")).Click();
|
|
|
|
var elements = s.Driver.FindElements(By.ClassName("redeliver"));
|
|
|
|
// One worked, one failed
|
|
|
|
s.Driver.FindElement(By.ClassName("fa-times"));
|
|
|
|
s.Driver.FindElement(By.ClassName("fa-check"));
|
|
|
|
elements[0].Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
|
|
|
|
s.FindAlertMessage();
|
2020-11-06 12:42:26 +01:00
|
|
|
request = await server.GetNextRequest();
|
2020-11-13 06:01:51 +01:00
|
|
|
request.Response.StatusCode = 404;
|
|
|
|
server.Done();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Can we browse the json content?");
|
2020-11-06 12:42:26 +01:00
|
|
|
CanBrowseContent(s);
|
|
|
|
|
|
|
|
s.GoToInvoices();
|
|
|
|
s.Driver.FindElement(By.LinkText("Details")).Click();
|
|
|
|
CanBrowseContent(s);
|
|
|
|
var element = s.Driver.FindElement(By.ClassName("redeliver"));
|
|
|
|
element.Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
|
|
|
|
s.FindAlertMessage();
|
2020-11-06 12:42:26 +01:00
|
|
|
request = await server.GetNextRequest();
|
2020-11-13 06:01:51 +01:00
|
|
|
request.Response.StatusCode = 404;
|
|
|
|
server.Done();
|
2020-11-06 12:42:26 +01:00
|
|
|
|
2021-11-22 09:16:08 +01:00
|
|
|
TestLogs.LogInformation("Let's see if we can delete store with some webhooks inside");
|
2021-10-29 08:25:43 +02:00
|
|
|
s.GoToStore(storeId, StoreNavPages.GeneralSettings);
|
2020-11-06 12:42:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("delete-store")).Click();
|
2021-09-07 04:55:53 +02:00
|
|
|
s.Driver.WaitForElement(By.Id("ConfirmContinue")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage();
|
2020-11-06 12:42:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:24:28 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
2021-10-12 11:37:13 +02:00
|
|
|
public async Task CanImportMnemonic()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2021-10-12 11:37:13 +02:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
s.RegisterNewUser(true);
|
|
|
|
foreach (var isHotwallet in new[] { false, true })
|
|
|
|
{
|
2021-11-11 06:30:19 +01:00
|
|
|
var cryptoCode = "BTC";
|
|
|
|
var (_, storeId) = s.CreateNewStore();
|
|
|
|
s.GenerateWallet(cryptoCode, "melody lizard phrase voice unique car opinion merge degree evil swift cargo", privkeys: isHotwallet);
|
|
|
|
s.GoToWalletSettings(storeId, cryptoCode);
|
2021-10-12 11:37:13 +02:00
|
|
|
if (isHotwallet)
|
|
|
|
Assert.Contains("View seed", s.Driver.PageSource);
|
|
|
|
else
|
|
|
|
Assert.DoesNotContain("View seed", s.Driver.PageSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact(Timeout = TestTimeout)]
|
2019-10-07 09:04:25 +02:00
|
|
|
public async Task CanManageWallet()
|
2019-05-13 10:59:15 +02:00
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2019-05-13 10:59:15 +02:00
|
|
|
{
|
2019-10-07 09:04:25 +02:00
|
|
|
await s.StartAsync();
|
2019-10-12 13:35:30 +02:00
|
|
|
s.RegisterNewUser(true);
|
2021-02-11 11:48:54 +01:00
|
|
|
var (storeName, storeId) = s.CreateNewStore();
|
2021-11-11 06:30:19 +01:00
|
|
|
var cryptoCode = "BTC";
|
2019-09-11 09:22:41 +02:00
|
|
|
|
2021-02-11 11:48:54 +01:00
|
|
|
// In this test, we try to spend from a manual seed. We import the xpub 49'/0'/0',
|
|
|
|
// then try to use the seed to sign the transaction
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GenerateWallet(cryptoCode, "", true);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-18 06:12:27 +01:00
|
|
|
//let's test quickly the receive wallet page
|
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
2020-01-21 09:33:12 +01:00
|
|
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
2021-06-14 07:06:56 +02:00
|
|
|
s.Driver.FindElement(By.Id("SignTransaction")).Click();
|
2021-01-25 14:10:19 +01:00
|
|
|
|
2021-02-11 11:48:54 +01:00
|
|
|
//you cannot use the Sign with NBX option without saving private keys when generating the wallet.
|
2020-01-21 09:33:12 +01:00
|
|
|
Assert.DoesNotContain("nbx-seed", s.Driver.PageSource);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-18 06:12:27 +01:00
|
|
|
s.Driver.FindElement(By.Id("WalletReceive")).Click();
|
|
|
|
//generate a receiving address
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click();
|
|
|
|
Assert.True(s.Driver.FindElement(By.ClassName("qr-container")).Displayed);
|
2020-12-22 03:18:51 +01:00
|
|
|
var receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value");
|
2020-01-18 06:12:27 +01:00
|
|
|
//unreserve
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=unreserve-current-address]")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
//generate it again, should be the same one as before as nothing got used in the meantime
|
2020-01-18 06:12:27 +01:00
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click();
|
|
|
|
Assert.True(s.Driver.FindElement(By.ClassName("qr-container")).Displayed);
|
2020-12-22 03:18:51 +01:00
|
|
|
Assert.Equal(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value"));
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-18 06:12:27 +01:00
|
|
|
//send money to addr and ensure it changed
|
|
|
|
var sess = await s.Server.ExplorerClient.CreateWebsocketNotificationSessionAsync();
|
2021-02-11 11:48:54 +01:00
|
|
|
await sess.ListenAllTrackedSourceAsync();
|
2020-01-18 06:12:27 +01:00
|
|
|
var nextEvent = sess.NextEventAsync();
|
2021-10-29 11:01:16 +02:00
|
|
|
await s.Server.ExplorerNode.SendToAddressAsync(BitcoinAddress.Create(receiveAddr, Network.RegTest),
|
|
|
|
Money.Parse("0.1"));
|
2020-01-18 06:12:27 +01:00
|
|
|
await nextEvent;
|
|
|
|
await Task.Delay(200);
|
|
|
|
s.Driver.Navigate().Refresh();
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click();
|
2020-12-22 03:18:51 +01:00
|
|
|
Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value"));
|
|
|
|
receiveAddr = s.Driver.FindElement(By.Id("address")).GetAttribute("value");
|
2020-07-20 17:46:25 +02:00
|
|
|
|
2020-01-18 06:12:27 +01:00
|
|
|
//change the wallet and ensure old address is not there and generating a new one does not result in the prev one
|
2021-02-11 11:48:54 +01:00
|
|
|
s.GoToStore(storeId);
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GenerateWallet(cryptoCode, "", true);
|
2020-01-18 06:12:27 +01:00
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("WalletReceive")).Click();
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=generate-new-address]")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
|
2020-12-22 03:18:51 +01:00
|
|
|
Assert.NotEqual(receiveAddr, s.Driver.FindElement(By.Id("address")).GetAttribute("value"));
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-02-11 11:48:54 +01:00
|
|
|
var invoiceId = s.CreateInvoice(storeName);
|
2019-12-18 14:28:03 +01:00
|
|
|
var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId);
|
2019-12-05 18:56:40 +01:00
|
|
|
var address = invoice.EntityToDTO().Addresses["BTC"];
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-21 09:33:12 +01:00
|
|
|
//wallet should have been imported to bitcoin core wallet in watch only mode.
|
2021-10-29 11:01:16 +02:00
|
|
|
var result =
|
|
|
|
await s.Server.ExplorerNode.GetAddressInfoAsync(BitcoinAddress.Create(address, Network.RegTest));
|
2019-12-06 10:03:17 +01:00
|
|
|
Assert.True(result.IsWatchOnly);
|
2021-02-11 11:48:54 +01:00
|
|
|
s.GoToStore(storeId);
|
2021-11-11 06:30:19 +01:00
|
|
|
var mnemonic = s.GenerateWallet(cryptoCode, "", true, true);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-21 09:33:12 +01:00
|
|
|
//lets import and save private keys
|
2020-03-23 07:46:54 +01:00
|
|
|
var root = mnemonic.DeriveExtKey();
|
2021-02-11 11:48:54 +01:00
|
|
|
invoiceId = s.CreateInvoice(storeName);
|
2020-06-24 03:34:09 +02:00
|
|
|
invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId);
|
|
|
|
address = invoice.EntityToDTO().Addresses["BTC"];
|
2021-10-29 11:01:16 +02:00
|
|
|
result = await s.Server.ExplorerNode.GetAddressInfoAsync(
|
|
|
|
BitcoinAddress.Create(address, Network.RegTest));
|
2020-06-24 03:34:09 +02:00
|
|
|
//spendable from bitcoin core wallet!
|
|
|
|
Assert.False(result.IsWatchOnly);
|
2021-10-29 11:01:16 +02:00
|
|
|
var tx = s.Server.ExplorerNode.SendToAddress(BitcoinAddress.Create(address, Network.RegTest),
|
|
|
|
Money.Coins(3.0m));
|
2021-01-25 14:10:19 +01:00
|
|
|
await s.Server.ExplorerNode.GenerateAsync(1);
|
2019-09-11 09:22:41 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
|
|
|
s.ClickOnAllSideMenus();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-08-03 07:27:04 +02:00
|
|
|
// Make sure wallet info is correct
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToWalletSettings(storeId, cryptoCode);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(),
|
|
|
|
s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value"));
|
|
|
|
Assert.Contains("m/84'/1'/0'",
|
|
|
|
s.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).GetAttribute("value"));
|
2021-11-11 06:30:19 +01:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
|
|
|
|
2019-10-12 13:35:30 +02:00
|
|
|
// Make sure we can rescan, because we are admin!
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("WalletRescan")).Click();
|
2019-10-12 13:35:30 +02:00
|
|
|
Assert.Contains("The batch size make sure", s.Driver.PageSource);
|
2021-11-11 06:30:19 +01:00
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
// Check the tx sent earlier arrived
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("WalletTransactions")).Click();
|
|
|
|
|
2019-09-11 09:22:41 +02:00
|
|
|
var walletTransactionLink = s.Driver.Url;
|
|
|
|
Assert.Contains(tx.ToString(), s.Driver.PageSource);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-06-14 07:06:56 +02:00
|
|
|
// Send to bob
|
|
|
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
|
|
|
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
|
|
|
SetTransactionOutput(s, 0, bob, 1);
|
|
|
|
s.Driver.FindElement(By.Id("SignTransaction")).Click();
|
2019-09-11 09:22:41 +02:00
|
|
|
|
2021-06-14 07:06:56 +02:00
|
|
|
// 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);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-21 09:33:12 +01:00
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-01-21 09:33:12 +01:00
|
|
|
var jack = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
2020-03-23 07:46:54 +01:00
|
|
|
SetTransactionOutput(s, 0, jack, 0.01m);
|
2021-06-14 07:06:56 +02:00
|
|
|
s.Driver.FindElement(By.Id("SignTransaction")).Click();
|
2021-05-19 04:39:27 +02:00
|
|
|
|
2020-01-21 09:33:12 +01:00
|
|
|
Assert.Contains(jack.ToString(), s.Driver.PageSource);
|
|
|
|
Assert.Contains("0.01000000", s.Driver.PageSource);
|
2021-07-30 19:37:54 +02:00
|
|
|
Assert.EndsWith("psbt/ready", s.Driver.Url);
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click();
|
2020-01-21 09:33:12 +01:00
|
|
|
Assert.Equal(walletTransactionLink, s.Driver.Url);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2020-02-13 09:18:43 +01:00
|
|
|
var bip21 = invoice.EntityToDTO().CryptoInfo.First().PaymentUrls.BIP21;
|
|
|
|
//let's make bip21 more interesting
|
|
|
|
bip21 += "&label=Solid Snake&message=Snake? Snake? SNAAAAKE!";
|
|
|
|
var parsedBip21 = new BitcoinUrlBuilder(bip21, Network.RegTest);
|
|
|
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("bip21parse")).Click();
|
|
|
|
s.Driver.SwitchTo().Alert().SendKeys(bip21);
|
|
|
|
s.Driver.SwitchTo().Alert().Accept();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Info);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal(parsedBip21.Amount.ToString(false),
|
|
|
|
s.Driver.FindElement(By.Id("Outputs_0__Amount")).GetAttribute("value"));
|
|
|
|
Assert.Equal(parsedBip21.Address.ToString(),
|
|
|
|
s.Driver.FindElement(By.Id("Outputs_0__DestinationAddress")).GetAttribute("value"));
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToWalletSettings(storeId, cryptoCode);
|
|
|
|
var settingsUrl = s.Driver.Url;
|
|
|
|
s.Driver.FindElement(By.Id("ActionsDropdownToggle")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("ViewSeed")).Click();
|
2020-07-16 20:09:28 +02:00
|
|
|
|
2020-07-15 23:58:18 +02:00
|
|
|
// Seed backup page
|
2021-10-29 11:01:16 +02:00
|
|
|
var recoveryPhrase = s.Driver.FindElements(By.Id("RecoveryPhrase")).First()
|
|
|
|
.GetAttribute("data-mnemonic");
|
2020-07-15 23:58:18 +02:00
|
|
|
Assert.Equal(mnemonic.ToString(), recoveryPhrase);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Contains("The recovery phrase will also be stored on the server as a hot wallet.",
|
|
|
|
s.Driver.PageSource);
|
2020-08-05 11:20:34 +02:00
|
|
|
|
|
|
|
// 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();
|
2021-11-11 06:30:19 +01:00
|
|
|
Assert.Equal(settingsUrl, s.Driver.Url);
|
2019-05-13 11:42:20 +02:00
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-08-03 07:27:04 +02:00
|
|
|
[Fact(Timeout = TestTimeout)]
|
|
|
|
public async Task CanImportWallet()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using (var s = CreateSeleniumTester())
|
2021-08-03 07:27:04 +02:00
|
|
|
{
|
|
|
|
await s.StartAsync();
|
|
|
|
s.RegisterNewUser(true);
|
2021-11-11 06:30:19 +01:00
|
|
|
(string _, string storeId) = s.CreateNewStore();
|
|
|
|
var cryptoCode = "BTC";
|
|
|
|
var mnemonic = s.GenerateWallet(cryptoCode, "click chunk owner kingdom faint steak safe evidence bicycle repeat bulb wheel");
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-08-03 07:27:04 +02:00
|
|
|
// Make sure wallet info is correct
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToWalletSettings(storeId, cryptoCode);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(),
|
|
|
|
s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value"));
|
|
|
|
Assert.Contains("m/84'/1'/0'",
|
|
|
|
s.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).GetAttribute("value"));
|
2021-08-03 07:27:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 03:34:09 +02:00
|
|
|
[Fact]
|
|
|
|
[Trait("Selenium", "Selenium")]
|
2021-10-18 05:37:59 +02:00
|
|
|
[Trait("Lightning", "Lightning")]
|
2020-06-24 03:34:09 +02:00
|
|
|
public async Task CanUsePullPaymentsViaUI()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using var s = CreateSeleniumTester();
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Server.ActivateLightning();
|
2021-06-30 09:59:01 +02:00
|
|
|
await s.StartAsync();
|
|
|
|
s.RegisterNewUser(true);
|
|
|
|
s.CreateNewStore();
|
|
|
|
s.GenerateWallet("BTC", "", true, true);
|
|
|
|
|
|
|
|
await s.Server.ExplorerNode.GenerateAsync(1);
|
|
|
|
await s.FundStoreWallet(denomination: 50.0m);
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
2021-06-30 09:59:01 +02:00
|
|
|
s.Driver.FindElement(By.Id("NewPullPayment")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Name")).SendKeys("PP1");
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).Clear();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("99.0");
|
2021-06-30 09:59:01 +02:00
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("View")).Click();
|
|
|
|
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
2021-06-30 09:59:01 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("NewPullPayment")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Name")).SendKeys("PP2");
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("100.0");
|
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
|
|
|
|
|
|
|
// This should select the first View, ie, the last one PP2
|
|
|
|
s.Driver.FindElement(By.LinkText("View")).Click();
|
|
|
|
var address = await s.Server.ExplorerNode.GetNewAddressAsync();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(address.ToString());
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys("15" + Keys.Enter);
|
|
|
|
s.FindAlertMessage();
|
|
|
|
|
|
|
|
// We should not be able to use an address already used
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(address.ToString());
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys("20" + Keys.Enter);
|
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Error);
|
|
|
|
|
|
|
|
address = await s.Server.ExplorerNode.GetNewAddressAsync();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(address.ToString());
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys("20" + Keys.Enter);
|
|
|
|
s.FindAlertMessage();
|
|
|
|
Assert.Contains("Awaiting Approval", s.Driver.PageSource);
|
|
|
|
|
|
|
|
var viewPullPaymentUrl = s.Driver.Url;
|
|
|
|
// This one should have nothing
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
2021-06-30 09:59:01 +02:00
|
|
|
var payouts = s.Driver.FindElements(By.ClassName("pp-payout"));
|
|
|
|
Assert.Equal(2, payouts.Count);
|
|
|
|
payouts[1].Click();
|
|
|
|
Assert.Empty(s.Driver.FindElements(By.ClassName("payout")));
|
|
|
|
// PP2 should have payouts
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
2021-06-30 09:59:01 +02:00
|
|
|
payouts = s.Driver.FindElements(By.ClassName("pp-payout"));
|
|
|
|
payouts[0].Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
Assert.NotEmpty(s.Driver.FindElements(By.ClassName("payout")));
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-selectAllCheckbox")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-actions")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-approve-pay")).Click();
|
2021-05-19 04:39:27 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
s.Driver.FindElement(By.Id("SignTransaction")).Click();
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click();
|
|
|
|
s.FindAlertMessage();
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
TestUtils.Eventually(() =>
|
|
|
|
{
|
|
|
|
s.Driver.Navigate().Refresh();
|
|
|
|
Assert.Contains("badge transactionLabel", s.Driver.PageSource);
|
|
|
|
});
|
|
|
|
Assert.Equal("payout", s.Driver.FindElement(By.ClassName("transactionLabel")).Text);
|
|
|
|
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Payouts);
|
2021-06-30 09:59:01 +02:00
|
|
|
var x = s.Driver.PageSource;
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.InProgress}-view")).Click();
|
|
|
|
ReadOnlyCollection<IWebElement> txs;
|
|
|
|
TestUtils.Eventually(() =>
|
|
|
|
{
|
|
|
|
s.Driver.Navigate().Refresh();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2020-06-24 03:34:09 +02:00
|
|
|
txs = s.Driver.FindElements(By.ClassName("transaction-link"));
|
|
|
|
Assert.Equal(2, txs.Count);
|
2021-06-30 09:59:01 +02:00
|
|
|
});
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
s.Driver.Navigate().GoToUrl(viewPullPaymentUrl);
|
|
|
|
txs = s.Driver.FindElements(By.ClassName("transaction-link"));
|
|
|
|
Assert.Equal(2, txs.Count);
|
|
|
|
Assert.Contains(PayoutState.InProgress.GetStateString(), s.Driver.PageSource);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
await s.Server.ExplorerNode.GenerateAsync(1);
|
2020-06-24 03:34:09 +02:00
|
|
|
|
2021-06-30 09:59:01 +02:00
|
|
|
TestUtils.Eventually(() =>
|
|
|
|
{
|
|
|
|
s.Driver.Navigate().Refresh();
|
|
|
|
Assert.Contains(PayoutState.Completed.GetStateString(), s.Driver.PageSource);
|
|
|
|
});
|
|
|
|
await s.Server.ExplorerNode.GenerateAsync(10);
|
|
|
|
var pullPaymentId = viewPullPaymentUrl.Split('/').Last();
|
|
|
|
|
|
|
|
await TestUtils.EventuallyAsync(async () =>
|
|
|
|
{
|
|
|
|
using var ctx = s.Server.PayTester.GetService<ApplicationDbContextFactory>().CreateContext();
|
|
|
|
var payoutsData = await ctx.Payouts.Where(p => p.PullPaymentDataId == pullPaymentId).ToListAsync();
|
|
|
|
Assert.True(payoutsData.All(p => p.State == PayoutState.Completed));
|
|
|
|
});
|
2021-07-16 09:57:37 +02:00
|
|
|
s.GoToHome();
|
|
|
|
//offline/external payout test
|
|
|
|
s.Driver.FindElement(By.Id("NotificationsDropdownToggle")).Click();
|
|
|
|
s.Driver.FindElement(By.CssSelector("#notificationsForm button")).Click();
|
|
|
|
|
|
|
|
var newStore = s.CreateNewStore();
|
|
|
|
s.GenerateWallet("BTC", "", true, true);
|
|
|
|
var newWalletId = new WalletId(newStore.storeId, "BTC");
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-07-16 09:57:37 +02:00
|
|
|
s.Driver.FindElement(By.Id("NewPullPayment")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Name")).SendKeys("External Test");
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("0.001");
|
|
|
|
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();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-07-16 09:57:37 +02:00
|
|
|
address = await s.Server.ExplorerNode.GetNewAddressAsync();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(address.ToString());
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys(Keys.Enter);
|
|
|
|
s.FindAlertMessage();
|
|
|
|
|
|
|
|
Assert.Contains(PayoutState.AwaitingApproval.GetStateString(), s.Driver.PageSource);
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Payouts);
|
2021-07-16 09:57:37 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-view")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-selectAllCheckbox")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-actions")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-approve")).Click();
|
|
|
|
s.FindAlertMessage();
|
2021-10-29 11:01:16 +02:00
|
|
|
var tx = await s.Server.ExplorerNode.SendToAddressAsync(address, Money.FromUnit(0.001m, MoneyUnit.BTC));
|
2021-07-16 09:57:37 +02:00
|
|
|
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Payouts);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-07-16 09:57:37 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-view")).Click();
|
|
|
|
Assert.Contains(PayoutState.AwaitingPayment.GetStateString(), s.Driver.PageSource);
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-selectAllCheckbox")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-actions")).Click();
|
2021-08-05 07:47:25 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-mark-paid")).Click();
|
2021-07-16 09:57:37 +02:00
|
|
|
s.FindAlertMessage();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.InProgress}-view")).Click();
|
2021-07-16 09:57:37 +02:00
|
|
|
Assert.Contains(tx.ToString(), s.Driver.PageSource);
|
2021-10-18 05:37:59 +02:00
|
|
|
|
|
|
|
//lightning tests
|
|
|
|
newStore = s.CreateNewStore();
|
|
|
|
s.AddLightningNode("BTC");
|
2021-10-29 08:25:43 +02:00
|
|
|
//Currently an onchain wallet is required to use the Lightning payouts feature..
|
2021-10-18 05:37:59 +02:00
|
|
|
s.GenerateWallet("BTC", "", true, true);
|
2021-10-22 04:17:40 +02:00
|
|
|
|
|
|
|
s.GoToStore(newStore.storeId, StoreNavPages.PullPayments);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id("NewPullPayment")).Click();
|
|
|
|
|
2021-11-16 04:58:17 +01:00
|
|
|
var paymentMethodOptions = s.Driver.FindElements(By.CssSelector("input[name='PaymentMethods']"));
|
2021-10-18 05:37:59 +02:00
|
|
|
Assert.Equal(2, paymentMethodOptions.Count);
|
|
|
|
|
|
|
|
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("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),
|
|
|
|
$"LN payout test {DateTime.Now.Ticks}",
|
|
|
|
TimeSpan.FromHours(1), CancellationToken.None)).BOLT11;
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(bolt);
|
|
|
|
s.Driver.FindElement(By.Id("SelectedPaymentMethod")).Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.CssSelector(
|
|
|
|
$"#SelectedPaymentMethod option[value={new PaymentMethodId("BTC", PaymentTypes.LightningLike)}]"))
|
|
|
|
.Click();
|
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys(Keys.Enter);
|
|
|
|
//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),
|
|
|
|
$"LN payout test {DateTime.Now.Ticks}",
|
|
|
|
TimeSpan.FromDays(31), CancellationToken.None)).BOLT11;
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(bolt);
|
|
|
|
s.Driver.FindElement(By.Id("SelectedPaymentMethod")).Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.CssSelector(
|
|
|
|
$"#SelectedPaymentMethod option[value={new PaymentMethodId("BTC", PaymentTypes.LightningLike)}]"))
|
|
|
|
.Click();
|
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys(Keys.Enter);
|
|
|
|
s.FindAlertMessage();
|
|
|
|
|
|
|
|
Assert.Contains(PayoutState.AwaitingApproval.GetStateString(), s.Driver.PageSource);
|
2021-10-22 04:17:40 +02:00
|
|
|
|
|
|
|
s.GoToStore(newStore.storeId, StoreNavPages.Payouts);
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{new PaymentMethodId("BTC", PaymentTypes.LightningLike)}-view")).Click();
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-view")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-selectAllCheckbox")).Click();
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
2021-10-29 11:01:16 +02:00
|
|
|
s.FindAlertMessage(new[]
|
|
|
|
{
|
|
|
|
StatusMessageModel.StatusSeverity.Error, StatusMessageModel.StatusSeverity.Success
|
|
|
|
});
|
2021-10-22 04:17:40 +02:00
|
|
|
s.GoToStore(newStore.storeId, StoreNavPages.Payouts);
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{new PaymentMethodId("BTC", PaymentTypes.LightningLike)}-view")).Click();
|
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.Completed}-view")).Click();
|
|
|
|
if (!s.Driver.PageSource.Contains(bolt))
|
|
|
|
{
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-view")).Click();
|
|
|
|
Assert.Contains(bolt, s.Driver.PageSource);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-18 05:37:59 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-selectAllCheckbox")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-actions")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingPayment}-mark-paid")).Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id($"{new PaymentMethodId("BTC", PaymentTypes.LightningLike)}-view")).Click();
|
2021-10-18 05:37:59 +02:00
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.Completed}-view")).Click();
|
|
|
|
Assert.Contains(bolt, s.Driver.PageSource);
|
|
|
|
}
|
2021-10-26 13:55:13 +02:00
|
|
|
}
|
2021-10-29 10:27:33 +02:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Trait("Selenium", "Selenium")]
|
|
|
|
[Trait("Lightning", "Lightning")]
|
|
|
|
public async Task CanUsePOSPrint()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using var s = CreateSeleniumTester();
|
2021-10-29 10:27:33 +02:00
|
|
|
s.Server.ActivateLightning();
|
|
|
|
await s.StartAsync();
|
|
|
|
|
|
|
|
await s.Server.EnsureChannelsSetup();
|
|
|
|
|
|
|
|
s.RegisterNewUser(true);
|
2021-11-11 06:30:19 +01:00
|
|
|
var cryptoCode = "BTC";
|
|
|
|
(_, string storeId) = s.CreateNewStore();
|
|
|
|
var network = s.Server.NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode).NBitcoinNetwork;
|
|
|
|
s.GoToStore(storeId);
|
|
|
|
s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning, false);
|
|
|
|
s.GoToLightningSettings(storeId, cryptoCode);
|
2021-10-29 10:27:33 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true);
|
|
|
|
s.GoToApps();
|
|
|
|
s.Driver.FindElement(By.Id("CreateNewApp")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("SelectedAppType")).Click();
|
|
|
|
s.Driver.FindElement(By.CssSelector("option[value='PointOfSale']")).Click();
|
2021-10-29 16:09:19 +02:00
|
|
|
s.Driver.FindElement(By.Id("AppName")).SendKeys(Guid.NewGuid().ToString());
|
2021-10-29 10:27:33 +02:00
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
|
|
|
|
s.Driver.FindElement(By.Id("DefaultView")).Click();
|
|
|
|
s.Driver.FindElement(By.CssSelector("option[value='3']")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("SaveSettings")).Click();
|
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("ViewApp")).Click();
|
|
|
|
var btns = s.Driver.FindElements(By.ClassName("lnurl"));
|
|
|
|
foreach (IWebElement webElement in btns)
|
|
|
|
{
|
|
|
|
var choice = webElement.GetAttribute("data-choice");
|
|
|
|
var lnurl = webElement.GetAttribute("href");
|
|
|
|
var parsed = LNURL.LNURL.Parse(lnurl, out _);
|
2021-10-29 14:51:41 +02:00
|
|
|
Assert.EndsWith(choice, parsed.ToString());
|
2021-10-29 10:27:33 +02:00
|
|
|
Assert.IsType<LNURLPayRequest>(await LNURL.LNURL.FetchInformation(parsed, new HttpClient()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:25:43 +02:00
|
|
|
[Fact]
|
2021-10-26 13:55:13 +02:00
|
|
|
[Trait("Selenium", "Selenium")]
|
|
|
|
[Trait("Lightning", "Lightning")]
|
|
|
|
public async Task CanUseLNURL()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using var s = CreateSeleniumTester();
|
2021-10-26 13:55:13 +02:00
|
|
|
s.Server.ActivateLightning();
|
|
|
|
await s.StartAsync();
|
|
|
|
await s.Server.EnsureChannelsSetup();
|
2021-10-29 08:25:43 +02:00
|
|
|
var cryptoCode = "BTC";
|
|
|
|
await Lightning.Tests.ConnectChannels.ConnectAll(s.Server.ExplorerNode,
|
2021-10-26 13:55:13 +02:00
|
|
|
new[] { s.Server.MerchantLightningD },
|
|
|
|
new[] { s.Server.MerchantLnd.Client });
|
|
|
|
s.RegisterNewUser(true);
|
2021-11-11 06:30:19 +01:00
|
|
|
(string storeName, string storeId) = s.CreateNewStore();
|
2021-10-29 08:25:43 +02:00
|
|
|
var network = s.Server.NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode).NBitcoinNetwork;
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToStore(storeId);
|
2021-10-29 08:25:43 +02:00
|
|
|
s.AddLightningNode(cryptoCode, LightningConnectionType.CLightning);
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToLightningSettings(storeId, cryptoCode);
|
2021-10-29 08:25:43 +02:00
|
|
|
// LNURL is false by default
|
|
|
|
Assert.False(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected);
|
|
|
|
// LNURL settings are not expanded when LNURL is disabled
|
|
|
|
Assert.DoesNotContain("show", s.Driver.FindElement(By.Id("LNURLSettings")).GetAttribute("class"));
|
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true);
|
|
|
|
s.Driver.WaitForAndClick(By.Id("save"));
|
|
|
|
Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text);
|
|
|
|
|
|
|
|
// Topup Invoice test
|
2021-11-11 06:30:19 +01:00
|
|
|
var i = s.CreateInvoice(storeName, null, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(i);
|
|
|
|
s.Driver.FindElement(By.Id("copy-tab")).Click();
|
|
|
|
var lnurl = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value");
|
|
|
|
var parsed = LNURL.LNURL.Parse(lnurl, out var tag);
|
2021-10-29 11:01:16 +02:00
|
|
|
var fetchedReuqest =
|
|
|
|
Assert.IsType<LNURL.LNURLPayRequest>(await LNURL.LNURL.FetchInformation(parsed, new HttpClient()));
|
2021-10-26 13:55:13 +02:00
|
|
|
Assert.Equal(1m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.Satoshi));
|
|
|
|
Assert.NotEqual(1m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.Satoshi));
|
|
|
|
var lnurlResponse = await fetchedReuqest.SendRequest(new LightMoney(0.000001m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
2021-10-29 11:01:16 +02:00
|
|
|
|
|
|
|
Assert.Equal(new LightMoney(0.000001m, LightMoneyUnit.BTC),
|
|
|
|
lnurlResponse.GetPaymentRequest(network).MinimumAmount);
|
|
|
|
|
2021-10-26 13:55:13 +02:00
|
|
|
var lnurlResponse2 = await fetchedReuqest.SendRequest(new LightMoney(0.000002m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
|
|
|
Assert.Equal(new LightMoney(0.000002m, LightMoneyUnit.BTC), lnurlResponse2.GetPaymentRequest(network).MinimumAmount);
|
2021-10-29 08:25:43 +02:00
|
|
|
await Assert.ThrowsAnyAsync<LightningRPCException>(async () =>
|
2021-10-26 13:55:13 +02:00
|
|
|
{
|
2021-10-29 08:25:43 +02:00
|
|
|
// Initial bolt was cancelled
|
2021-10-26 13:55:13 +02:00
|
|
|
await s.Server.CustomerLightningD.Pay(lnurlResponse.Pr);
|
|
|
|
});
|
2021-10-29 08:25:43 +02:00
|
|
|
|
|
|
|
await s.Server.CustomerLightningD.Pay(lnurlResponse2.Pr);
|
2021-10-26 13:55:13 +02:00
|
|
|
await TestUtils.EventuallyAsync(async () =>
|
|
|
|
{
|
|
|
|
var inv = await s.Server.PayTester.InvoiceRepository.GetInvoice(i);
|
|
|
|
Assert.Equal(InvoiceStatusLegacy.Complete, inv.Status);
|
|
|
|
});
|
|
|
|
|
2021-10-29 08:25:43 +02:00
|
|
|
// Standard invoice test
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToHome();
|
2021-11-11 06:30:19 +01:00
|
|
|
i = s.CreateInvoice(storeName, 0.0000001m, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(i);
|
|
|
|
s.Driver.FindElement(By.ClassName("payment__currencies")).Click();
|
2021-10-29 08:25:43 +02:00
|
|
|
// BOLT11 is also available for standard invoices
|
2021-10-26 13:55:13 +02:00
|
|
|
Assert.Equal(2, s.Driver.FindElements(By.CssSelector(".vex.vex-theme-btcpay .vex-content .vexmenu li.vexmenuitem")).Count);
|
|
|
|
s.Driver.FindElement(By.CssSelector(".vex.vex-theme-btcpay .vex-content .vexmenu li.vexmenuitem")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("copy-tab")).Click();
|
|
|
|
lnurl = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value");
|
|
|
|
parsed = LNURL.LNURL.Parse(lnurl, out tag);
|
2021-10-29 08:25:43 +02:00
|
|
|
fetchedReuqest = Assert.IsType<LNURLPayRequest>(await LNURL.LNURL.FetchInformation(parsed, new HttpClient()));
|
2021-10-26 13:55:13 +02:00
|
|
|
Assert.Equal(0.0000001m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.BTC));
|
|
|
|
Assert.Equal(0.0000001m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.BTC));
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<HttpRequestException>(async () =>
|
|
|
|
{
|
|
|
|
await fetchedReuqest.SendRequest(new LightMoney(0.0000002m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
|
|
|
});
|
|
|
|
await Assert.ThrowsAsync<HttpRequestException>(async () =>
|
|
|
|
{
|
|
|
|
await fetchedReuqest.SendRequest(new LightMoney(0.00000005m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
|
|
|
});
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-26 13:55:13 +02:00
|
|
|
lnurlResponse = await fetchedReuqest.SendRequest(new LightMoney(0.0000001m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
|
|
|
lnurlResponse2 = await fetchedReuqest.SendRequest(new LightMoney(0.0000001m, LightMoneyUnit.BTC),
|
|
|
|
network, new HttpClient());
|
2021-10-29 11:01:16 +02:00
|
|
|
//invoice amounts do no change so the paymnet request is not regenerated
|
|
|
|
Assert.Equal(lnurlResponse.Pr, lnurlResponse2.Pr);
|
2021-10-26 13:55:13 +02:00
|
|
|
await s.Server.CustomerLightningD.Pay(lnurlResponse.Pr);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.Equal(new LightMoney(0.0000001m, LightMoneyUnit.BTC),
|
|
|
|
lnurlResponse2.GetPaymentRequest(network).MinimumAmount);
|
2021-11-16 04:58:17 +01:00
|
|
|
|
|
|
|
s.GoToLightningSettings(s.StoreId, cryptoCode);
|
2021-10-29 08:25:43 +02:00
|
|
|
// LNURL is enabled and settings are expanded
|
|
|
|
Assert.True(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected);
|
|
|
|
Assert.Contains("show", s.Driver.FindElement(By.Id("LNURLSettings")).GetAttribute("class"));
|
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), false);
|
|
|
|
s.Driver.FindElement(By.Id("save")).Click();
|
|
|
|
Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text);
|
|
|
|
|
2021-11-11 06:30:19 +01:00
|
|
|
i = s.CreateInvoice(storeName, 0.000001m, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(i);
|
|
|
|
s.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
|
|
|
|
|
|
|
s.GoToHome();
|
2021-11-11 06:30:19 +01:00
|
|
|
i = s.CreateInvoice(storeName, null, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(i);
|
|
|
|
s.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-11-16 04:58:17 +01:00
|
|
|
s.GoToLightningSettings(s.StoreId, cryptoCode);
|
2021-10-29 08:25:43 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLBech32Mode"), false);
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), false);
|
2021-10-29 08:25:43 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("DisableBolt11PaymentMethod"), true);
|
|
|
|
s.Driver.FindElement(By.Id("save")).Click();
|
|
|
|
Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text);
|
2021-10-26 13:55:13 +02:00
|
|
|
|
2021-10-29 08:25:43 +02:00
|
|
|
// Ensure the toggles are set correctly
|
2021-11-16 04:58:17 +01:00
|
|
|
s.GoToLightningSettings(s.StoreId, cryptoCode);
|
2021-10-29 16:09:19 +02:00
|
|
|
|
|
|
|
//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);
|
2021-10-29 11:01:16 +02:00
|
|
|
Assert.False(s.Driver.FindElement(By.Id("LNURLStandardInvoiceEnabled")).Selected);
|
2021-10-29 08:25:43 +02:00
|
|
|
Assert.False(s.Driver.FindElement(By.Id("LNURLBech32Mode")).Selected);
|
2021-11-11 06:30:19 +01:00
|
|
|
s.CreateInvoice(storeName, 0.0000001m, cryptoCode,"",null, expectedSeverity: StatusMessageModel.StatusSeverity.Error);
|
2021-10-29 08:25:43 +02:00
|
|
|
|
2021-11-11 06:30:19 +01:00
|
|
|
i = s.CreateInvoice(storeName, null, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(i);
|
|
|
|
s.Driver.FindElement(By.ClassName("payment__currencies_noborder"));
|
|
|
|
s.Driver.FindElement(By.Id("copy-tab")).Click();
|
|
|
|
lnurl = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value");
|
|
|
|
Assert.StartsWith("lnurlp", lnurl);
|
2021-10-29 08:25:43 +02:00
|
|
|
LNURL.LNURL.Parse(lnurl, out tag);
|
2021-10-26 13:55:13 +02:00
|
|
|
|
|
|
|
s.GoToHome();
|
|
|
|
var newStore = s.CreateNewStore(false);
|
2021-10-29 08:25:43 +02:00
|
|
|
s.AddLightningNode(cryptoCode, LightningConnectionType.LndREST, false);
|
2021-11-16 04:58:17 +01:00
|
|
|
s.GoToLightningSettings(newStore.storeId, cryptoCode);
|
2021-10-29 08:25:43 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true);
|
|
|
|
s.Driver.SetCheckbox(By.Id("DisableBolt11PaymentMethod"), true);
|
|
|
|
s.Driver.FindElement(By.Id("save")).Click();
|
|
|
|
Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text);
|
|
|
|
var invForPP = s.CreateInvoice(newStore.storeName, 0.0000001m, cryptoCode);
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToInvoiceCheckout(invForPP);
|
|
|
|
s.Driver.FindElement(By.Id("copy-tab")).Click();
|
|
|
|
lnurl = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value");
|
|
|
|
parsed = LNURL.LNURL.Parse(lnurl, out tag);
|
|
|
|
|
2021-10-29 08:25:43 +02:00
|
|
|
// Check that pull payment has lightning option
|
2021-10-26 13:55:13 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
|
|
|
s.Driver.FindElement(By.Id("NewPullPayment")).Click();
|
2021-11-16 04:58:17 +01:00
|
|
|
Assert.Equal(new PaymentMethodId(cryptoCode, PaymentTypes.LightningLike),PaymentMethodId.Parse(Assert.Single(s.Driver.FindElements(By.CssSelector("input[name='PaymentMethods']"))).GetAttribute("value")));
|
2021-10-26 13:55:13 +02:00
|
|
|
s.Driver.FindElement(By.Id("Name")).SendKeys("PP1");
|
|
|
|
s.Driver.FindElement(By.Id("Amount")).Clear();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("0.0000001");
|
2021-10-26 13:55:13 +02:00
|
|
|
s.Driver.FindElement(By.Id("Create")).Click();
|
|
|
|
s.Driver.FindElement(By.LinkText("View")).Click();
|
|
|
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(lnurl);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-26 13:55:13 +02:00
|
|
|
var pullPaymentId = s.Driver.Url.Split('/').Last();
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).Clear();
|
|
|
|
s.Driver.FindElement(By.Id("ClaimedAmount")).SendKeys("0.0000001" + Keys.Enter);
|
|
|
|
s.FindAlertMessage();
|
|
|
|
|
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.PullPayments);
|
|
|
|
var payouts = s.Driver.FindElements(By.ClassName("pp-payout"));
|
|
|
|
payouts[0].Click();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id("BTC_LightningLike-view")).Click();
|
2021-10-26 13:55:13 +02:00
|
|
|
Assert.NotEmpty(s.Driver.FindElements(By.ClassName("payout")));
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-selectAllCheckbox")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-actions")).Click();
|
|
|
|
s.Driver.FindElement(By.Id($"{PayoutState.AwaitingApproval}-approve-pay")).Click();
|
|
|
|
|
|
|
|
Assert.Contains(lnurl, s.Driver.PageSource);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-26 13:55:13 +02:00
|
|
|
s.Driver.FindElement(By.Id("pay-invoices-form")).Submit();
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-10-26 13:55:13 +02:00
|
|
|
await TestUtils.EventuallyAsync(async () =>
|
|
|
|
{
|
|
|
|
var inv = await s.Server.PayTester.InvoiceRepository.GetInvoice(invForPP);
|
|
|
|
Assert.Equal(InvoiceStatusLegacy.Complete, inv.Status);
|
|
|
|
|
|
|
|
await using var ctx = s.Server.PayTester.GetService<ApplicationDbContextFactory>().CreateContext();
|
|
|
|
var payoutsData = await ctx.Payouts.Where(p => p.PullPaymentDataId == pullPaymentId).ToListAsync();
|
|
|
|
Assert.True(payoutsData.All(p => p.State == PayoutState.Completed));
|
|
|
|
});
|
2020-06-24 03:34:09 +02:00
|
|
|
}
|
2021-01-22 17:49:26 +01:00
|
|
|
|
2021-10-29 11:01:16 +02:00
|
|
|
[Fact]
|
|
|
|
[Trait("Selenium", "Selenium")]
|
|
|
|
[Trait("Lightning", "Lightning")]
|
|
|
|
public async Task CanUseLNAddress()
|
|
|
|
{
|
2021-11-22 09:16:08 +01:00
|
|
|
using var s = CreateSeleniumTester();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Server.ActivateLightning();
|
|
|
|
await s.StartAsync();
|
|
|
|
await s.Server.EnsureChannelsSetup();
|
2021-11-11 06:30:19 +01:00
|
|
|
var cryptoCode = "BTC";
|
2021-10-29 11:01:16 +02:00
|
|
|
s.RegisterNewUser(true);
|
|
|
|
//ln address tests
|
2021-11-11 06:30:19 +01:00
|
|
|
s.CreateNewStore();
|
2021-10-29 11:01:16 +02:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Integrations);
|
2021-11-10 10:50:39 +01:00
|
|
|
//ensure ln address is not available as Lightning is not enable
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.FindElement(By.Id("lightning-address-option"))
|
2021-11-10 10:50:39 +01:00
|
|
|
.FindElement(By.LinkText("You need to setup Lightning first"));
|
2021-10-29 11:01:16 +02:00
|
|
|
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToStore(s.StoreId);
|
2021-10-29 11:01:16 +02:00
|
|
|
s.AddLightningNode("BTC", LightningConnectionType.LndREST, false);
|
2021-11-10 10:50:39 +01:00
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Integrations);
|
|
|
|
//ensure ln address is not available as lnurl is not configured
|
|
|
|
s.Driver.FindElement(By.Id("lightning-address-option"))
|
|
|
|
.FindElement(By.LinkText("You need LNURL configured first"));
|
|
|
|
|
2021-11-11 06:30:19 +01:00
|
|
|
s.GoToLightningSettings(s.StoreId, cryptoCode);
|
2021-10-29 11:01:16 +02:00
|
|
|
s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true);
|
|
|
|
s.Driver.WaitForAndClick(By.Id("save"));
|
2021-11-11 06:30:19 +01:00
|
|
|
Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text);
|
2021-10-29 11:01:16 +02:00
|
|
|
|
|
|
|
s.GoToStore(s.StoreId, StoreNavPages.Integrations);
|
|
|
|
s.Driver.FindElement(By.Id("lightning-address-option"))
|
|
|
|
.FindElement(By.Id("lightning-address-setup-link")).Click();
|
|
|
|
|
|
|
|
s.Driver.ToggleCollapse("AddAddress");
|
|
|
|
var lnaddress1 = Guid.NewGuid().ToString();
|
|
|
|
s.Driver.FindElement(By.Id("Add_Username")).SendKeys(lnaddress1);
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value='add']")).Click();
|
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
|
|
|
|
|
|
|
|
s.Driver.ToggleCollapse("AddAddress");
|
|
|
|
s.Driver.FindElement(By.Id("Add_Username")).SendKeys(lnaddress1);
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value='add']")).Click();
|
|
|
|
s.Driver.FindElement(By.ClassName("text-danger"));
|
|
|
|
|
|
|
|
s.Driver.FindElement(By.Id("Add_Username")).Clear();
|
|
|
|
var lnaddress2 = "EUR" + Guid.NewGuid().ToString();
|
|
|
|
s.Driver.FindElement(By.Id("Add_Username")).SendKeys(lnaddress2);
|
|
|
|
|
|
|
|
s.Driver.ToggleCollapse("AdvancedSettings");
|
|
|
|
s.Driver.FindElement(By.Id("Add_CurrencyCode")).SendKeys("EUR");
|
|
|
|
s.Driver.FindElement(By.Id("Add_Min")).SendKeys("2");
|
|
|
|
s.Driver.FindElement(By.Id("Add_Max")).SendKeys("10");
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value='add']")).Click();
|
|
|
|
s.FindAlertMessage(StatusMessageModel.StatusSeverity.Success);
|
|
|
|
|
|
|
|
var addresses = s.Driver.FindElements(By.ClassName("lightning-address-value"));
|
|
|
|
Assert.Equal(2, addresses.Count);
|
|
|
|
|
|
|
|
foreach (IWebElement webElement in addresses)
|
|
|
|
{
|
|
|
|
var value = webElement.GetAttribute("value");
|
|
|
|
//cannot test this directly as https is not supported on our e2e tests
|
|
|
|
// var request = await LNURL.LNURL.FetchPayRequestViaInternetIdentifier(value, new HttpClient());
|
|
|
|
|
|
|
|
var lnurl = new Uri(LNURL.LNURL.ExtractUriFromInternetIdentifier(value).ToString()
|
|
|
|
.Replace("https", "http"));
|
|
|
|
var request =(LNURL.LNURLPayRequest) await LNURL.LNURL.FetchInformation(lnurl, new HttpClient());
|
|
|
|
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case { } v when v.StartsWith(lnaddress2):
|
|
|
|
Assert.Equal(2, request.MinSendable.ToDecimal(LightMoneyUnit.Satoshi));
|
|
|
|
Assert.Equal(10, request.MaxSendable.ToDecimal(LightMoneyUnit.Satoshi));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case { } v when v.StartsWith(lnaddress1):
|
|
|
|
Assert.Equal(1, request.MinSendable.ToDecimal(LightMoneyUnit.Satoshi));
|
|
|
|
Assert.Equal(6.12m, request.MaxSendable.ToDecimal(LightMoneyUnit.BTC));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:49:26 +01:00
|
|
|
private static void CanBrowseContent(SeleniumTester s)
|
|
|
|
{
|
|
|
|
s.Driver.FindElement(By.ClassName("delivery-content")).Click();
|
|
|
|
var windows = s.Driver.WindowHandles;
|
|
|
|
Assert.Equal(2, windows.Count);
|
|
|
|
s.Driver.SwitchTo().Window(windows[1]);
|
|
|
|
JObject.Parse(s.Driver.FindElement(By.TagName("body")).Text);
|
|
|
|
s.Driver.Close();
|
|
|
|
s.Driver.SwitchTo().Window(windows[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void CanSetupEmailCore(SeleniumTester s)
|
|
|
|
{
|
2021-05-19 04:39:27 +02:00
|
|
|
s.Driver.FindElement(By.Id("QuickFillDropdownToggle")).Click();
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.ClassName("dropdown-item")).Click();
|
2021-05-19 04:39:27 +02:00
|
|
|
|
2021-01-22 17:49:26 +01:00
|
|
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("test@gmail.com");
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=\"Save\"]")).Submit();
|
|
|
|
s.FindAlertMessage();
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("mypassword");
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=\"Save\"]")).Submit();
|
|
|
|
Assert.Contains("Configured", s.Driver.PageSource);
|
|
|
|
s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("test_fix@gmail.com");
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=\"Save\"]")).Submit();
|
|
|
|
Assert.Contains("Configured", s.Driver.PageSource);
|
|
|
|
Assert.Contains("test_fix", s.Driver.PageSource);
|
|
|
|
s.Driver.FindElement(By.CssSelector("button[value=\"ResetPassword\"]")).Submit();
|
|
|
|
s.FindAlertMessage();
|
|
|
|
Assert.DoesNotContain("Configured", s.Driver.PageSource);
|
|
|
|
Assert.Contains("test_fix", s.Driver.PageSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string AssertUrlHasPairingCode(SeleniumTester s)
|
|
|
|
{
|
|
|
|
var regex = Regex.Match(new Uri(s.Driver.Url, UriKind.Absolute).Query, "pairingCode=([^&]*)");
|
|
|
|
Assert.True(regex.Success, $"{s.Driver.Url} does not match expected regex");
|
|
|
|
var pairingCode = regex.Groups[1].Value;
|
|
|
|
return pairingCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetTransactionOutput(SeleniumTester s, int index, BitcoinAddress dest, decimal amount, bool subtract = false)
|
|
|
|
{
|
|
|
|
s.Driver.FindElement(By.Id($"Outputs_{index}__DestinationAddress")).SendKeys(dest.ToString());
|
|
|
|
var amountElement = s.Driver.FindElement(By.Id($"Outputs_{index}__Amount"));
|
|
|
|
amountElement.Clear();
|
|
|
|
amountElement.SendKeys(amount.ToString(CultureInfo.InvariantCulture));
|
|
|
|
var checkboxElement = s.Driver.FindElement(By.Id($"Outputs_{index}__SubtractFeesFromOutput"));
|
|
|
|
if (checkboxElement.Selected != subtract)
|
|
|
|
{
|
|
|
|
checkboxElement.Click();
|
|
|
|
}
|
|
|
|
}
|
2019-05-12 10:13:26 +02:00
|
|
|
}
|
|
|
|
}
|