mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Pluginify BTCPayNetworkProvider (#5331)
This commit is contained in:
@@ -3,8 +3,18 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using BTCPayServer.Hosting;
|
||||
using BTCPayServer.Logging;
|
||||
using BTCPayServer.Plugins.Bitcoin;
|
||||
using BTCPayServer.Plugins;
|
||||
using BTCPayServer.Tests.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NBXplorer;
|
||||
using Xunit.Abstractions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Memory;
|
||||
using NBitcoin;
|
||||
|
||||
namespace BTCPayServer.Tests
|
||||
{
|
||||
@@ -15,7 +25,53 @@ namespace BTCPayServer.Tests
|
||||
TestLogs = new XUnitLog(helper) { Name = "Tests" };
|
||||
TestLogProvider = new XUnitLogProvider(helper);
|
||||
BTCPayLogs = new BTCPayServer.Logging.Logs();
|
||||
BTCPayLogs.Configure(new BTCPayServer.Logging.FuncLoggerFactory((n) => new XUnitLog(helper) { Name = n }));
|
||||
LoggerFactory = new BTCPayServer.Logging.FuncLoggerFactory((n) => new XUnitLog(helper) { Name = n });
|
||||
BTCPayLogs.Configure(LoggerFactory);
|
||||
}
|
||||
|
||||
public BTCPayNetworkProvider CreateNetworkProvider(ChainName chainName)
|
||||
{
|
||||
var conf = new ConfigurationRoot(new List<IConfigurationProvider>()
|
||||
{
|
||||
new MemoryConfigurationProvider(new MemoryConfigurationSource()
|
||||
{
|
||||
InitialData = new[] {
|
||||
new KeyValuePair<string, string>("chains", "*"),
|
||||
new KeyValuePair<string, string>("network", chainName.ToString())
|
||||
}
|
||||
})
|
||||
});
|
||||
return CreateNetworkProvider(conf);
|
||||
}
|
||||
public BTCPayNetworkProvider CreateNetworkProvider(IConfiguration conf = null)
|
||||
{
|
||||
conf ??= new ConfigurationRoot(new List<IConfigurationProvider>()
|
||||
{
|
||||
new MemoryConfigurationProvider(new MemoryConfigurationSource()
|
||||
{
|
||||
InitialData = new[] {
|
||||
new KeyValuePair<string, string>("chains", "*"),
|
||||
new KeyValuePair<string, string>("network", "regtest")
|
||||
}
|
||||
})
|
||||
});
|
||||
var bootstrap = Startup.CreateBootstrap(conf);
|
||||
var services = new PluginServiceCollection(new ServiceCollection(), bootstrap);
|
||||
var plugins = new List<BaseBTCPayServerPlugin>() { new BitcoinPlugin() };
|
||||
#if ALTCOINS
|
||||
plugins.Add(new BTCPayServer.Plugins.Altcoins.AltcoinsPlugin());
|
||||
#endif
|
||||
foreach (var p in plugins)
|
||||
{
|
||||
p.Execute(services);
|
||||
}
|
||||
services.AddSingleton(services.BootstrapServices.GetRequiredService<SelectedChains>());
|
||||
services.AddSingleton(services.BootstrapServices.GetRequiredService<NBXplorerNetworkProvider>());
|
||||
services.AddSingleton(services.BootstrapServices.GetRequiredService<Logs>());
|
||||
services.AddSingleton(services.BootstrapServices.GetRequiredService<IConfiguration>());
|
||||
services.AddSingleton<BTCPayNetworkProvider>();
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
return serviceProvider.GetService<BTCPayNetworkProvider>();
|
||||
}
|
||||
public ILog TestLogs
|
||||
{
|
||||
@@ -26,14 +82,15 @@ namespace BTCPayServer.Tests
|
||||
get;
|
||||
}
|
||||
public BTCPayServer.Logging.Logs BTCPayLogs { get; }
|
||||
public FuncLoggerFactory LoggerFactory { get; }
|
||||
|
||||
public ServerTester CreateServerTester([CallerMemberNameAttribute] string scope = null, bool newDb = false)
|
||||
{
|
||||
return new ServerTester(scope, newDb, TestLogs, TestLogProvider);
|
||||
return new ServerTester(scope, newDb, TestLogs, TestLogProvider, CreateNetworkProvider());
|
||||
}
|
||||
public SeleniumTester CreateSeleniumTester([CallerMemberNameAttribute] string scope = null, bool newDb = false)
|
||||
{
|
||||
return new SeleniumTester() { Server = new ServerTester(scope, newDb, TestLogs, TestLogProvider) };
|
||||
return new SeleniumTester() { Server = new ServerTester(scope, newDb, TestLogs, TestLogProvider, CreateNetworkProvider()) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user