diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs index 0a708af0bb84..b9b097dcf432 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs @@ -1921,14 +1921,19 @@ public async Task Send_raw_transaction_will_send_transaction(string rawTransacti Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"Invalid, InvalidTxSignature: Signature is invalid.\"},\"id\":67}")); } - [Test] - public async Task Send_raw_transaction_returns_invalid_rlp_for_empty_list() + [TestCase("c0", TestName = "EmptyList")] + [TestCase("d4", TestName = "TruncatedShortList")] + [TestCase("09c0", TestName = "UnknownTxType")] + [TestCase("03c0", TestName = "Eip4844_TruncatedList")] + [TestCase("04c0", TestName = "Eip7702_TruncatedList")] + public async Task Send_raw_transaction_returns_invalid_params_for_malformed_rlp(string rawTxHex) { using Context ctx = await Context.Create(); - string serialized = await ctx.Test.TestEthRpc("eth_sendRawTransaction", "c0"); + string serialized = await ctx.Test.TestEthRpc("eth_sendRawTransaction", rawTxHex); - Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"Invalid RLP.\"},\"id\":67}")); + Assert.That(serialized, Does.Contain($"\"code\":{ErrorCodes.InvalidParams}")); + Assert.That(serialized, Does.Contain("Invalid RLP:")); } [TestCaseSource(nameof(SendRawTransactionSyncFailureCases))] @@ -1946,7 +1951,7 @@ public async Task EthSendRawTransactionSync_WhenSubmitFailsOrTimesOut_ReturnsExp private static IEnumerable SendRawTransactionSyncFailureCases() { - yield return new TestCaseData("c0", null, ErrorCodes.TransactionRejected, "Invalid RLP") + yield return new TestCaseData("c0", null, ErrorCodes.InvalidParams, "Invalid RLP") .SetName("InvalidRlp"); Transaction tx = Build.A.Transaction @@ -2408,7 +2413,7 @@ public async Task eth_sendRawTransaction_returns_correct_error_if_AuthorityTuple string result = await test.TestEthRpc("eth_sendRawTransaction", Bytes.ToHexString(Rlp.Encode(invalidSetCodeTx).Bytes)); JsonRpcErrorResponse actual = new EthereumJsonSerializer().Deserialize(result); - Assert.That(actual.Error!.Code, Is.EqualTo(ErrorCodes.TransactionRejected)); + Assert.That(actual.Error!.Code, Is.EqualTo(ErrorCodes.InvalidParams)); } [Test] diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs index d2c88f4027ac..4917af28f883 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs @@ -366,9 +366,9 @@ public virtual async Task> eth_sendRawTransaction(byte[] RlpBehaviors.AllowUnsigned | RlpBehaviors.SkipTypedWrapping | RlpBehaviors.InMempoolForm); return await SendTx(tx); } - catch (RlpException) + catch (RlpException e) { - return ResultWrapper.Fail("Invalid RLP.", ErrorCodes.TransactionRejected); + return ResultWrapper.Fail($"Invalid RLP: {e.Message}", ErrorCodes.InvalidParams); } }