Skip to content

Commit

Permalink
Merge pull request #1 from nbd-wtf/wip
Browse files Browse the repository at this point in the history
Better support for running tests against various images, fixes, style cleanup
  • Loading branch information
rsafier authored Mar 26, 2024
2 parents 43b0466 + 7bc03f3 commit b528d5f
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 499 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal -l "console;verbosity=detailed" --collect:"XPlat Code Coverage" --logger "trx;LogFileName=test-results.trx" --results-directory ./coverage
run: |
cdir=`pwd`
cd LNUnit.Tests
dotnet test -f net8.0 --filter FullyQualifiedName~LNUnit.Test --no-build --verbosity normal -l "console;verbosity=detailed" --collect:"XPlat Code Coverage" --logger "trx;LogFileName=test-results.trx" --results-directory $cdir/coverage
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
Expand Down
24 changes: 11 additions & 13 deletions LNBolt.Tests/Bech32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,25 @@
using LNBolt.BOLT11;
using NUnit.Framework;
using org.ldk.structs;
using ServiceStack;

namespace LNBolt.Tests;

public class Bech32Tests
{

public record PaymentRequest
{
public byte[] PaymentHash { get; set; }
public Option_u64Z AmountMilliSatoshis { get; set; }
public long expiry_time { get; set; }
public byte[] payee_pub_key { get; set; }
}

[Test]
public async Task ldk()
{
for (int i = 0; i < 10000; i++)
for (var i = 0; i < 10000; i++)
{
var bolt11 = Bolt11Invoice.from_str(
"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcsh2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqclj9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9dha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58aguqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphmsywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0vp62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh38s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5j5r6drg6k6zcqj0fcwg");
var x = bolt11 as Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK;
var res = new PaymentRequest()
var res = new PaymentRequest
{
PaymentHash = x.res.payment_hash(),
AmountMilliSatoshis = x.res.amount_milli_satoshis(),
expiry_time = x.res.expiry_time(),
payee_pub_key = x.res.payee_pub_key(),
payee_pub_key = x.res.payee_pub_key()
//RouteHints = x.res.route_hints(),
};
var y = x.res.payment_hash();
Expand Down Expand Up @@ -102,4 +92,12 @@ public void LNURLDecode()
Assert.AreEqual("https://service.com/api?q=3fc3645b439ce8e7f2553a69e5267081d96dcd340693afabe04be7b0ccd178df",
url);
}

public record PaymentRequest
{
public byte[] PaymentHash { get; set; }
public Option_u64Z AmountMilliSatoshis { get; set; }
public long expiry_time { get; set; }
public byte[] payee_pub_key { get; set; }
}
}
6 changes: 3 additions & 3 deletions LNBolt.Tests/LNBolt.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

<ItemGroup>
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.4.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.4.4"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="NUnit" Version="3.14.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="org.ldk" Version="0.0.121.2"/>
<PackageReference Include="coverlet.collector" Version="3.1.2">
Expand Down
2 changes: 1 addition & 1 deletion LNBolt/LNBolt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="NBitcoin" Version="7.0.31"/>
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0"/>
<PackageReference Include="ServiceStack.Text" Version="8.0.0" />
<PackageReference Include="ServiceStack.Text" Version="8.0.0"/>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
Expand Down
2 changes: 1 addition & 1 deletion LNUnit.LND/LNDNodePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public async Task<PoolRebalanceStats> RebalanceNodePool()
{
Value = valueInSataoshis,
Memo = "InvoicePayRebalance",
Expiry = 60, //1 minute
Expiry = 60 //1 minute
});
_logger?.LogDebug("InvoicePayRebalance: {PaymentRequest} for {Value} sats from {Source}",
invoice.PaymentRequest, valueInSataoshis, src.LocalAlias);
Expand Down
11 changes: 8 additions & 3 deletions LNUnit.LND/LNDSimpleHtlcInterceptorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Grpc.Core;
using Routerrpc;

Expand All @@ -17,7 +18,8 @@ public LNDSimpleHtlcInterceptorHandler(LNDNodeConnection connection,
Func<ForwardHtlcInterceptRequest, Task<ForwardHtlcInterceptResponse>> interceptLogic)
{
Node = connection;
_task = Task.Factory.StartNew(AttachInterceptor, _cancellationTokenSource.Token);
_task = Task.Factory.StartNew(AttachInterceptor, _cancellationTokenSource.Token,
TaskCreationOptions.LongRunning, TaskScheduler.Current);
OnIntercept = interceptLogic;
while (!Running)
Task.Delay(100).Wait();
Expand All @@ -42,17 +44,20 @@ public void Dispose()

private async Task AttachInterceptor()
{
Debug.Print($"AttachInterceptor: {Node.LocalAlias}");
try
{
using (var streamingEvents =
Node.RouterClient.HtlcInterceptor(cancellationToken: _cancellationTokenSource.Token))
{
Running = true;
while (await streamingEvents.ResponseStream.MoveNext())
while (await streamingEvents.ResponseStream.MoveNext().ConfigureAwait(false))
{
Debug.Print($"Event: {Node.LocalAlias}");

var message = streamingEvents.ResponseStream.Current;
var result = OnIntercept(message);
await streamingEvents.RequestStream.WriteAsync(await result);
await streamingEvents.RequestStream.WriteAsync(await result).ConfigureAwait(false);
InterceptCount++;
}
}
Expand Down
10 changes: 5 additions & 5 deletions LNUnit.LND/LNUnit.LND.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="EndianBinaryIO" Version="1.1.2"/>
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
<PackageReference Include="Google.Protobuf" Version="3.25.1"/>
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.59.0"/>
<PackageReference Include="Grpc.Net.Client" Version="2.59.0"/>
<PackageReference Include="Grpc.Net.Common" Version="2.59.0"/>
Expand All @@ -33,13 +33,13 @@

<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0"/>

<PackageReference Include="NBitcoin" Version="7.0.31" />
<PackageReference Include="NBitcoin" Version="7.0.31"/>

<PackageReference Include="Portable.BouncyCastle" Version="1.9.0"/>

<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="ServiceStack.Text" Version="8.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="Serilog" Version="3.1.1"/>
<PackageReference Include="ServiceStack.Text" Version="8.0.0"/>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0"/>
</ItemGroup>


Expand Down
Loading

0 comments on commit b528d5f

Please sign in to comment.