diff --git a/tests/end_to_end/bytecodes.py b/tests/end_to_end/bytecodes.py index 8ecd71098..11007e19d 100644 --- a/tests/end_to_end/bytecodes.py +++ b/tests/end_to_end/bytecodes.py @@ -1798,7 +1798,7 @@ "value": 0, "code": "3000", "calldata": "", - "stack": f"""{int.from_bytes(b"target_evm_address", "big")}""", + "stack": "{account_address}", "memory": "", "return_data": "", "success": 1, diff --git a/tests/end_to_end/test_kakarot.py b/tests/end_to_end/test_kakarot.py index 169ec17d7..140fa8b41 100644 --- a/tests/end_to_end/test_kakarot.py +++ b/tests/end_to_end/test_kakarot.py @@ -60,15 +60,16 @@ async def class_hashes(): @pytest_asyncio.fixture(scope="session") async def origin(evm: Contract, addresses): """ - Deploys the origin's Starknet contract to the correct address and funds it. + Deploys the origin's Starknet contract to the correct address. """ - from kakarot_scripts.utils.starknet import fund_address - - evm_address = int(addresses[0].address, 16) - sn_address = ( - await evm.functions["compute_starknet_address"].call(evm_address) - ).contract_address - await fund_address(sn_address, 10) + from tests.utils.helpers import generate_random_private_key + + private_key = generate_random_private_key() + evm_address = int(private_key.public_key.to_checksum_address(), 16) + is_deployed = (await evm.functions["is_deployed"].call(evm_address)).deployed + if is_deployed: + return evm_address + await evm.functions["deploy_account"].invoke_v1(evm_address, max_fee=100) return evm_address @@ -116,7 +117,7 @@ async def test_execute( int(x) for x in params["stack"] .format( - account_address=int(addresses[0].address, 16), + account_address=origin, timestamp=result.block_timestamp, block_number=result.block_number, ) diff --git a/tests/fixtures/EVM.cairo b/tests/fixtures/EVM.cairo index ecc10c0c4..7bb303404 100644 --- a/tests/fixtures/EVM.cairo +++ b/tests/fixtures/EVM.cairo @@ -52,11 +52,12 @@ func execute{ ) -> (model.EVM*, model.Stack*, model.Memory*, model.State*, felt) { alloc_locals; // Deploy target account - let evm_address = 'target_evm_address'; - let (starknet_address) = Starknet.deploy(evm_address); + let evm_address = env.origin; + let starknet_address = Account.compute_starknet_address(evm_address); tempvar address = new model.Address(starknet_address, evm_address); - // Write the valid jumpdests in the storage of the executed contract + // Write the valid jumpdests in the storage of the executed contract. + // This requires the origin account to be deployed prior to the execution. let (valid_jumpdests_start, valid_jumpdests) = Helpers.initialize_jumpdests( bytecode_len, bytecode ); @@ -191,6 +192,25 @@ func evm_execute{ return result; } +@external +func deploy_account{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( + evm_address: felt +) -> (contract_address: felt) { + let (starknet_address) = Starknet.deploy(evm_address); + return (contract_address=starknet_address); +} + +@view +func is_deployed{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( + evm_address: felt +) -> (deployed: felt) { + let (starknet_address) = Kakarot_evm_to_starknet_address.read(evm_address); + if (starknet_address == 0) { + return (deployed=0); + } + return (deployed=1); +} + // @notice Compute the starknet address of a contract given its EVM address // @param evm_address The EVM address of the contract // @return contract_address The starknet address of the contract