Skip to content

Commit

Permalink
feat(justfile): add context to drop-db command to specify Application…
Browse files Browse the repository at this point in the history
…DbContext for clarity (#360)

feat(Dockerfile, NodeGuard.csproj): upgrade .NET version from 7.0 to 8.0 for better performance and features
feat(NodeGuard.csproj): update package versions to their latest stable versions for improved functionality and security
feat(Program.cs): refactor code for better readability and maintainability
feat(Program.cs): add NpgsqlDataSourceBuilder to enable dynamic JSON in PostgreSQL
fix(NodeChannelSubscribeJobTests.cs): change Assert.ThrowsAsync to Assert.ThrowsAnyAsync to catch any type of exceptions

feat(NodeGuard.Tests.csproj): upgrade project to .NET 8.0 for improved performance and features
chore(NodeGuard.Tests.csproj): update all package references to their latest versions for better stability and new features
  • Loading branch information
Jossec101 committed Dec 20, 2023
1 parent 77fb910 commit 8f98b6d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set fallback := true

drop-db:
cd src && dotnet ef database drop -f
cd src && dotnet ef database drop -f --context ApplicationDbContext
add-license-cs:
go install github.com/fbiville/headache/cmd/headache@latest
headache --configuration ./configuration-cs.json
Expand Down
4 changes: 2 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["src/NodeGuard.csproj", "."]
RUN dotnet restore "./NodeGuard.csproj"
Expand Down
38 changes: 19 additions & 19 deletions src/NodeGuard.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-NodeGuard-66F1BF9B-21F9-40C4-8380-C86E94E1BCAC</UserSecretsId>
Expand All @@ -25,29 +25,29 @@
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.2.4" />
<PackageReference Include="Grpc.AspNetCore" Version="2.59.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="7.0.0.2" />
<PackageReference Include="NBitcoin" Version="7.0.30" />
<PackageReference Include="NBXplorer.Client" Version="4.2.5" />
<PackageReference Include="NBitcoin" Version="7.0.32" />
<PackageReference Include="NBXplorer.Client" Version="4.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Blazorise.DataGrid" Version="1.2.4" />
<PackageReference Include="OneSignalApi" Version="2.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OneSignalApi" Version="2.0.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.7" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
<PackageReference Include="Quartz" Version="3.8.0" />
Expand All @@ -56,7 +56,7 @@
<PackageReference Include="Blazorise.SpinKit" Version="1.2.4" />
<PackageReference Include="RestSharp" Version="106.13.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
</ItemGroup>

Expand Down
36 changes: 25 additions & 11 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
using NodeGuard.Helpers;
using NodeGuard.Rpc;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Npgsql;
using Quartz.AspNetCore;

namespace NodeGuard
Expand All @@ -57,15 +58,15 @@ public static void Main(string[] args)
var builder = WebApplication.CreateBuilder(args);

var jsonFormatter = new LowerCaseJsonFormatter();

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.Enrich.With(new DatadogLogEnricher())
.WriteTo.Console(jsonFormatter)
.CreateLogger();

builder.Host.UseSerilog();

//Add services to the container.
Expand Down Expand Up @@ -105,7 +106,8 @@ public static void Main(string[] args)
builder.Services.AddTransient<IWalletRepository, WalletRepository>();
builder.Services.AddTransient<IInternalWalletRepository, InternalWalletRepository>();
builder.Services.AddTransient<IFMUTXORepository, FUTXORepository>();
builder.Services.AddTransient<IWalletWithdrawalRequestPsbtRepository, WalletWithdrawalRequestPsbtRepository>();
builder.Services
.AddTransient<IWalletWithdrawalRequestPsbtRepository, WalletWithdrawalRequestPsbtRepository>();
builder.Services.AddTransient<IWalletWithdrawalRequestRepository, WalletWithdrawalRequestRepository>();
builder.Services.AddTransient<IRemoteSignerService, RemoteSignerServiceService>();
builder.Services.AddTransient<ILiquidityRuleRepository, LiquidityRuleRepository>();
Expand All @@ -125,19 +127,26 @@ public static void Main(string[] args)
builder.Services.AddTransient<INBXplorerService, NBXplorerService>();

//DbContext
var dataSourceBuilder = new NpgsqlDataSourceBuilder(Constants.POSTGRES_CONNECTIONSTRING);
dataSourceBuilder.EnableDynamicJson();

var npgsqlDataSource = dataSourceBuilder.Build();
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
//options.EnableSensitiveDataLogging();
//options.EnableDetailedErrors();
options.UseNpgsql(Constants.POSTGRES_CONNECTIONSTRING, options =>
options.UseNpgsql(npgsqlDataSource, npgsqlDbContextOptionsBuilder =>
{
options.UseQuerySplittingBehavior(QuerySplittingBehavior
npgsqlDbContextOptionsBuilder.UseQuerySplittingBehavior(QuerySplittingBehavior
.SingleQuery); // Slower but integrity is ensured
});
}, ServiceLifetime.Transient);

//DataProtection
builder.Services.AddDbContext<DataProtectionKeysContext>(options => options.UseNpgsql(Constants.POSTGRES_CONNECTIONSTRING));
builder.Services.AddDbContext<DataProtectionKeysContext>(options =>
options.UseNpgsql(Constants.POSTGRES_CONNECTIONSTRING));
builder.Services.AddDataProtection()
.PersistKeysToDbContext<DataProtectionKeysContext>()
.SetApplicationName("NodeGuard");
Expand All @@ -158,8 +167,9 @@ public static void Main(string[] args)
// Setup a HTTP/2 endpoint without TLS.
options.ListenAnyIP(50051, o => o.Protocols =
HttpProtocols.Http2);
options.ListenAnyIP(int.Parse(Environment.GetEnvironmentVariable("HTTP1_LISTEN_PORT") ?? "80"), o => o.Protocols =
HttpProtocols.Http1);
options.ListenAnyIP(int.Parse(Environment.GetEnvironmentVariable("HTTP1_LISTEN_PORT") ?? "80"), o =>
o.Protocols =
HttpProtocols.Http1);
});

//DBContextFactory
Expand Down Expand Up @@ -207,8 +217,12 @@ public static void Main(string[] args)
q.AddTrigger(opts =>
{
opts.ForJob(nameof(SweepAllNodesWalletsJob)).WithIdentity($"{nameof(SweepAllNodesWalletsJob)}Trigger")
.StartNow().WithSimpleSchedule(scheduleBuilder => { scheduleBuilder.WithIntervalInMinutes(1).RepeatForever(); });
opts.ForJob(nameof(SweepAllNodesWalletsJob))
.WithIdentity($"{nameof(SweepAllNodesWalletsJob)}Trigger")
.StartNow().WithSimpleSchedule(scheduleBuilder =>
{
scheduleBuilder.WithIntervalInMinutes(1).RepeatForever();
});
});
//Monitor Withdrawals Job
Expand Down
2 changes: 1 addition & 1 deletion test/NodeGuard.Tests/Jobs/NodeChannelSubscribeJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task NodeUpdateManagement_ThrowsException_WhenCloseAddressIsEmpty()
};

// Act + Assert
Assert.ThrowsAsync<Exception>(async () => await _nodeUpdateManager.NodeUpdateManagement(channelEventUpdate, new Node()));
await Assert.ThrowsAnyAsync<Exception>(async () => await _nodeUpdateManager.NodeUpdateManagement(channelEventUpdate, new Node()));
}

[Fact]
Expand Down
22 changes: 11 additions & 11 deletions test/NodeGuard.Tests/NodeGuard.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -12,28 +12,28 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Grpc.Core.Api" Version="2.59.0" />
<PackageReference Include="Grpc.Core.Testing" Version="2.46.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Moq.EntityFrameworkCore" Version="7.0.0.2" />
<PackageReference Include="NBitcoin.TestFramework" Version="3.0.22" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="NBitcoin.TestFramework" Version="3.0.24" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="XunitXml.TestLogger" Version="3.1.11" />
<PackageReference Include="XunitXml.TestLogger" Version="3.1.17" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 8f98b6d

Please sign in to comment.