Skip to content

Commit

Permalink
dev: limit examples for slow tests (#366)
Browse files Browse the repository at this point in the history
Part of #318 

For test > 2000s from
https://github.com/kkrt-labs/keth/actions/runs/12526214515/job/34938536446,
mark those test slow and set the max example to 300.
At time of writing the max_examples for nightly is 1500 hence a division
by 5 but still more than the main ci (which is 100)
  • Loading branch information
obatirou authored Jan 6, 2025
1 parent d608c8b commit d6c1657
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cairo/tests/ethereum/cancun/test_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from ethereum_types.bytes import Bytes
from ethereum_types.numeric import Uint
from hypothesis import assume, given
from hypothesis import assume, given, settings
from hypothesis import strategies as st

from ethereum.cancun.fork_types import Account
Expand All @@ -30,6 +30,8 @@ def test_encode_internal_node(self, cairo_run, node: Optional[InternalNode]):
encode_internal_node(node), cairo_run("encode_internal_node", node)
)

@pytest.mark.slow
@settings(max_examples=300)
@given(node=..., storage_root=...)
def test_encode_node(self, cairo_run, node: Node, storage_root: Optional[Bytes]):
assume(node is not None)
Expand Down Expand Up @@ -138,6 +140,8 @@ def test_get_branches(self, cairo_run, obj, level):
)
assert value == obj.get(level, b"")

@pytest.mark.slow
@settings(max_examples=300)
@given(obj=st.dictionaries(nibble, bytes32))
def test_patricialize(self, cairo_run, obj: Mapping[Bytes, Bytes]):
assert patricialize(obj, Uint(0)) == cairo_run("patricialize", obj, Uint(0))
14 changes: 13 additions & 1 deletion cairo/tests/ethereum/test_rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
from ethereum_types.numeric import U256, Uint
from hypothesis import assume, given
from hypothesis import assume, given, settings

from ethereum.cancun.blocks import Log, Receipt, Withdrawal
from ethereum.cancun.fork_types import Account, Address, Bloom, encode_account
Expand Down Expand Up @@ -48,12 +48,16 @@ def test_encode_u256_little(self, cairo_run, raw_uint256: U256):
def test_encode_bytes(self, cairo_run, raw_bytes: Bytes):
assert encode_bytes(raw_bytes) == cairo_run("encode_bytes", raw_bytes)

@pytest.mark.slow
@settings(max_examples=300)
@given(raw_sequence=...)
def test_encode_sequence(self, cairo_run, raw_sequence: Sequence[Extended]):
assert encode_sequence(raw_sequence) == cairo_run(
"encode_sequence", raw_sequence
)

@pytest.mark.slow
@settings(max_examples=300)
@given(raw_sequence=...)
def test_get_joined_encodings(
self, cairo_run, raw_sequence: Sequence[Extended]
Expand Down Expand Up @@ -98,10 +102,14 @@ def test_encode_account(
def test_encode_legacy_transaction(self, cairo_run, tx: LegacyTransaction):
assert encode(tx) == cairo_run("encode_legacy_transaction", tx)

@pytest.mark.slow
@settings(max_examples=300)
@given(log=...)
def test_encode_log(self, cairo_run, log: Log):
assert encode(log) == cairo_run("encode_log", log)

@pytest.mark.slow
@settings(max_examples=300)
@given(tuple_log=...)
def test_encode_tuple_log(self, cairo_run, tuple_log: Tuple[Log, ...]):
assert encode(tuple_log) == cairo_run("encode_tuple_log", tuple_log)
Expand All @@ -110,6 +118,8 @@ def test_encode_tuple_log(self, cairo_run, tuple_log: Tuple[Log, ...]):
def test_encode_bloom(self, cairo_run, bloom: Bloom):
assert encode(bloom) == cairo_run("encode_bloom", bloom)

@pytest.mark.slow
@settings(max_examples=300)
@given(receipt=...)
def test_encode_receipt(self, cairo_run, receipt: Receipt):
assert encode(receipt) == cairo_run("encode_receipt", receipt)
Expand Down Expand Up @@ -145,6 +155,8 @@ def test_decode_to_bytes_should_raise(self, cairo_run, encoded_bytes: Bytes):
if decoded_bytes is not None:
assert decoded_bytes == decode_to_bytes(encoded_bytes)

@pytest.mark.slow
@settings(max_examples=300)
@given(raw_data=...)
def test_decode_to_sequence(self, cairo_run, raw_data: Sequence[Extended]):
assume(isinstance(raw_data, list))
Expand Down
4 changes: 3 additions & 1 deletion cairo/tests/programs/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from eth_abi.abi import encode
from ethereum_types.numeric import U256
from hexbytes import HexBytes
from hypothesis import given
from hypothesis import given, settings
from hypothesis.strategies import integers

from ethereum.crypto.elliptic_curve import SECP256K1N
Expand Down Expand Up @@ -274,6 +274,8 @@ def test_create_tx_returndata(self, cairo_run):
== state["accounts"]["0x32dCAB0EF3FB2De2fce1D2E0799D36239671F04A"]["code"]
)

@pytest.mark.slow
@settings(max_examples=300)
@given(nonce=integers(min_value=2**64, max_value=2**248 - 1))
def test_should_raise_when_nonce_is_greater_u64(self, cairo_run, nonce):
initial_state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from Crypto.Hash import keccak
from hypothesis import example, given
from hypothesis import example, given, settings
from hypothesis import strategies as st

EXISTING_ACCOUNT = 0xABDE1
Expand Down Expand Up @@ -69,6 +69,8 @@ def test_exec_copy_should_copy_code(
== copied_bytecode
)

@pytest.mark.slow
@settings(max_examples=300)
@given(
opcode_number=st.sampled_from([0x39, 0x37]),
offset=st.integers(0, 2**128 - 1),
Expand Down
3 changes: 2 additions & 1 deletion cairo/tests/src/precompiles/test_ripemd160.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from Crypto.Hash import RIPEMD160
from hypothesis import example, given
from hypothesis import example, given, settings
from hypothesis.strategies import binary

from tests.utils.errors import cairo_error
Expand All @@ -9,6 +9,7 @@

@pytest.mark.slow
class TestRIPEMD160:
@settings(max_examples=300)
@given(msg_bytes=binary(min_size=1, max_size=200))
@example(msg_bytes=b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmomnopnopq")
def test_ripemd160_should_return_correct_hash(self, cairo_run, msg_bytes):
Expand Down
4 changes: 3 additions & 1 deletion cairo/tests/src/utils/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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 given, settings
from hypothesis import strategies as st
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

Expand All @@ -28,6 +28,7 @@ def test__public_key_point_to_eth_address(

class TestVerifyEthSignature:
@pytest.mark.slow
@settings(max_examples=300)
@given(private_key=..., message=...)
def test__verify_eth_signature_uint256(
self, cairo_run, private_key: PrivateKey, message: Bytes32
Expand Down Expand Up @@ -123,6 +124,7 @@ def test_should_raise_with_out_of_bounds_s(

class TestTryRecoverEthAddress:
@pytest.mark.slow
@settings(max_examples=300)
@given(private_key=..., message=...)
def test__try_recover_eth_address(
self, cairo_run, private_key: PrivateKey, message: Bytes32
Expand Down

0 comments on commit d6c1657

Please sign in to comment.