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: Remove unnecessary chainID check from AddressProvider #196

Merged
merged 2 commits into from
May 28, 2024
Merged
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
6 changes: 2 additions & 4 deletions Tests/WalletConnectSharp.Sign.Test/SignTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using WalletConnectSharp.Common.Model.Errors;
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Crypto;
using WalletConnectSharp.Network.Models;
using WalletConnectSharp.Sign.Interfaces;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine;
using WalletConnectSharp.Storage;
using WalletConnectSharp.Tests.Common;
using Xunit;
using Xunit.Abstractions;
@@ -786,8 +784,8 @@ public async Task TestAddressProviderChainIdChange()

_ = await TestConnectMethod(ClientA, ClientB);

const string badChainId = "invalid:invalid";
await Assert.ThrowsAsync<InvalidOperationException>(() => ClientA.AddressProvider.SetDefaultChainIdAsync(badChainId));
const string badChainId = "badChainId";
await Assert.ThrowsAsync<ArgumentException>(() => ClientA.AddressProvider.SetDefaultChainIdAsync(badChainId));

// Change the default chain id
const string newChainId = "eip155:10";
5 changes: 3 additions & 2 deletions WalletConnectSharp.Sign/Controllers/AddressProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Core;
using WalletConnectSharp.Sign.Interfaces;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine.Events;
@@ -220,9 +221,9 @@ public async Task SetDefaultChainIdAsync(string chainId)
throw new ArgumentNullException(nameof(chainId));
}

if (!DefaultSession.Namespaces[DefaultNamespace].Chains.Contains(chainId))
if (!Utils.IsValidChainId(chainId))
{
throw new InvalidOperationException($"Chain {chainId} is not available in the current session");
throw new ArgumentException("The format of 'chainId' is invalid. Must be in the format of 'namespace:chainId' (e.g. 'eip155:10'). See CAIP-2 for more information.");
}

DefaultChainId = chainId;

Unchanged files with check annotations Beta

{
eventHandler -= internalHandler;
}
catch (Exception e)

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used

Check warning on line 129 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used
{
// ignored
}
{
eventHandler -= internalHandler;
}
catch (Exception e)

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / build

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (unit-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used

Check warning on line 155 in Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used
{
// ignored
}
}
}
public async void Dispose()

Check warning on line 302 in Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 302 in Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs

GitHub Actions / test (unit-tests)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 302 in Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs

GitHub Actions / test (integration-tests)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Dispose(true);
GC.SuppressFinalize(this);
//Contract.Requires<ArgumentNullException>(data != null);
//Contract.Ensures(//Contract.Result<byte[]>() != null);
SHA256 sha256 = new SHA256Managed();

Check warning on line 119 in Core Modules/WalletConnectSharp.Crypto/Encoder/Base58Encoding.cs

GitHub Actions / build

'SHA256Managed' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.' (https://aka.ms/dotnet-warnings/SYSLIB0021)
byte[] hash1 = sha256.ComputeHash(data);
byte[] hash2 = sha256.ComputeHash(hash1);
var carry = source[pbegin];
// Apply "b58 = b58 * 256 + ch".
var i = 0;
for (var it1 = size - 1; (carry != 0 || i < length) && (it1 != -1); it1--, i++) {

Check warning on line 66 in Core Modules/WalletConnectSharp.Crypto/Encoder/BaseX.cs

GitHub Actions / test (unit-tests)

Comparison to integral constant is useless; the constant is outside the range of type 'uint'

Check warning on line 66 in Core Modules/WalletConnectSharp.Crypto/Encoder/BaseX.cs

GitHub Actions / test (integration-tests)

Comparison to integral constant is useless; the constant is outside the range of type 'uint'
carry += (byte)((uint)(256 * b58[it1]) >> 0);
b58[it1] = (byte)((uint)(carry % Base) >> 0);
carry = (byte)((uint)(carry / Base) >> 0);
return null;
}
var i = 0;
for (var it3 = size - 1; (carry != 0 || i < length) && (it3 != -1); it3--, i++) {

Check warning on line 121 in Core Modules/WalletConnectSharp.Crypto/Encoder/BaseX.cs

GitHub Actions / test (integration-tests)

Comparison to integral constant is useless; the constant is outside the range of type 'uint'
carry += (byte)((uint)(Base * b256[it3]) >> 0);
b256[it3] = (byte)((uint)(carry % 256) >> 0);
carry = (byte)((uint)(carry / 256) >> 0);
{
seed = await KeyChain.Get(CryptoClientSeed);
}
catch (Exception e)

Check warning on line 662 in Core Modules/WalletConnectSharp.Crypto/Crypto.cs

GitHub Actions / test (integration-tests)

The variable 'e' is declared but never used
{
byte[] seedRaw = new byte[32];
RandomNumberGenerator.Fill(seedRaw);