Skip to content

Commit

Permalink
fix private_key strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Dec 10, 2024
1 parent b8d9162 commit 0207a9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion cairo/tests/src/utils/test_signature.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from ethereum_types.numeric import U256

from starkware.cairo.common.cairo_builtins import BitwiseBuiltin, KeccakBuiltin
Expand Down
8 changes: 4 additions & 4 deletions cairo/tests/src/utils/test_signature.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
from eth_keys.datatypes import PrivateKey
from ethereum_types.bytes import Bytes32
from ethereum_types.numeric import U256
from hypothesis import given
from hypothesis import strategies as st
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

from ethereum_types.numeric import U256
from ethereum_types.bytes import Bytes32
from ethereum.crypto.elliptic_curve import SECP256K1N
from tests.utils.errors import cairo_error
from tests.utils.strategies import felt
Expand Down Expand Up @@ -49,8 +49,8 @@ def test__verify_eth_signature_uint256(

@given(
msg_hash=...,
r=st.integers(min_value=1, max_value=SECP256K1N - 1).map(U256),
s=st.integers(min_value=1, max_value=SECP256K1N - 1).map(U256),
r=st.integers(min_value=U256(1), max_value=SECP256K1N - U256(1)),
s=st.integers(min_value=U256(1), max_value=SECP256K1N - U256(1)),
y_parity=st.integers(min_value=2, max_value=DEFAULT_PRIME - 1),
eth_address=felt,
)
Expand Down
5 changes: 3 additions & 2 deletions cairo/tests/utils/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from typing import ForwardRef, Sequence, TypeAlias, Union
from unittest.mock import patch

from eth_keys.datatypes import PrivateKey
from ethereum_types.bytes import Bytes0, Bytes8, Bytes20, Bytes32, Bytes256
from ethereum_types.numeric import U64, U256, FixedUnsigned, Uint
from hypothesis import strategies as st
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

from ethereum.crypto.elliptic_curve import SECP256K1N
from eth_keys.datatypes import PrivateKey

# Mock the Extended type because hypothesis cannot handle the RLP Protocol
# Needs to be done before importing the types from ethereum.cancun.trie
Expand Down Expand Up @@ -94,7 +95,7 @@ def st_from_type(cls):
)

private_key = (
st.integers(min_value=1, max_value=SECP256K1N - 1)
st.integers(min_value=1, max_value=SECP256K1N._number - 1)
.map(lambda x: int.to_bytes(x, 32, "big"))
.map(PrivateKey)
)
Expand Down

0 comments on commit 0207a9d

Please sign in to comment.