Skip to content

Commit 23a9a22

Browse files
Test invoice creation
Cleanup Update MoneroPluginUITest.cs Remove whitespace
1 parent e9ecf24 commit 23a9a22

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-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: 66 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,75 @@ 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+
}
36+
1537
await s.RegisterNewUser(true);
16-
await s.CreateNewStore();
38+
await s.CreateNewStore(preferredExchange: "Kraken");
1739
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
1840
await s.Page.CheckAsync("#Enabled");
1941
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "2");
2042
await s.Page.ClickAsync("#SaveButton");
2143
var classList = await s.Page.Locator("svg.icon-checkmark").GetAttributeAsync("class");
2244
Assert.Contains("text-success", classList);
45+
46+
// Set rate provider
47+
await s.Page.Locator("#StoreNav-General").ClickAsync();
48+
await s.Page.Locator("#mainNav #StoreNav-Rates").ClickAsync();
49+
await s.Page.FillAsync("#DefaultCurrencyPairs", "BTC_USD,XMR_USD,XMR_BTC");
50+
await s.Page.SelectOptionAsync("#PrimarySource_PreferredExchange", "kraken");
51+
await s.Page.Locator("#page-primary").ClickAsync();
52+
53+
// Generate a new invoice
54+
await s.Page.Locator("a.nav-link[href*='invoices']").ClickAsync();
55+
await s.Page.Locator("#page-primary").ClickAsync();
56+
await s.Page.FillAsync("#Amount", "4.20");
57+
await s.Page.FillAsync("#BuyerEmail", "monero@monero.com");
58+
await s.Page.Locator("#page-primary").ClickAsync();
59+
60+
// View the invoice
61+
await s.Page.Locator("a.invoice-checkout-link").ClickAsync();
62+
await s.Page.ClickAsync("#DetailsToggle");
63+
64+
// Verify the total fiat amount is $4.20
65+
var totalFiat = await s.Page.Locator("#PaymentDetails-TotalFiat dd.clipboard-button").InnerTextAsync();
66+
Assert.Equal("$4.20", totalFiat);
67+
68+
await s.Page.GoBackAsync();
69+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
70+
71+
// Create a new account label
72+
await s.Page.FillAsync("#NewAccountLabel", "tst-account");
73+
await s.Page.ClickAsync("button[name='command'][value='add-account']");
74+
75+
// Select primary Account Index
76+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
77+
await s.Page.SelectOptionAsync("#AccountIndex", "1");
78+
await s.Page.ClickAsync("#SaveButton");
79+
80+
// Verify selected account index
81+
await s.Page.Locator("a.nav-link[href*='monerolike/XMR']").ClickAsync();
82+
var selectedValue = await s.Page.Locator("#AccountIndex").InputValueAsync();
83+
Assert.Equal("1", selectedValue);
84+
85+
// Select confirmation time to 0
86+
await s.Page.SelectOptionAsync("#SettlementConfirmationThresholdChoice", "3");
87+
await s.Page.ClickAsync("#SaveButton");
2388
}
2489
}

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)