Skip to content

Commit

Permalink
fix strategy to deep copy the initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Jan 16, 2025
1 parent aa3bcd4 commit 7b48f99
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cairo/tests/utils/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(),
)
),
Expand Down

0 comments on commit 7b48f99

Please sign in to comment.