From 7b48f99fe476e5ce87c18cc8b149d6b868a4d8fa Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 16 Jan 2025 15:29:49 +0100 Subject: [PATCH] fix strategy to deep copy the initial state --- cairo/tests/utils/strategies.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cairo/tests/utils/strategies.py b/cairo/tests/utils/strategies.py index cd5d3b57..bc62e588 100644 --- a/cairo/tests/utils/strategies.py +++ b/cairo/tests/utils/strategies.py @@ -18,6 +18,7 @@ from hypothesis import strategies as st from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME +from ethereum.cancun.trie import copy_trie from ethereum.crypto.elliptic_curve import SECP256K1N from ethereum.exceptions import EthereumException from tests.utils.args_gen import ( @@ -378,11 +379,25 @@ def tuple_strategy(thing): _snapshots=st.just([]), created_accounts=st.just(set()), ).map( - # Create the original state snapshot using the same tries + # Create the original state snapshot using copies of the tries lambda state: State( _main_trie=state._main_trie, _storage_tries=state._storage_tries, - _snapshots=[(state._main_trie, state._storage_tries)], + # Create deep copies of the tries for the snapshot, + # because otherwise mutating the main trie will also mutate the snapshot + _snapshots=[ + ( + copy_trie(state._main_trie), + { + addr: Trie( + secured=trie.secured, + default=trie.default, + _data=dict(trie._data), + ) + for addr, trie in state._storage_tries.items() + }, + ) + ], created_accounts=set(), ) ),