From 9617ab5bf9736e3178d58dcb666f25e2cdee2e6c Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Tue, 4 Feb 2025 17:35:47 +0100 Subject: [PATCH] EVM Node: Do not use snake_case for state override --- etherlink/CHANGES_NODE.md | 2 ++ .../lib_dev/encodings/ethereum_types.ml | 28 ++++++++++++++----- etherlink/tezt/tests/eth_call.ml | 4 +-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index c565a40ddb81..f4512cf93526 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -34,6 +34,8 @@ - `eth_getLogs` now returns an empty array instead of an error when `fromBlock` is greater than `toBlock`. - Improve reliability of `debug_traceTransaction` when dealing with non standard revert reasons. (!16415) +- Fixes the encoding of state overrides for `eth_call` to correctly parse + `stateDiff`. Keeps the support for `state_diff` for now. (!16581) ### Internal diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml index 492b6dcf99cf..03909ef77481 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml @@ -1106,20 +1106,34 @@ let state_encoding = let state_account_override_encoding = let open Data_encoding in - conv + let state_diff_encoding = + StorageMap.associative_array_encoding hex_encoding + in + conv_with_guard (fun {balance; nonce; code; state; state_diff} -> - (balance, nonce, code, state, state_diff)) - (fun (balance, nonce, code, state, state_diff) -> + (balance, nonce, code, state, Some state_diff, None)) + (fun (balance, nonce, code, state, state_diff, state_diff') -> + let open Result_syntax in + let+ state_diff = + match (state_diff, state_diff') with + | Some state_diff, None | None, Some state_diff -> Ok state_diff + | None, None -> Ok StorageMap.empty + | Some _, Some _ -> Error "Cannot provide both state_diff and stateDiff" + in {balance; nonce; code; state; state_diff}) - (obj5 + (obj6 (opt "balance" quantity_encoding) (opt "nonce" quantity_encoding) (opt "code" hex_encoding) (dft "state" state_encoding None) - (dft + (opt "stateDiff" state_diff_encoding) + (opt + ~description: + "DEPRECATED. The expected name for this field is stateDiff. We \ + keep supporting state_diff for now for avoiding potential \ + breaking changes." "state_diff" - (StorageMap.associative_array_encoding hex_encoding) - StorageMap.empty)) + state_diff_encoding)) let state_override_empty = AddressMap.empty diff --git a/etherlink/tezt/tests/eth_call.ml b/etherlink/tezt/tests/eth_call.ml index 77e0833170b0..e28792207705 100644 --- a/etherlink/tezt/tests/eth_call.ml +++ b/etherlink/tezt/tests/eth_call.ml @@ -301,7 +301,7 @@ let test_call_state_override_state_diff = ); ] in - let override = [`O [(contract, `O [("state_diff", state_diff)])]] in + let override = [`O [(contract, `O [("stateDiff", state_diff)])]] in let* call_result = make_call ~override "getCount()" in check_value call_result @@ -327,7 +327,7 @@ let test_call_state_override_state_diff = ); ] in - let override = [`O [(contract, `O [("state_diff", invalid)])]] in + let override = [`O [(contract, `O [("stateDiff", invalid)])]] in let* call_result = make_call ~override "getCount()" in Check.( (Evm_node.extract_error_message call_result -- GitLab