|
| 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 | +} |
0 commit comments