Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unhandledable session event exception #201

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefaultVersion>2.4.0</DefaultVersion>
<DefaultVersion>2.4.1</DefaultVersion>
<DefaultTargetFrameworks>net6.0;net7.0;net8.0;netstandard2.1;</DefaultTargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions Tests/WalletConnectSharp.Web3Wallet.Tests/SignTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ await Task.WhenAll(

Assert.True(_dapp.TryUnsubscribeFromSessionEvent(referenceTypeEventData.Name, ReferenceTypeEventHandler));
Assert.True(_dapp.TryUnsubscribeFromSessionEvent(valueTypeEventData.Name, ValueTypeEventHandler));

// Test invalid chains
await Assert.ThrowsAsync<FormatException>(() => _wallet.EmitSessionEvent(session.Topic, valueTypeEventData, "invalid chain"));
await Assert.ThrowsAsync<NamespacesException>(() => _wallet.EmitSessionEvent(session.Topic, valueTypeEventData, "123:321"));
}

[Fact, Trait("Category", "unit")]
Expand Down
2 changes: 2 additions & 0 deletions WalletConnectSharp.Sign/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using WalletConnectSharp.Common.Model.Errors;
using WalletConnectSharp.Common.Model.Relay;
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Core;
using WalletConnectSharp.Core.Interfaces;
using WalletConnectSharp.Core.Models;
using WalletConnectSharp.Core.Models.Pairing;
Expand Down Expand Up @@ -818,6 +819,7 @@ public async Task Respond<T, TR>(string topic, JsonRpcResponse<TR> response)
public async Task Emit<T>(string topic, EventData<T> eventData, string chainId = null)
{
IsInitialized();
await PrivateThis.IsValidEmit(topic, eventData, chainId);
await MessageHandler.SendRequest<SessionEvent<T>, object>(topic,
new SessionEvent<T> { ChainId = chainId, Event = eventData, Topic = topic });
}
Expand Down
4 changes: 4 additions & 0 deletions WalletConnectSharp.Sign/Internals/EngineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ async Task IEnginePrivate.OnSessionEventRequest(string topic, JsonRpcRequest<Ses
{
await MessageHandler.SendError<SessionEvent<JToken>, bool>(id, topic, Error.FromException(e));
}
catch (Exception e) // to avoid unhandled exceptions caused by invalid events sent by another peer
{
logger.LogError(e);
}
}
}
}
2 changes: 1 addition & 1 deletion WalletConnectSharp.Sign/Internals/EngineValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void ValidateNamespacesChainId(Namespaces namespaces, string chainId)
{
if (!Utils.IsValidChainId(chainId))
{
throw new FormatException($"ChainId {chainId} should be a string and conform to 'chainId:chainId' format.");
throw new FormatException($"ChainId {chainId} should be a string and conform to CAIP-2.");
}

var chains = GetNamespacesChains(namespaces);
Expand Down
Loading