Skip to content

Commit

Permalink
fix: all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gigajuwels committed Oct 5, 2023
1 parent f218272 commit cb3585c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
10 changes: 4 additions & 6 deletions Tests/WalletConnectSharp.Auth.Tests/AuthClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,9 @@ public async void TestCustomRequestExpiry()

TaskCompletionSource<bool> resolve1 = new TaskCompletionSource<bool>();

PeerA.Core.Relayer.ListenOnce<object>(nameof(PeerA.Core.Relayer.OnPublishedMessage), (sender, args) =>
PeerA.Core.Relayer.Publisher.ListenOnce<PublishParams>(nameof(PeerA.Core.Relayer.Publisher.OnPublishedMessage), (sender, args) =>
{
var @event = (RequestArguments<RelayPublishRequest>)args;

Assert.Equal(expiry, @event.Params.TTL);
Assert.Equal(expiry, args.Options.TTL);
resolve1.SetResult(true);
});

Expand Down Expand Up @@ -409,7 +407,7 @@ public async void TestPing()
receivedPeerPing.SetResult(true);
});

PeerA.Core.Pairing.ListenOnce(nameof(PeerA.Core.Pairing.PairingPinged), (sender, args) =>
PeerA.Core.Pairing.ListenOnce<PairingEvent>(nameof(PeerA.Core.Pairing.PairingPinged), (sender, args) =>
{
receivedClientPing.SetResult(true);
});
Expand Down Expand Up @@ -445,7 +443,7 @@ public async void TestDisconnectedPairing()

PeerB.AuthRequested += OnPeerBOnAuthRequested;

PeerB.Core.Pairing.ListenOnce(nameof(PeerB.Core.Pairing.PairingDeleted), (sender, args) =>
PeerB.Core.Pairing.ListenOnce<PairingEvent>(nameof(PeerB.Core.Pairing.PairingDeleted), (sender, args) =>
{
peerDeletedPairing.SetResult(true);
});
Expand Down
2 changes: 1 addition & 1 deletion Tests/WalletConnectSharp.Network.Tests/RelayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async void DoesNotDoubleRegisterListeners()
var expectedDisconnectCount = 3;
var disconnectCount = 0;

provider.On<DisconnectionInfo>("disconnect", (_, __) => disconnectCount++);
provider.Disconnected += (_, _) => disconnectCount++;

await provider.Connect();
await provider.Disconnect();
Expand Down
10 changes: 9 additions & 1 deletion WalletConnectSharp.Core/Controllers/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class Publisher : IPublisher
/// The EventDelegator this publisher module is using
/// </summary>
public EventDelegator Events { get; }


public event EventHandler<PublishParams> OnPublishedMessage;

/// <summary>
/// The Relayer this publisher module uses to publish messages
/// </summary>
Expand Down Expand Up @@ -63,6 +65,10 @@ public Publisher(IRelayer relayer)

private void RegisterEventListeners()
{
#pragma warning disable CS0618 // Old event system
this.OnPublishedMessage += Relayer.WrapEventHandler<PublishParams>(RelayerEvents.Publish);
#pragma warning restore CS0618 // Old event system

Relayer.Core.HeartBeat.OnPulse += (_, _) => CheckQueue();
}

Expand Down Expand Up @@ -98,6 +104,7 @@ private async void CheckQueue()
var hash = HashUtils.HashMessage(@params.Message);
await RpcPublish(@params.Topic, @params.Message, @params.Options.TTL, @params.Options.Tag,
@params.Options.Relay);
this.OnPublishedMessage?.Invoke(this, @params);
OnPublish(hash);
}
}
Expand Down Expand Up @@ -178,6 +185,7 @@ public async Task Publish(string topic, string message, PublishOptions opts = nu
{
await RpcPublish(topic, message, @params.Options.TTL, @params.Options.Tag, @params.Options.Relay)
.WithTimeout(TimeSpan.FromSeconds(45));
this.OnPublishedMessage?.Invoke(this, @params);
OnPublish(hash);
}
catch (Exception e)

Check warning on line 191 in WalletConnectSharp.Core/Controllers/Publisher.cs

View workflow job for this annotation

GitHub Actions / build (integration-tests)

The variable 'e' is declared but never used
Expand Down
4 changes: 0 additions & 4 deletions WalletConnectSharp.Core/Controllers/Relayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public string Context
public event EventHandler OnConnected;
public event EventHandler OnDisconnected;
public event EventHandler<Exception> OnErrored;
public event EventHandler<object> OnPublishedMessage;
public event EventHandler<MessageEvent> OnMessageReceived;
public event EventHandler OnTransportClosed;
public event EventHandler OnConnectionStalled;
Expand Down Expand Up @@ -189,7 +188,6 @@ private void WrapOldEvents()
{
this.OnTransportClosed += this.WrapEventHandler(RelayerEvents.TransportClosed);
this.OnConnectionStalled += this.WrapEventHandler(RelayerEvents.ConnectionStalled);
this.OnPublishedMessage += this.WrapEventHandler<object>(RelayerEvents.Publish);
this.OnMessageReceived += this.WrapEventHandler<MessageEvent>(RelayerEvents.Message);
this.OnConnected += this.WrapEventHandler(RelayerEvents.Connect);
this.OnDisconnected += this.WrapEventHandler(RelayerEvents.Disconnect);
Expand Down Expand Up @@ -382,8 +380,6 @@ public async Task<TR> Request<T, TR>(IRequestArguments<T> request, object contex

WCLogger.Log("[Relayer] Sending request through provider");
var result = await this.Provider.Request<T, TR>(request, context);

this.OnPublishedMessage?.Invoke(this, request);

return result;
}
Expand Down
3 changes: 3 additions & 0 deletions WalletConnectSharp.Core/Interfaces/IPublisher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using WalletConnectSharp.Common;
using WalletConnectSharp.Core.Models.Publisher;
using WalletConnectSharp.Core.Models.Relay;
using WalletConnectSharp.Events.Interfaces;

Expand All @@ -11,6 +12,8 @@ namespace WalletConnectSharp.Core.Interfaces
/// </summary>
public interface IPublisher : IEvents, IModule
{
event EventHandler<PublishParams> OnPublishedMessage;

/// <summary>
/// The IRelayer instance this publisher is using to publish messages
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions WalletConnectSharp.Core/Interfaces/IRelayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public interface IRelayer : IEvents, IModule

event EventHandler<Exception> OnErrored;

event EventHandler<object> OnPublishedMessage;

event EventHandler<MessageEvent> OnMessageReceived;

event EventHandler OnTransportClosed;
Expand Down
21 changes: 11 additions & 10 deletions WalletConnectSharp.Sign/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public async Task<ConnectedData> Connect(ConnectOptions options)
WCLogger.Log($"Created public key pair");

TaskCompletionSource<SessionStruct> approvalTask = new TaskCompletionSource<SessionStruct>();
this.Events.ListenForOnce<SessionStruct>("session_connect", async (sender, e) =>
this.SessionConnected += async (sender, session) =>
{
logger.Log("Got session_connect event for session struct");
if (approvalTask.Task.IsCompleted)
Expand All @@ -318,7 +318,6 @@ public async Task<ConnectedData> Connect(ConnectOptions options)
return;
}

var session = e.EventData;
session.Self.PublicKey = publicKey;
var completeSession = session with { RequiredNamespaces = requiredNamespaces };
await PrivateThis.SetExpiry(session.Topic, session.Expiry.Value);
Expand All @@ -329,23 +328,25 @@ public async Task<ConnectedData> Connect(ConnectOptions options)
await this.Client.Core.Pairing.UpdateMetadata(topic, session.Peer.Metadata);
}
approvalTask.SetResult(completeSession);
});
this.Events.ListenForOnce<JsonRpcResponse<SessionProposeResponse>>("session_connect", (sender, e) =>
};

this.SessionConnectionErrored += (sender, exception) =>
{
logger.Log("Got session_connect event for rpc response");
if (approvalTask.Task.IsCompleted)
{
logger.Log("approval already received though, skipping");
return;
}
if (e.EventData.IsError)

if (exception == null)
{
logger.LogError("Got session_connect error " + e.EventData.Error.Message);
approvalTask.SetException(e.EventData.Error.ToException());
return;
}
});

logger.LogError("Got session_connect error " + exception.Message);
approvalTask.SetException(exception);
};

if (string.IsNullOrWhiteSpace(topic))
{
Expand Down
5 changes: 5 additions & 0 deletions WalletConnectSharp.Sign/Internals/EngineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ async Task IEnginePrivate.OnSessionSettleResponse(string topic, JsonRpcResponse<
var error = Error.FromErrorType(ErrorType.USER_DISCONNECTED);
await this.Client.Session.Delete(topic, error);
this.SessionRejected?.Invoke(this, session);

// Still used do not remove
this.Events.Trigger($"session_approve{id}", payload);
}
else
Expand Down Expand Up @@ -225,6 +227,7 @@ async Task IEnginePrivate.OnSessionUpdateResponse(string topic, JsonRpcResponse<
Id = id,
Topic = topic,
});
// Still used, do not remove
this.Events.Trigger($"session_update{id}", payload);
}

Expand Down Expand Up @@ -256,6 +259,7 @@ async Task IEnginePrivate.OnSessionExtendResponse(string topic, JsonRpcResponse<
Topic = topic,
Id = id
});
// Still used, do not remove
this.Events.Trigger($"session_extend{id}", payload);
}

Expand Down Expand Up @@ -292,6 +296,7 @@ async Task IEnginePrivate.OnSessionPingResponse(string topic, JsonRpcResponse<bo
Topic = topic
});

// Still used, do not remove
this.Events.Trigger($"session_ping{id}", payload);
}

Expand Down
2 changes: 2 additions & 0 deletions WalletConnectSharp.Sign/WalletConnectSignClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ private WalletConnectSignClient(SignClientOptions options)
Session = new Session(Core);
Proposal = new Proposal(Core);
Engine = new Engine(this);

SetupEvents();
}

private void SetupEvents()
Expand Down

0 comments on commit cb3585c

Please sign in to comment.