From 43d3c04a1888a222215024d6bd6c7170a4314c09 Mon Sep 17 00:00:00 2001 From: Oba Date: Tue, 12 Nov 2024 17:30:47 +0100 Subject: [PATCH] Fix test NoDelegateCall --- cairo_zero/kakarot/precompiles/precompiles_helpers.cairo | 2 +- .../tests/src/kakarot/precompiles/test_precompiles.py | 5 ++--- .../CairoPrecompiles/test_call_cairo_precompile.py | 6 ++---- .../CairoPrecompiles/test_multicall_cairo_precompile.py | 6 ++---- tests/end_to_end/Security/test_dual_vm_token_hack.py | 9 +++++++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cairo_zero/kakarot/precompiles/precompiles_helpers.cairo b/cairo_zero/kakarot/precompiles/precompiles_helpers.cairo index d86cfd3dc..71af22851 100644 --- a/cairo_zero/kakarot/precompiles/precompiles_helpers.cairo +++ b/cairo_zero/kakarot/precompiles/precompiles_helpers.cairo @@ -105,7 +105,7 @@ namespace PrecompilesHelpers { let range_check_ptr = [ap - 2]; let authorized = [ap - 1]; - // Ensure that calls to CAIRO_CALL_PRECOMPILE or CAIRO_CALL_PRECOMPILE are not made through + // Ensure that calls to CAIRO_CALL_PRECOMPILE or CAIRO_MULTICALL_PRECOMPILE are not made through // a delegatecall / callcode. let is_delegatecall_protected_ = is_delegatecall_protected(precompile_address); if (is_delegatecall_protected_ != FALSE) { diff --git a/cairo_zero/tests/src/kakarot/precompiles/test_precompiles.py b/cairo_zero/tests/src/kakarot/precompiles/test_precompiles.py index 42440057c..eaec65405 100644 --- a/cairo_zero/tests/src/kakarot/precompiles/test_precompiles.py +++ b/cairo_zero/tests/src/kakarot/precompiles/test_precompiles.py @@ -110,8 +110,7 @@ def test_should_deploy_account_when_sender_starknet_address_zero( assert bytes(return_data) == b"" assert gas_used == CAIRO_PRECOMPILE_GAS - SyscallHandler.mock_deploy.assert_called_once() - return + assert SyscallHandler.mock_deploy.call_count == 1 @SyscallHandler.patch( "Kakarot_authorized_cairo_precompiles_callers", @@ -121,7 +120,7 @@ def test_should_deploy_account_when_sender_starknet_address_zero( @SyscallHandler.patch( "Kakarot_evm_to_starknet_address", CALLER_ADDRESS, 0x1234 ) - @SyscallHandler.mock_deploy(lambda *_: [0]) + @SyscallHandler.patch("deploy", lambda *_: [0]) @pytest.mark.parametrize( "address, caller_address, input_data, expected_return_data, expected_reverted", [ diff --git a/tests/end_to_end/CairoPrecompiles/test_call_cairo_precompile.py b/tests/end_to_end/CairoPrecompiles/test_call_cairo_precompile.py index 640bd79cf..898e6ea93 100644 --- a/tests/end_to_end/CairoPrecompiles/test_call_cairo_precompile.py +++ b/tests/end_to_end/CairoPrecompiles/test_call_cairo_precompile.py @@ -5,7 +5,7 @@ from kakarot_scripts.constants import NETWORK from kakarot_scripts.utils.kakarot import deploy, eth_send_transaction from kakarot_scripts.utils.starknet import get_contract, invoke -from tests.utils.errors import cairo_error +from tests.utils.errors import cairo_error, evm_error CALL_CAIRO_PRECOMPILE = 0x75004 @@ -101,9 +101,7 @@ async def test_should_fail_when_called_with_delegatecall( async def test_should_fail_when_called_with_callcode( self, cairo_counter_caller ): - with cairo_error( - "EVM tx reverted, reverting SN tx because of previous calls to cairo precompiles" - ): + with evm_error("CairoLib: call_contract failed with"): await cairo_counter_caller.incrementCairoCounterCallcode() @pytest.mark.skipif( diff --git a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py index b1d2c6611..d7b09822f 100644 --- a/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py +++ b/tests/end_to_end/CairoPrecompiles/test_multicall_cairo_precompile.py @@ -8,7 +8,7 @@ from kakarot_scripts.utils.kakarot import deploy, eth_send_transaction from kakarot_scripts.utils.starknet import get_contract, invoke -from tests.utils.errors import cairo_error +from tests.utils.errors import cairo_error, evm_error @pytest_asyncio.fixture(scope="module") @@ -124,7 +124,5 @@ async def test_should_fail_when_called_with_delegatecall( async def test_should_fail_when_called_with_callcode( self, multicall_cairo_counter_caller ): - with cairo_error( - "EVM tx reverted, reverting SN tx because of previous calls to cairo precompiles" - ): + with evm_error("CairoLib: call_contract failed with"): await multicall_cairo_counter_caller.incrementCairoCounterCallcode() diff --git a/tests/end_to_end/Security/test_dual_vm_token_hack.py b/tests/end_to_end/Security/test_dual_vm_token_hack.py index 1b710a63a..1331df887 100644 --- a/tests/end_to_end/Security/test_dual_vm_token_hack.py +++ b/tests/end_to_end/Security/test_dual_vm_token_hack.py @@ -13,10 +13,15 @@ logger.setLevel(logging.INFO) -@pytest_asyncio.fixture(scope="function") +@pytest_asyncio.fixture(scope="package") async def starknet_token(owner): address = await deploy_starknet( - "StarknetToken", int(1e18), owner.starknet_contract.address + "StarknetToken", + "MyToken", + "MTK", + 18, + int(2**256 - 1), + owner.starknet_contract.address, ) return get_contract_starknet("StarknetToken", address=address)