diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index c565a40ddb81f9e1f66cab20a0f11f2c53b201df..f4512cf93526b23848c8f89afc68f83af47c3105 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 492b6dcf99cf32965e7ebfb973a71275d65d5e23..03909ef77481f1b9b3f113f169f9d15be4551865 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 77e0833170b0934dd687ca616acc289709fab01d..e28792207705f480f10a93db2cec620e16b6ceed 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