From 826a5906e2d29c8dd8cbb8f3fa9af6af3ded9540 Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:23:11 +0200 Subject: [PATCH] staging: fixes all possible tests (#1182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Time spent on this PR: 0.5 day Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [x] Other (please describe): tests Some of the tests fail on staging. Resolves #NA All end 2 end tests pass on staging (except for tests which must have a sequencer fee of 0). - - - This change is [Reviewable](https://reviewable.io/reviews/kkrt-labs/kakarot/1182) --- kakarot_scripts/constants.py | 27 ++++++++++--------- kakarot_scripts/utils/kakarot.py | 3 ++- kakarot_scripts/utils/starknet.py | 5 ++-- .../PlainOpcodes/test_plain_opcodes.py | 6 ++--- tests/end_to_end/test_kakarot.py | 13 ++------- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/kakarot_scripts/constants.py b/kakarot_scripts/constants.py index d5a8e4f55..adb389cb3 100644 --- a/kakarot_scripts/constants.py +++ b/kakarot_scripts/constants.py @@ -131,21 +131,22 @@ WEB3 = Web3() try: + response = requests.post( + RPC_CLIENT.url, + json={ + "jsonrpc": "2.0", + "method": "starknet_chainId", + "params": [], + "id": 0, + }, + ) + payload = json.loads(response.text) + starknet_chain_id = int(payload["result"], 16) + if WEB3.is_connected(): chain_id = WEB3.eth.chain_id else: - response = requests.post( - RPC_CLIENT.url, - json={ - "jsonrpc": "2.0", - "method": "starknet_chainId", - "params": [], - "id": 0, - }, - ) - payload = json.loads(response.text) - - chain_id = int(payload["result"], 16) + chain_id = starknet_chain_id except ( requests.exceptions.ConnectionError, requests.exceptions.MissingSchema, @@ -155,10 +156,12 @@ f"⚠️ Could not get chain Id from {NETWORK['rpc_url']}: {e}, defaulting to KKRT" ) chain_id = int.from_bytes(b"KKRT", "big") + starknet_chain_id = int.from_bytes(b"KKRT", "big") class ChainId(IntEnum): chain_id = chain_id + starknet_chain_id = starknet_chain_id NETWORK["chain_id"] = ChainId.chain_id diff --git a/kakarot_scripts/utils/kakarot.py b/kakarot_scripts/utils/kakarot.py index 2a37c51e0..dfa8febc4 100644 --- a/kakarot_scripts/utils/kakarot.py +++ b/kakarot_scripts/utils/kakarot.py @@ -33,6 +33,7 @@ NETWORK, RPC_CLIENT, WEB3, + ChainId, ) from kakarot_scripts.utils.starknet import call as _call_starknet from kakarot_scripts.utils.starknet import fund_address as _fund_starknet_address @@ -334,7 +335,7 @@ async def get_eoa(private_key=None, amount=10) -> Account: return Account( address=starknet_address, client=RPC_CLIENT, - chain=NETWORK["chain_id"], + chain=ChainId.starknet_chain_id, # This is somehow a hack because we put EVM private key into a # Stark signer KeyPair to have both a regular Starknet account # and the access to the private key diff --git a/kakarot_scripts/utils/starknet.py b/kakarot_scripts/utils/starknet.py index a94ec1e4e..8066586e0 100644 --- a/kakarot_scripts/utils/starknet.py +++ b/kakarot_scripts/utils/starknet.py @@ -45,6 +45,7 @@ RPC_CLIENT, SOURCE_DIR, ArtifactType, + ChainId, ) logging.basicConfig() @@ -122,7 +123,7 @@ async def get_starknet_account( return Account( address=address, client=RPC_CLIENT, - chain=NETWORK["chain_id"], + chain=ChainId.starknet_chain_id, key_pair=key_pair, ) @@ -347,7 +348,7 @@ async def deploy_starknet_account(class_hash=None, private_key=None, amount=1): salt=salt, key_pair=key_pair, client=RPC_CLIENT, - chain=NETWORK["chain_id"], + chain=ChainId.starknet_chain_id, constructor_calldata=constructor_calldata, max_fee=_max_fee, ) diff --git a/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py b/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py index c035f3ec3..8ad63450d 100644 --- a/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py +++ b/tests/end_to_end/PlainOpcodes/test_plain_opcodes.py @@ -36,8 +36,8 @@ async def test_should_return_starknet_timestamp( self, plain_opcodes, block_timestamp ): assert pytest.approx( - await plain_opcodes.opcodeTimestamp(), abs=10 - ) == await block_timestamp("latest") + await plain_opcodes.opcodeTimestamp(), abs=20 + ) == await block_timestamp("pending") class TestBlockhash: @pytest.mark.xfail(reason="Need to fix blockhash on real Starknet network") @@ -54,7 +54,7 @@ async def test_should_return_zero_with_invalid_block_number( self, plain_opcodes, block_number ): blockhash_invalid_number = await plain_opcodes.opcodeBlockHash( - await block_number("latest") + 1 + await block_number("latest") + 10 ) assert int.from_bytes(blockhash_invalid_number, byteorder="big") == 0 diff --git a/tests/end_to_end/test_kakarot.py b/tests/end_to_end/test_kakarot.py index eba483d5d..ab0643b05 100644 --- a/tests/end_to_end/test_kakarot.py +++ b/tests/end_to_end/test_kakarot.py @@ -58,7 +58,7 @@ async def class_hashes(): @pytest_asyncio.fixture(scope="session") -async def origin(evm: Contract): +async def origin(evm: Contract, max_fee): """ Deploys the origin's Starknet contract to the correct address. """ @@ -69,7 +69,7 @@ async def origin(evm: Contract): is_deployed = (await evm.functions["is_deployed"].call(evm_address)).deployed if is_deployed: return evm_address - tx = await evm.functions["deploy_account"].invoke_v1(evm_address, max_fee=100) + tx = await evm.functions["deploy_account"].invoke_v1(evm_address, max_fee=max_fee) await wait_for_transaction(tx.hash) return evm_address @@ -100,7 +100,6 @@ async def test_execute( params: dict, request, evm: Contract, - addresses, max_fee, origin, ): @@ -167,8 +166,6 @@ async def test_should_return_same_as_deployed_address( class TestDeployExternallyOwnedAccount: async def test_should_deploy_starknet_contract_at_corresponding_address( self, - starknet: FullNodeClient, - fund_starknet_address, deploy_externally_owned_account, compute_starknet_address, get_contract, @@ -186,11 +183,8 @@ class TestRegisterAccount: async def test_should_fail_when_sender_is_not_account( self, starknet: FullNodeClient, - fund_starknet_address, - deploy_externally_owned_account, register_account, compute_starknet_address, - get_contract, random_seed, ): evm_address = generate_random_evm_address(random_seed) @@ -204,11 +198,8 @@ async def test_should_fail_when_sender_is_not_account( async def test_should_fail_when_account_is_already_registered( self, starknet: FullNodeClient, - fund_starknet_address, deploy_externally_owned_account, register_account, - compute_starknet_address, - get_contract, ): evm_address = generate_random_evm_address(random_seed) await deploy_externally_owned_account(evm_address)