Skip to content

Commit ac19857

Browse files
Test invoice creation
1 parent e9ecf24 commit ac19857

File tree

4 files changed

+111
-3
lines changed

4 files changed

+111
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Plugins/packed
55
.vs/
66
coverage
77
nuget-packages
8-
**/.AssemblyAttributes
8+
**/.AssemblyAttributes
9+
btcpay-monero-plugin.sln.DotSettings.user
10+
.DS_Store

BTCPayServer.Plugins.IntegrationTests/BTCPayServer.Plugins.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
1212
<PackageReference Include="Microsoft.Playwright" Version="1.52.0"/>
1313
<PackageReference Include="xunit" Version="2.9.3"/>
14-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
14+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>

BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginUITest.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using BTCPayServer.Rating;
2+
using BTCPayServer.Services.Rates;
13
using BTCPayServer.Tests;
4+
using BTCPayServer.Tests.Mocks;
25

36
using Xunit;
47
using Xunit.Abstractions;
@@ -12,13 +15,76 @@ public async Task EnableMoneroPluginSuccessfully()
1215
{
1316
await using var s = CreatePlaywrightTester();
1417
await s.StartAsync();
18+
19+
if (s.Server.PayTester.MockRates)
20+
{
21+
var rateProviderFactory = s.Server.PayTester.GetService<RateProviderFactory>();
22+
rateProviderFactory.Providers.Clear();
23+
24+
var coinAverageMock = new MockRateProvider();
25+
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_USD"), new BidAsk(5000m)));
26+
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_EUR"), new BidAsk(4000m)));
27+
coinAverageMock.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_BTC"), new BidAsk(4500m)));
28+
rateProviderFactory.Providers.Add("coingecko", coinAverageMock);
29+
30+
var kraken = new MockRateProvider();
31+
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("BTC_USD"), new BidAsk(0.1m)));
32+
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_USD"), new BidAsk(0.1m)));
33+
kraken.ExchangeRates.Add(new PairRate(CurrencyPair.Parse("XMR_BTC"), new BidAsk(0.1m)));
34+
rateProviderFactory.Providers.Add("kraken", kraken);
35+
}
1536
await s.RegisterNewUser(true);
16-
await s.CreateNewStore();
37+
await s.CreateNewStore(preferredExchange: "Kraken");
1738
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
1839
await s.Page.CheckAsync("#Enabled");
1940
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "2");
2041
await s.Page.ClickAsync("#SaveButton");
2142
var classList = await s.Page.Locator("svg.icon-checkmark").GetAttributeAsync("class");
2243
Assert.Contains("text-success", classList);
44+
45+
// Set rate provider
46+
await s.Page.Locator("#StoreNav-General").ClickAsync();
47+
await s.Page.Locator("#mainNav #StoreNav-Rates").ClickAsync();
48+
await s.Page.FillAsync("#DefaultCurrencyPairs", "BTC_USD,XMR_USD,XMR_BTC");
49+
await s.Page.SelectOptionAsync("#PrimarySource_PreferredExchange", "kraken");
50+
await s.Page.Locator("#page-primary").ClickAsync();
51+
52+
// Generate a new invoice
53+
await s.Page.Locator("a.nav-link[href*='invoices']").ClickAsync();
54+
await s.Page.Locator("#page-primary").ClickAsync();
55+
await s.Page.FillAsync("#Amount", "4.20");
56+
await s.Page.FillAsync("#BuyerEmail", "monero@monero.com");
57+
await s.Page.Locator("#page-primary").ClickAsync();
58+
59+
// View the invoice
60+
await s.Page.Locator("a.invoice-checkout-link").ClickAsync();
61+
await s.Page.ClickAsync("#DetailsToggle");
62+
63+
// Verify the total fiat amount is $4.20
64+
var totalFiat = await s.Page.Locator("#PaymentDetails-TotalFiat dd.clipboard-button").InnerTextAsync();
65+
Assert.Equal("$4.20", totalFiat);
66+
67+
await s.Page.GoBackAsync();
68+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
69+
70+
// Create a new account label
71+
await s.Page.FillAsync("#NewAccountLabel", "tst-account");
72+
await s.Page.ClickAsync("button[name='command'][value='add-account']");
73+
74+
// Select primary Account Index
75+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
76+
await s.Page.SelectOptionAsync("#AccountIndex", "1");
77+
await s.Page.ClickAsync("#SaveButton");
78+
79+
// Verify selected account index
80+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
81+
var selectedValue = await s.Page.Locator("#AccountIndex").InputValueAsync();
82+
Assert.Equal("1", selectedValue);
83+
84+
// Select confirmation time to 0
85+
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "3");
86+
await s.Page.ClickAsync("#SaveButton");
87+
88+
2389
}
2490
}

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ Visual Studio does not support this feature.
132132
When debugging in regtest, BTCPay Server will automatically create an configure two wallets. (cashcow and merchant)
133133
You can trigger payments or mine blocks on the invoice's checkout page.
134134

135+
## 6. Integration Tests without Docker
136+
To run the integration test outside Docker and have the Monero plugin available, you need to build the plugin and copy its output to the BTCPayServer plugins directory used at runtime.
137+
138+
Steps:
139+
140+
Build the Monero plugin:
141+
```bash
142+
dotnet build Plugins/Monero/BTCPayServer.Plugins.Monero.csproj --configuration Release
143+
```
144+
145+
Copy the plugin DLL and files to the BTCPayServer plugins directory: By default, BTCPayServer looks for plugins in ~/.btcpayserver/Plugins/BTCPayServer.Plugins.Monero/ (as in the Dockerfile).
146+
147+
```bash
148+
mkdir -p ~/.btcpayserver/Plugins/BTCPayServer.Plugins.Monero/
149+
cp -f Plugins/Monero/bin/Release/net8.0/* ~/.btcpayserver/Plugins/BTCPayServer.Plugins.Monero/
150+
```
151+
152+
Run your integration test.
153+
154+
Remember you will need to copy the plugin files every time you build the plugin, or you can automate this with a script.
155+
156+
You can automate copying the plugin output to the BTCPayServer plugins directory by adding a PostBuild target to your BTCPayServer.Plugins.Monero.csproj. This will copy the files after every build.
157+
158+
Add the following to the end of your BTCPayServer.Plugins.Monero.csproj (just before the closing </Project> tag):
159+
```bash
160+
<Target Name="CopyPluginToBTCPayServerPlugins" AfterTargets="Build">
161+
<PropertyGroup>
162+
<PluginOutputDir>$(UserProfile)/.btcpayserver/Plugins/BTCPayServer.Plugins.Monero/</PluginOutputDir>
163+
</PropertyGroup>
164+
<MakeDir Directories="$(PluginOutputDir)" />
165+
<Copy SourceFiles="@(BuiltOutputProjectGroupKeyOutput)" DestinationFolder="$(PluginOutputDir)" SkipUnchangedFiles="true" />
166+
<Copy SourceFiles="@(Content)" DestinationFolder="$(PluginOutputDir)" SkipUnchangedFiles="true" Condition="Exists('%(Content.Identity)')" />
167+
</Target>
168+
```
169+
170+
To run the integration tests in isolation via CLI, you can use the following command:
171+
```bash
172+
dotnet test --filter FullyQualifiedName=BTCPayServer.Plugins.IntegrationTests.Monero.MoneroPluginIntegrationTest.EnableMoneroPluginSuccessfully --no-build --framework net8.0 --logger "console;verbosity=detailed"
173+
```
174+
135175
## About docker-compose deployment
136176

137177
BTCPay Server maintains its own [deployment stack project](https://github.com/btcpayserver/btcpayserver-docker) to enable users to easily update or deploy additional infrastructure (such as nodes).

0 commit comments

Comments
 (0)