Rely on docker for tests, move everything to the root

This commit is contained in:
NicolasDorier
2017-10-03 00:41:03 +09:00
parent 42b3b9eec0
commit 61b37f87dc
15 changed files with 79 additions and 356 deletions

View File

@@ -1,6 +1,6 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs) # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/ **/[Bb]in/
[Oo]bj/ **/[Oo]bj/
node_modules/ node_modules/
dist/ dist/
@@ -121,4 +121,3 @@ bower_components
output output
.vs .vs
BTCPayServer.Tests/

View File

@@ -8,7 +8,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170720-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170720-02" />
<PackageReference Include="NBitcoin.TestFramework" Version="1.4.4" />
<PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup> </ItemGroup>
@@ -17,4 +16,13 @@
<ProjectReference Include="..\BTCPayServer\BTCPayServer.csproj" /> <ProjectReference Include="..\BTCPayServer\BTCPayServer.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update=".dockerignore">
<DependentUpon>Dockerfile</DependentUpon>
</None>
<None Update="docker-compose.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NBitcoin; using NBitcoin;
using NBitcoin.Tests;
using NBXplorer; using NBXplorer;
using NBXplorer.DerivationStrategy; using NBXplorer.DerivationStrategy;
using System; using System;
@@ -59,6 +58,11 @@ namespace BTCPayServer.Tests
get; set; get; set;
} }
public string Postgres
{
get; set;
}
IWebHost _Host; IWebHost _Host;
public void Start() public void Start()
{ {
@@ -73,6 +77,8 @@ namespace BTCPayServer.Tests
config.AppendLine($"explorer.url={NBXplorerUri.AbsoluteUri}"); config.AppendLine($"explorer.url={NBXplorerUri.AbsoluteUri}");
config.AppendLine($"explorer.cookiefile={CookieFile}"); config.AppendLine($"explorer.cookiefile={CookieFile}");
config.AppendLine($"hdpubkey={HDPrivateKey.Neuter().ToString(Network.RegTest)}"); config.AppendLine($"hdpubkey={HDPrivateKey.Neuter().ToString(Network.RegTest)}");
if(Postgres != null)
config.AppendLine($"postgres=" + Postgres);
File.WriteAllText(Path.Combine(_Directory, "settings.config"), config.ToString()); File.WriteAllText(Path.Combine(_Directory, "settings.config"), config.ToString());
ServerUri = new Uri("http://127.0.0.1:" + port + "/"); ServerUri = new Uri("http://127.0.0.1:" + port + "/");

View File

@@ -0,0 +1,12 @@
FROM microsoft/dotnet:2.0.0-sdk
WORKDIR /app
# caches restore result by copying csproj file separately
COPY BTCPayServer.Tests/BTCPayServer.Tests.csproj BTCPayServer.Tests/BTCPayServer.Tests.csproj
COPY BTCPayServer/BTCPayServer.csproj BTCPayServer/BTCPayServer.csproj
WORKDIR /app/BTCPayServer.Tests
RUN dotnet restore
# copies the rest of your code
COPY . ../.
ENTRYPOINT ["dotnet", "test"]

View File

@@ -1,112 +0,0 @@
using NBitcoin;
using NBitcoin.Tests;
using NBXplorer.DerivationStrategy;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using Xunit;
namespace BTCPayServer.Tests
{
public class NBXplorerTester : IDisposable
{
private string _Directory;
public NBXplorerTester(string scope)
{
if(scope == null)
throw new ArgumentNullException(nameof(scope));
this._Directory = scope;
}
Process _Process;
public CoreNode Node
{
get; set;
}
public void Start()
{
ProcessLauncher launcher = new ProcessLauncher();
launcher.GoTo("Repositories", true);
if(!launcher.GoTo(new[] { "nxbplorer", "NBXplorer" }))
{
launcher.Run("git", "clone https://github.com/dgarage/NBXplorer nxbplorer");
Assert.True(launcher.GoTo(new[] { "nxbplorer", "NBXplorer" }), "Could not clone nxbplorer");
}
launcher.PushDirectory();
if(!launcher.GoTo(new[] { "bin", "Release", "netcoreapp2.0" }) || !launcher.Exists("NBXplorer.dll"))
{
launcher.PopDirectory();
launcher.Run("git", "pull");
launcher.Run("git", "checkout master");
try
{
//Need to do that or VS insist in adding this repo as submodules :/
Utils.DeleteDirectory(Path.GetFullPath(Path.Combine(launcher.CurrentDirectory, "..", ".git")));
}
catch { }
launcher.Run("dotnet", "build /p:Configuration=Release");
Assert.True(launcher.GoTo(new[] { "bin", "Release", "netcoreapp2.0" }), "Could not build NBXplorer");
launcher.AssertExists("NBXplorer.dll");
}
var port = Utils.FreeTcpPort();
var launcher2 = new ProcessLauncher();
launcher2.GoTo(_Directory, true);
launcher2.GoTo("nbxplorer-datadir", true);
StringBuilder config = new StringBuilder();
config.AppendLine($"regtest=1");
config.AppendLine($"port={port}");
config.AppendLine($"rpc.url={Node.RPCUri.AbsoluteUri}");
config.AppendLine($"rpc.auth={Node.AuthenticationString}");
config.AppendLine($"node.endpoint={Node.NodeEndpoint.Address}:{Node.NodeEndpoint.Port}");
File.WriteAllText(Path.Combine(launcher2.CurrentDirectory, "settings.config"), config.ToString());
_Process = launcher.Start("dotnet", $"NBXplorer.dll --datadir \"{launcher2.CurrentDirectory}\"");
ExplorerClient = new NBXplorer.ExplorerClient(Node.Network, new Uri($"http://127.0.0.1:{port}/"));
CookieFile = Path.Combine(launcher2.CurrentDirectory, ".cookie");
File.Create(CookieFile).Close(); //Will be wipedout when the client starts
ExplorerClient.SetCookieAuth(CookieFile);
try
{
var cancellationSource = new CancellationTokenSource(10000);
ExplorerClient.WaitServerStarted(cancellationSource.Token);
}
catch(OperationCanceledException)
{
Assert.False(_Process.HasExited, "NBXplorer failed to launch");
throw;
}
}
public NBXplorer.ExplorerClient ExplorerClient
{
get; set;
}
public string CookieFile
{
get;
set;
}
public static NBXplorerTester Create([CallerMemberNameAttribute] string scope = null)
{
return new NBXplorerTester(scope);
}
public void Dispose()
{
if(_Process != null && !_Process.HasExited)
_Process.Kill();
}
}
}

View File

@@ -2,10 +2,12 @@
using BTCPayServer.Models.AccountViewModels; using BTCPayServer.Models.AccountViewModels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NBitcoin; using NBitcoin;
using NBitcoin.Tests; using NBitcoin.RPC;
using NBitpayClient; using NBitpayClient;
using NBXplorer;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
@@ -21,8 +23,6 @@ namespace BTCPayServer.Tests
} }
string _Directory; string _Directory;
NodeBuilder _Builder;
public ServerTester(string scope) public ServerTester(string scope)
{ {
_Directory = scope; _Directory = scope;
@@ -34,42 +34,45 @@ namespace BTCPayServer.Tests
Utils.DeleteDirectory(_Directory); Utils.DeleteDirectory(_Directory);
if(!Directory.Exists(_Directory)) if(!Directory.Exists(_Directory))
Directory.CreateDirectory(_Directory); Directory.CreateDirectory(_Directory);
_Builder = NodeBuilder.Create(_Directory, "0.14.2");
ExplorerNode = _Builder.CreateNode(false);
ExplorerNode.WhiteBind = true;
ExplorerNode.Start();
ExplorerNode.CreateRPCClient().Generate(101);
ExplorerTester = NBXplorerTester.Create(Path.Combine(_Directory, "explorer"));
ExplorerTester.Node = ExplorerNode;
ExplorerTester.Start();
ExplorerNode = new RPCClient(RPCCredentialString.Parse(GetEnvironment("TESTS_RPCCONNECTION", "server=http://127.0.0.1:43782;ceiwHEbqWI83:DwubwWsoo3")), Network);
ExplorerClient = new ExplorerClient(Network, new Uri(GetEnvironment("TESTS_NBXPLORERURL", "http://127.0.0.1:32838/")));
PayTester = new BTCPayServerTester(Path.Combine(_Directory, "pay")) PayTester = new BTCPayServerTester(Path.Combine(_Directory, "pay"))
{ {
NBXplorerUri = ExplorerTester.ExplorerClient.Address, NBXplorerUri = ExplorerClient.Address,
CookieFile = ExplorerTester.CookieFile Postgres = GetEnvironment("TESTS_POSTGRES", "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver")
}; };
PayTester.Start(); PayTester.Start();
} }
private string GetEnvironment(string variable, string defaultValue)
{
var var = Environment.GetEnvironmentVariable(variable);
return String.IsNullOrEmpty(var) ? defaultValue : var;
}
public TestAccount CreateAccount() public TestAccount CreateAccount()
{ {
return new TestAccount(this); return new TestAccount(this);
} }
public CoreNode ExplorerNode public RPCClient ExplorerNode
{ {
get; set; get; set;
} }
public ExplorerClient ExplorerClient
{
get; set;
}
public BTCPayServerTester PayTester public BTCPayServerTester PayTester
{ {
get; set; get; set;
} }
public NBXplorerTester ExplorerTester
{
get; set;
}
public Network Network public Network Network
{ {
get; get;
@@ -80,10 +83,6 @@ namespace BTCPayServer.Tests
{ {
if(PayTester != null) if(PayTester != null)
PayTester.Dispose(); PayTester.Dispose();
if(ExplorerTester != null)
ExplorerTester.Dispose();
if(_Builder != null)
_Builder.Dispose();
} }
} }
} }

View File

@@ -33,7 +33,7 @@ namespace BTCPayServer.Tests
var account = parent.PayTester.GetController<AccountController>(); var account = parent.PayTester.GetController<AccountController>();
await account.Register(new RegisterViewModel() await account.Register(new RegisterViewModel()
{ {
Email = "Bob@toto.com", Email = Guid.NewGuid() + "@toto.com",
ConfirmPassword = "Kitten0@", ConfirmPassword = "Kitten0@",
Password = "Kitten0@", Password = "Kitten0@",
}); });

View File

@@ -85,7 +85,7 @@ namespace BTCPayServer.Tests
Transaction tx = new Transaction(); Transaction tx = new Transaction();
tx.Outputs.AddRange(request.Details.Outputs.Select(o => new TxOut(o.Amount, o.Script))); tx.Outputs.AddRange(request.Details.Outputs.Select(o => new TxOut(o.Amount, o.Script)));
var cashCow = tester.ExplorerNode.CreateRPCClient(); var cashCow = tester.ExplorerNode;
tx = cashCow.FundRawTransaction(tx).Transaction; tx = cashCow.FundRawTransaction(tx).Transaction;
tx = cashCow.SignRawTransaction(tx); tx = cashCow.SignRawTransaction(tx);
@@ -125,7 +125,7 @@ namespace BTCPayServer.Tests
FullNotifications = true FullNotifications = true
}); });
BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21); BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21);
tester.ExplorerNode.CreateRPCClient().SendToAddress(url.Address, url.Amount); tester.ExplorerNode.SendToAddress(url.Address, url.Amount);
callbackServer.ProcessNextRequest((ctx) => callbackServer.ProcessNextRequest((ctx) =>
{ {
var ipn = new StreamReader(ctx.Request.Body).ReadToEnd(); var ipn = new StreamReader(ctx.Request.Body).ReadToEnd();
@@ -193,7 +193,7 @@ namespace BTCPayServer.Tests
var rate = user.BitPay.GetRates(); var rate = user.BitPay.GetRates();
var cashCow = tester.ExplorerNode.CreateRPCClient(); var cashCow = tester.ExplorerNode;
var invoiceAddress = BitcoinAddress.Create(invoice.BitcoinAddress, cashCow.Network); var invoiceAddress = BitcoinAddress.Create(invoice.BitcoinAddress, cashCow.Network);
cashCow.SendToAddress(invoiceAddress, firstPayment); cashCow.SendToAddress(invoiceAddress, firstPayment);

View File

@@ -2,25 +2,21 @@ version: "3"
services: services:
btcpayserver: tests:
ports:
- 8080:49392
expose:
- "49392"
build: build:
context: . context: ..
dockerfile: DockerFile dockerfile: BTCPayServer.Tests/Dockerfile
environment: environment:
BTCPAY_POSTGRES: "User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver" TESTS_RPCCONNECTION: server=http://bitcoind:43782;ceiwHEbqWI83:DwubwWsoo3
BTCPAY_NETWORK: regtest TESTS_NBXPLORERURL: http://nbxplorer:32838/
BTCPAY_EXPLORERURL: http://nbxplorer:32838/ TESTS_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver
BTCPAY_BIND: 0.0.0.0:49392
links: links:
- nbxplorer - nbxplorer
- postgres
nbxplorer: nbxplorer:
image: nicolasdorier/nbxplorer:1.0.0.12 image: nicolasdorier/nbxplorer:1.0.0.12
ports:
- "32838:32838"
expose: expose:
- "32838" - "32838"
environment: environment:
@@ -28,21 +24,27 @@ services:
NBXPLORER_RPCURL: http://bitcoind:43782/ NBXPLORER_RPCURL: http://bitcoind:43782/
NBXPLORER_RPCUSER: ceiwHEbqWI83 NBXPLORER_RPCUSER: ceiwHEbqWI83
NBXPLORER_RPCPASSWORD: DwubwWsoo3 NBXPLORER_RPCPASSWORD: DwubwWsoo3
NBXPLORER_NODEENDPOINT: bitcoind:8332 NBXPLORER_NODEENDPOINT: bitcoind:39388
NBXPLORER_BIND: 0.0.0.0:32838 NBXPLORER_BIND: 0.0.0.0:32838
NBXPLORER_NOAUTH: 1 NBXPLORER_NOAUTH: 1
links: links:
- bitcoind - bitcoind
- postgres
bitcoind: bitcoind:
image: nicolasdorier/docker-bitcoin:0.15.0.1 image: nicolasdorier/docker-bitcoin:0.15.0.1
ports:
- "43782:43782"
- "39388:39388"
environment: environment:
BITCOIN_EXTRA_ARGS: "regtest=1\nrpcport=43782\nport=8332" BITCOIN_EXTRA_ARGS: "regtest=1\nrpcport=43782\nport=39388\nwhitelist=0.0.0.0/0"
BITCOIN_RPC_USER: ceiwHEbqWI83 BITCOIN_RPC_USER: ceiwHEbqWI83
BITCOIN_RPC_PASSWORD: DwubwWsoo3 BITCOIN_RPC_PASSWORD: DwubwWsoo3
expose: expose:
- "43782" - "43782"
- "8332" - "39388"
postgres: postgres:
image: postgres:9.6.5 image: postgres:9.6.5
ports:
- "39372:5432"

View File

@@ -1,123 +0,0 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
node_modules/
dist/
# mstest test results
TestResults
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
packages
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
src/Rapporteringsregisteret.Web/assets/less/*.css
MetricResults/
*.sln.ide/
_configs/
# vnext stuff
bower_components
output
.vs

View File

@@ -38,7 +38,7 @@ namespace BTCPayServer.Configuration
if(!Explorer.SetCookieAuth(opts.CookieFile)) if(!Explorer.SetCookieAuth(opts.CookieFile))
Explorer.SetNoAuth(); Explorer.SetNoAuth();
CancellationTokenSource cts = new CancellationTokenSource(10000); CancellationTokenSource cts = new CancellationTokenSource(30000);
try try
{ {
Logs.Configuration.LogInformation("Trying to connect to explorer " + Explorer.Address.AbsoluteUri); Logs.Configuration.LogInformation("Trying to connect to explorer " + Explorer.Address.AbsoluteUri);

View File

@@ -1,18 +0,0 @@
FROM microsoft/aspnetcore-build AS builder
WORKDIR /source
# caches restore result by copying csproj file separately
COPY *.csproj .
RUN dotnet restore
# copies the rest of your code
COPY . .
RUN dotnet publish --output /app/ --configuration Release
FROM microsoft/aspnetcore:2.0.0
WORKDIR /app
RUN mkdir /datadir
ENV BTCPAY_DATADIR=/datadir
VOLUME /datadir
COPY --from=builder "/app" .
ENTRYPOINT ["dotnet", "BTCPayServer.dll"]

View File

@@ -1,2 +0,0 @@
docker-compose -f docker-compose.regtest.yml down
docker-compose -f docker-compose.regtest.yml up --force-recreate --build

View File

@@ -1,10 +1,10 @@
FROM microsoft/aspnetcore-build AS builder FROM microsoft/aspnetcore-build AS builder
WORKDIR /source WORKDIR /source
COPY BTCPayServer/BTCPayServer.csproj BTCPayServer/BTCPayServer.csproj COPY BTCPayServer/BTCPayServer.csproj BTCPayServer.csproj
# Cache some dependencies # Cache some dependencies
RUN cd BTCPayServer && dotnet restore && cd .. RUN dotnet restore
COPY . . COPY BTCPayServer/. .
RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release RUN dotnet publish --output /app/ --configuration Release
FROM microsoft/aspnetcore:2.0.0 FROM microsoft/aspnetcore:2.0.0
WORKDIR /app WORKDIR /app

View File

@@ -1,48 +0,0 @@
version: "3"
services:
btcpayserver:
ports:
- 8080:49392
expose:
- "49392"
build:
context: .
dockerfile: DockerFile
environment:
BTCPAY_POSTGRES: "User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver"
BTCPAY_NETWORK: regtest
BTCPAY_EXPLORERURL: http://nbxplorer:32838/
BTCPAY_BIND: 0.0.0.0:49392
links:
- nbxplorer
- postgres
nbxplorer:
image: nicolasdorier/nbxplorer:1.0.0.12
expose:
- "32838"
environment:
NBXPLORER_NETWORK: regtest
NBXPLORER_RPCURL: http://bitcoind:43782/
NBXPLORER_RPCUSER: ceiwHEbqWI83
NBXPLORER_RPCPASSWORD: DwubwWsoo3
NBXPLORER_NODEENDPOINT: bitcoind:8332
NBXPLORER_BIND: 0.0.0.0:32838
NBXPLORER_NOAUTH: 1
links:
- bitcoind
bitcoind:
image: nicolasdorier/bitcoin:0.15.0.1
environment:
BITCOIN_EXTRA_ARGS: "regtest=1\nrpcport=43782\nport=8332"
BITCOIN_RPC_USER: ceiwHEbqWI83
BITCOIN_RPC_PASSWORD: DwubwWsoo3
expose:
- "43782"
- "8332"
postgres:
image: postgres:9.6.5