fix: eth_simulateV1 wrong error codes for nonce too low/high (#11220, #11221)#11434
fix: eth_simulateV1 wrong error codes for nonce too low/high (#11220, #11221)#11434divi2806 wants to merge 2 commits into
Conversation
- Introduced new error codes for transaction nonce validation: NonceTooLow (-38010) and NonceTooHigh (-38011). - Updated SimulateTxExecutor to return these new error codes when nonce validation fails. - Added corresponding error messages for clarity. - Implemented a regression test to ensure correct behavior when a transaction nonce is too low, verifying that the expected error code and message are returned.
|
@claude review |
|
Claude finished @LukaszRozmej's task in 2m 32s —— View job Review
SummaryThe core fix is correct. FindingsMediumMissing regression test for LowSwitch arm ordering inconsistency — see inline comment What looks good
|
|
Duplicate of #11430 ? |
|
|
||
| Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.NonceTooLow)); | ||
| Assert.That(result.Result!.Error, Is.EqualTo(SimulateErrorMessages.NonceTooLow)); | ||
| } |
There was a problem hiding this comment.
Medium – Missing regression test for NonceTooHigh (#11221)
The PR claims to fix both #11220 and #11221, but only adds a test for the NonceTooLow path. The two cases map to different error codes (-38010 vs -38011) and different messages, so a regression on the NonceTooHigh arm (e.g. codes accidentally swapped, or the wrong constant referenced) would go undetected.
The author argues "same code path", but the switch has two separate arms:
TransactionResult.ErrorType.TransactionNonceTooHigh => ErrorCodes.NonceTooHigh,
TransactionResult.ErrorType.TransactionNonceTooLow => ErrorCodes.NonceTooLow,A simple companion test is straightforward — set StateOverrides nonce to 3, submit tx with Nonce = 5, and assert ErrorCode == -38011 and Error == "Transactions nonce is too high".
| TransactionResult.ErrorType.TransactionNonceTooLow | ||
| => SimulateErrorMessages.NonceTooLow, | ||
| TransactionResult.ErrorType.TransactionNonceTooHigh | ||
| => SimulateErrorMessages.NonceTooHigh, |
There was a problem hiding this comment.
Low – Arm ordering inconsistency
In MapSimulateErrorCode (line 261–262) the order is NonceTooHigh before NonceTooLow, but here in MapSimulateErrorMessage it is NonceTooLow before NonceTooHigh. No functional impact, but keeping both switches in the same order makes auditing the mapping easier.
| TransactionResult.ErrorType.TransactionNonceTooLow | |
| => SimulateErrorMessages.NonceTooLow, | |
| TransactionResult.ErrorType.TransactionNonceTooHigh | |
| => SimulateErrorMessages.NonceTooHigh, | |
| TransactionResult.ErrorType.TransactionNonceTooHigh | |
| => SimulateErrorMessages.NonceTooHigh, | |
| TransactionResult.ErrorType.TransactionNonceTooLow | |
| => SimulateErrorMessages.NonceTooLow, |
|
@LukaszRozmej, I did not see #11430 was already existing, |
- Updated regression tests to cover both nonce too low and too high scenarios for eth_simulateV1. - Adjusted test cases to return appropriate error codes and messages based on the sender's current nonce. - Improved code clarity by parameterizing nonce values in the test setup.
Fixes #11220
Fixes #11221
Changes
ErrorCodes.NonceTooLow = -38010andErrorCodes.NonceTooHigh = -38011toErrorCodes.csSimulateErrorMessages.NonceTooLow = "Transactions nonce is too low"andSimulateErrorMessages.NonceTooHigh = "Transactions nonce is too high"constants toSimulateErrorMessagesTransactionResult.ErrorType.TransactionNonceTooLow→ErrorCodes.NonceTooLow (-38010)inMapSimulateErrorCode(was incorrectly returning-32603InternalError)TransactionResult.ErrorType.TransactionNonceTooHigh→ErrorCodes.NonceTooHigh (-38011)inMapSimulateErrorCode(was incorrectly returning-32603InternalError)MapSimulateErrorMessageeth_simulateV1_nonce_too_low_returns_spec_error_code_and_messagecovering thevalidation: truepathTypes of changes
Testing
Requires testing
If yes, did you write tests?
Notes on testing
Added
eth_simulateV1_nonce_too_low_returns_spec_error_code_and_messagewhich usesStateOverridesto set the sender account nonce to5, then submits a transaction withNonce = 3(< 5) underValidation = true. AssertsErrorCode = -38010andError = "Transactions nonce is too low".Note:
TransactionNonceTooHigh(#11221) is fixed in the same switch arm and does not require a separate regression test — the mapping is covered by the same code path. Thevalidation: falsepath intentionally bypasses nonce checking by design (SkipValidationflag inTransactionProcessor), so no test is added for that case.All 92 simulate tests pass.
Documentation
Requires documentation update
Requires explanation in Release Notes