Skip to content

Commit ebee0a1

Browse files
committed
Write test to call a relay subscription
1 parent 8c6af84 commit ebee0a1

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Angor.Client.Services;
2+
using Angor.Shared;
3+
using Angor.Shared.Models;
4+
using Angor.Shared.Networks;
5+
using Angor.Shared.Services;
6+
using Microsoft.Extensions.Logging.Abstractions;
7+
using Moq;
8+
using Nostr.Client.Client;
9+
10+
namespace Angor.Test.Services
11+
{
12+
public class TestSignService
13+
{
14+
private readonly SignService _signService;
15+
16+
public TestSignService()
17+
{
18+
var mockNetworkConfiguration = new Mock<INetworkConfiguration>();
19+
var mockNetworkStorage = new Mock<INetworkStorage>();
20+
21+
mockNetworkConfiguration.Setup(nc => nc.GetAngorKey()).Returns("dummyAngorKey");
22+
mockNetworkConfiguration.Setup(nc => nc.GetNetwork()).Returns(Networks.Bitcoin.Testnet);
23+
24+
mockNetworkStorage.Setup(ns => ns.GetSettings()).Returns(new SettingsInfo
25+
{
26+
Relays = new List<SettingsUrl>
27+
{
28+
new() { Name = "", Url = "wss://relay.angor.io", IsPrimary = true },
29+
new() { Name = "", Url = "wss://relay2.angor.io", IsPrimary = true },
30+
},
31+
});
32+
33+
var communicationFactory = new NostrCommunicationFactory(new NullLogger<NostrWebsocketClient>(), new NullLogger<NostrCommunicationFactory>());
34+
var networkService = new NetworkService(mockNetworkStorage.Object, new HttpClient { BaseAddress = new Uri("https://angor.io") }, new NullLogger<NetworkService>(), mockNetworkConfiguration.Object);
35+
var subscriptionsHanding = new RelaySubscriptionsHandling(new NullLogger<RelaySubscriptionsHandling>(), communicationFactory, networkService);
36+
37+
_signService = new SignService(communicationFactory, networkService, subscriptionsHanding);
38+
}
39+
40+
//[Fact] // uncomment to test
41+
public async Task TestLookupInvestmentRequestApprovals()
42+
{
43+
string nostrPubKey = "5a05cc7a38e3875ee3242e5f068304a36c9609c4c15f5baaf7d75e8fcdfe36c5"; // Replace with actual public key
44+
45+
var tcs = new TaskCompletionSource<bool>();
46+
47+
bool failed = false;
48+
_signService.LookupSignedReleaseSigs(nostrPubKey, item =>
49+
{
50+
if(item.NostrEvent.Tags.FindFirstTagValue("subject") != "Release transaction signatures")
51+
{
52+
failed = true;
53+
tcs.SetResult(false);
54+
}
55+
},
56+
() =>
57+
{
58+
tcs.SetResult(true);
59+
});
60+
61+
await tcs.Task;
62+
63+
Assert.False(failed);
64+
}
65+
}
66+
}

src/Angor/Shared/Services/SignService.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Reactive.Linq;
22
using Angor.Shared.Models;
33
using Angor.Shared.Services;
4+
using Newtonsoft.Json;
5+
using Nostr.Client.Json;
46
using Nostr.Client.Keys;
57
using Nostr.Client.Messages;
68
using Nostr.Client.Requests;
@@ -244,16 +246,24 @@ public void LookupSignedReleaseSigs(string projectNostrPubKey, Action<SignServic
244246

245247
_subscriptionsHanding.TryAddEoseAction(subscriptionKey, onAllMessagesReceived);
246248

247-
nostrClient.Send(new NostrRequest(subscriptionKey, new NostrFilter
249+
nostrClient.Send(new NostrRequest(subscriptionKey, new NostrFilterWithSubject
248250
{
249251
Authors = new[] { projectNostrPubKey }, // From founder
250252
Kinds = new[] { NostrKind.EncryptedDm },
251-
}));
253+
//Subject = "Release transaction signatures"
254+
}));
252255
}
253256

254257
public void CloseConnection()
255258
{
256259
_subscriptionsHanding.Dispose();
257260
}
258261
}
262+
263+
public class NostrFilterWithSubject : NostrFilter
264+
{
265+
/// <summary>A list of subjects to filter by, corresponding to the "subject" tag</summary>
266+
[JsonProperty("#subject")]
267+
public string? Subject { get; set; }
268+
}
259269
}

0 commit comments

Comments
 (0)