diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcServiceTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcServiceTests.cs index 91583f619e4..cb40d0e2626 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcServiceTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcServiceTests.cs @@ -48,7 +48,7 @@ public void Initialize() private ILogManager _logManager = null!; private JsonRpcContext _context = null!; - private JsonRpcResponse TestRequest(T module, string method, params string[] parameters) where T : IRpcModule + private JsonRpcResponse TestRequest(T module, string method, params string[]? parameters) where T : IRpcModule { RpcModuleProvider moduleProvider = new(new FileSystem(), _configurationProvider.GetConfig(), LimboLogs.Instance); moduleProvider.Register(new SingletonModulePool(new SingletonFactory(module), true)); @@ -182,7 +182,7 @@ public void NetVersionTest() { INetRpcModule netRpcModule = Substitute.For(); netRpcModule.net_version().ReturnsForAnyArgs(x => ResultWrapper.Success("1")); - JsonRpcSuccessResponse? response = TestRequest(netRpcModule, "net_version") as JsonRpcSuccessResponse; + JsonRpcSuccessResponse? response = TestRequest(netRpcModule, "net_version", null) as JsonRpcSuccessResponse; Assert.That(response?.Result, Is.EqualTo("1")); Assert.IsNotInstanceOf(response); } diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs b/src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs index 43a8d311af4..d66f7b41528 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs @@ -63,9 +63,9 @@ public static IJsonRpcService BuildRpcService(T module) where T : class, IRpc return service; } - public static JsonRpcRequest GetJsonRequest(string method, params string[] parameters) + public static JsonRpcRequest GetJsonRequest(string method, params string[]? parameters) { - var doc = JsonDocument.Parse(JsonSerializer.Serialize(parameters?.ToArray() ?? Array.Empty())); + var doc = JsonDocument.Parse(JsonSerializer.Serialize(parameters?.ToArray())); var request = new JsonRpcRequest() { JsonRpc = "2.0", diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs index 2c34729f701..bea90a5b9a4 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs @@ -99,12 +99,16 @@ private async Task ExecuteAsync(JsonRpcRequest request, string LogRequest(methodName, providedParameters, method.expectedParameters); - int missingParamsCount = method.expectedParameters.Length - providedParameters.GetArrayLength(); - foreach (JsonElement item in providedParameters.EnumerateArray()) + var providedParametersLength = providedParameters.ValueKind == JsonValueKind.Array ? providedParameters.GetArrayLength() : 0; + int missingParamsCount = method.expectedParameters.Length - providedParametersLength; + if (providedParametersLength > 0) { - if (item.ValueKind == JsonValueKind.Null || (item.ValueKind == JsonValueKind.String && item.ValueEquals(ReadOnlySpan.Empty))) + foreach (JsonElement item in providedParameters.EnumerateArray()) { - missingParamsCount++; + if (item.ValueKind == JsonValueKind.Null || (item.ValueKind == JsonValueKind.String && item.ValueEquals(ReadOnlySpan.Empty))) + { + missingParamsCount++; + } } } @@ -232,7 +236,7 @@ private void LogRequest(string methodName, JsonElement providedParameters, Param int paramsCount = 0; const string separator = ", "; - if (providedParameters.ValueKind != JsonValueKind.Undefined && providedParameters.ValueKind != JsonValueKind.Null) + if (providedParameters.ValueKind == JsonValueKind.Array) { foreach (JsonElement param in providedParameters.EnumerateArray()) {