Skip to content

Commit

Permalink
test: chain_id test moved to kakarot
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou committed Aug 26, 2024
1 parent 783aae6 commit 4b5eb93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
23 changes: 1 addition & 22 deletions tests/src/kakarot/instructions/test_block_information.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections import OrderedDict
from unittest.mock import patch

import pytest

from kakarot_scripts.constants import COINBASE
from tests.utils.constants import BIG_CHAIN_ID, BLOCK_GAS_LIMIT, CHAIN_ID, Opcodes
from tests.utils.constants import BLOCK_GAS_LIMIT, CHAIN_ID, Opcodes
from tests.utils.syscall_handler import SyscallHandler


Expand All @@ -29,23 +28,3 @@ class TestBlockInformation:
def test__exec_block_information(self, cairo_run, opcode, expected_result):
output = cairo_run("test__exec_block_information", opcode=opcode)
assert output == hex(expected_result)

@patch.object(
SyscallHandler,
"tx_info",
OrderedDict(
{
"version": 1,
"account_contract_address": 0xABDE1,
"max_fee": int(1e17),
"signature_len": None,
"signature": [],
"transaction_hash": 0xABDE1,
"chain_id": BIG_CHAIN_ID,
"nonce": 1,
}
),
)
def test__exec_chain_id__should_return_mod_53(self, cairo_run):
output = cairo_run("test__exec_block_information", opcode=Opcodes.CHAINID)
assert output == hex(BIG_CHAIN_ID % 2**53)
5 changes: 5 additions & 0 deletions tests/src/kakarot/test_kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ func test__set_cairo1_helpers_class_hash{
set_cairo1_helpers_class_hash(value);
return ();
}

func test__chain_id{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> felt {
let (chain_id) = Kakarot.eth_chain_id();
return chain_id;
}
10 changes: 10 additions & 0 deletions tests/src/kakarot/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from eth_abi import decode, encode
from eth_utils import keccak
from eth_utils.address import to_checksum_address
from hypothesis import given
from hypothesis.strategies import integers
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME
from starkware.starknet.public.abi import get_storage_var_address
from web3._utils.abi import map_abi_data
from web3._utils.normalizers import BASE_RETURN_NORMALIZERS
Expand Down Expand Up @@ -405,6 +408,13 @@ def test_failing_contract(self, cairo_run):
)
assert not evm["reverted"]

class TestEthChainIdEntrypoint:
@given(chain_id=integers(min_value=0, max_value=DEFAULT_PRIME - 1))
def test_should_return_chain_id(self, cairo_run, chain_id):
with patch.dict(SyscallHandler.tx_info, {"chain_id": chain_id}):
res = cairo_run("test__chain_id")
assert res == chain_id % 2**53

class TestLoopProfiling:
@pytest.mark.slow
@pytest.mark.NoCI
Expand Down

0 comments on commit 4b5eb93

Please sign in to comment.