Test invoice creation (#30)

This commit is contained in:
Deverick 2025-06-21 22:40:15 -05:00 committed by napoly
parent 052915ec05
commit b544981bc5
6 changed files with 79 additions and 3 deletions

4
.gitignore vendored
View file

@ -5,4 +5,6 @@ Plugins/packed
.vs/
coverage
nuget-packages
**/.AssemblyAttributes
**/.AssemblyAttributes
btcpay-monero-plugin.sln.DotSettings.user
.DS_Store

View file

@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="Microsoft.Playwright" Version="1.52.0"/>
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View file

@ -11,6 +11,7 @@ namespace BTCPayServer.Plugins.IntegrationTests.Monero
{
SetDefaultEnv("BTCPAY_XMR_DAEMON_URI", "http://127.0.0.1:18081");
SetDefaultEnv("BTCPAY_XMR_WALLET_DAEMON_URI", "http://127.0.0.1:18082");
SetDefaultEnv("BTCPAY_XMR_WALLET_DAEMON_WALLETDIR", "/wallet");
}
private static void SetDefaultEnv(string key, string defaultValue)

View file

@ -1,4 +1,7 @@
using BTCPayServer.Rating;
using BTCPayServer.Services.Rates;
using BTCPayServer.Tests;
using BTCPayServer.Tests.Mocks;
using Xunit;
using Xunit.Abstractions;
@ -12,13 +15,78 @@ public class MoneroPluginIntegrationTest(ITestOutputHelper helper) : MoneroAndBi
{
await using var s = CreatePlaywrightTester();
await s.StartAsync();
if (s.Server.PayTester.MockRates)
{
var rateProviderFactory = s.Server.PayTester.GetService<RateProviderFactory>();
rateProviderFactory.Providers.Clear();
var coinAverageMock = new MockRateProvider();
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_USD"), new BidAsk(5000m)));
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_EUR"), new BidAsk(4000m)));
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_BTC"), new BidAsk(4500m)));
rateProviderFactory.Providers.Add("coingecko", coinAverageMock);
var kraken = new MockRateProvider();
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_USD"), new BidAsk(0.1m)));
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_USD"), new BidAsk(0.1m)));
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_BTC"), new BidAsk(0.1m)));
rateProviderFactory.Providers.Add("kraken", kraken);
}
await s.RegisterNewUser(true);
await s.CreateNewStore();
await s.CreateNewStore(preferredExchange: "Kraken");
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
await s.Page.CheckAsync("#Enabled");
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "2");
await s.Page.ClickAsync("#SaveButton");
var classList = await s.Page.Locator("svg.icon-checkmark").GetAttributeAsync("class");
Assert.Contains("text-success", classList);
// Set rate provider
await s.Page.Locator("#StoreNav-General").ClickAsync();
await s.Page.Locator("#mainNav #StoreNav-Rates").ClickAsync();
await s.Page.FillAsync("#DefaultCurrencyPairs", "BTC_USD,XMR_USD,XMR_BTC");
await s.Page.SelectOptionAsync("#PrimarySource_PreferredExchange", "kraken");
await s.Page.Locator("#page-primary").ClickAsync();
// Generate a new invoice
await s.Page.Locator("a.nav-link[href*='invoices']").ClickAsync();
await s.Page.Locator("#page-primary").ClickAsync();
await s.Page.FillAsync("#Amount", "4.20");
await s.Page.FillAsync("#BuyerEmail", "monero@monero.com");
await Task.Delay(TimeSpan.FromSeconds(25)); // wallet-rpc needs some time to sync. refactor this later
await s.Page.Locator("#page-primary").ClickAsync();
// View the invoice
var href = await s.Page.Locator("a[href^='/i/']").GetAttributeAsync("href");
var invoiceId = href?.Split("/i/").Last();
await s.Page.Locator($"a[href='/i/{invoiceId}']").ClickAsync();
await s.Page.ClickAsync("#DetailsToggle");
// Verify the total fiat amount is $4.20
var totalFiat = await s.Page.Locator("#PaymentDetails-TotalFiat dd.clipboard-button").InnerTextAsync();
Assert.Equal("$4.20", totalFiat);
await s.Page.GoBackAsync();
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
// Create a new account label
await s.Page.FillAsync("#NewAccountLabel", "tst-account");
await s.Page.ClickAsync("button[name='command'][value='add-account']");
// Select primary Account Index
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
await s.Page.SelectOptionAsync("#AccountIndex", "1");
await s.Page.ClickAsync("#SaveButton");
// Verify selected account index
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
var selectedValue = await s.Page.Locator("#AccountIndex").InputValueAsync();
Assert.Equal("1", selectedValue);
// Select confirmation time to 0
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "3");
await s.Page.ClickAsync("#SaveButton");
}
}

View file

@ -13,6 +13,7 @@ services:
TESTS_INCONTAINER: "true"
BTCPAY_XMR_DAEMON_URI: http://monerod:18081
BTCPAY_XMR_WALLET_DAEMON_URI: http://xmr_wallet:18082
BTCPAY_XMR_WALLET_DAEMON_WALLETDIR: /wallet
depends_on:
- nbxplorer
- postgres

View file

@ -87,6 +87,10 @@ Global
{BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Release|Any CPU.Build.0 = Release|Any CPU
{EE24163B-B82C-4561-92F2-C7198CE91F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE24163B-B82C-4561-92F2-C7198CE91F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE24163B-B82C-4561-92F2-C7198CE91F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE24163B-B82C-4561-92F2-C7198CE91F67}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{049FC011-1952-4140-9652-12921C106B02} = {891F21E0-262C-4430-90C5-7A540AD7C9AD}