diff --git a/tests/src/kakarot/instructions/test_system_operations.cairo b/tests/src/kakarot/instructions/test_system_operations.cairo index 8ceb02280..c7af561df 100644 --- a/tests/src/kakarot/instructions/test_system_operations.cairo +++ b/tests/src/kakarot/instructions/test_system_operations.cairo @@ -8,7 +8,6 @@ from starkware.cairo.common.bool import TRUE, FALSE from starkware.cairo.common.cairo_builtins import HashBuiltin, BitwiseBuiltin from starkware.cairo.common.math import split_felt, assert_not_zero from starkware.cairo.common.uint256 import Uint256, uint256_sub -from starkware.starknet.common.syscalls import get_contract_address // Local dependencies from data_availability.starknet import Starknet @@ -615,7 +614,7 @@ func test__exec_create__should_return_a_new_context_with_bytecode_from_memory_at // Fill the stack with exec_create args let stack: model.Stack* = Stack.init(); - tempvar value = new Uint256(0, 0); + tempvar value = new Uint256(1, 0); tempvar offset = new Uint256(3, 0); tempvar size = new Uint256(4, 0); let stack = Stack.push(stack, size); @@ -632,7 +631,7 @@ func test__exec_create__should_return_a_new_context_with_bytecode_from_memory_at let bytecode_len = 0; let (bytecode: felt*) = alloc(); // As this test contract is mocking the contract account we have to set this contract address as the starknet_contract_address. - let (contract_address: felt) = get_contract_address(); + let (contract_address: felt) = Account.compute_starknet_address(evm_caller_address); let ctx = TestHelpers.init_context_at_address_with_stack( contract_address, evm_caller_address, bytecode_len, bytecode, stack ); @@ -680,6 +679,11 @@ func test__exec_create__should_return_a_new_context_with_bytecode_from_memory_at account.code_len, account.code, return_data_len, sub_ctx.return_data ); + tempvar sender_address = new model.Address(contract_address, evm_caller_address); + let (state, sender) = State.get_account(state, sender_address); + assert [sender.balance] = Uint256(0, 0); + assert [account.balance] = Uint256(1, 0); + return (); } @@ -709,7 +713,7 @@ func test__exec_create2__should_return_a_new_context_with_bytecode_from_memory_a // Fill the stack with exec_create2 args let stack: model.Stack* = Stack.init(); - tempvar value = new Uint256(0, 0); + tempvar value = new Uint256(1, 0); let stack = Stack.push_uint128(stack, nonce); let stack = Stack.push_uint128(stack, bytecode_size); let stack = Stack.push_uint128(stack, bytecode_offset); @@ -722,7 +726,8 @@ func test__exec_create2__should_return_a_new_context_with_bytecode_from_memory_a let stack = Stack.push(stack, memory_offset); let bytecode_len = 0; let (bytecode: felt*) = alloc(); - let (contract_address: felt) = get_contract_address(); + let (contract_address: felt) = Account.compute_starknet_address(evm_caller_address); + tempvar sender_address = new model.Address(contract_address, evm_caller_address); let ctx = TestHelpers.init_context_at_address_with_stack( contract_address, evm_caller_address, bytecode_len, bytecode, stack ); @@ -769,5 +774,10 @@ func test__exec_create2__should_return_a_new_context_with_bytecode_from_memory_a account.code_len, account.code, return_data_len, sub_ctx.return_data ); + let (state, sender) = State.get_account(state, sender_address); + + assert [sender.balance] = Uint256(0, 0); + assert [account.balance] = Uint256(1, 0); + return (); } diff --git a/tests/src/kakarot/instructions/test_system_operations.py b/tests/src/kakarot/instructions/test_system_operations.py index be2aa821e..1897e932b 100644 --- a/tests/src/kakarot/instructions/test_system_operations.py +++ b/tests/src/kakarot/instructions/test_system_operations.py @@ -105,7 +105,7 @@ async def test_should_return_a_new_context_based_on_calling_ctx_stack( await mint(ZERO_ACCOUNT, 2) await system_operations.test__exec_delegatecall__should_return_a_new_context_based_on_calling_ctx_stack().call() - async def test_create(self, system_operations): + async def test_create(self, system_operations, eth): salt = 0 # given we start with the first anvil test account evm_caller_address = to_checksum_address( @@ -113,6 +113,13 @@ async def test_create(self, system_operations): ) expected_create_addr = get_create_address(evm_caller_address, salt) + starknet_contract_address = ( + await system_operations.compute_starknet_address( + int(evm_caller_address, 16) + ).call() + ).result.contract_address + await eth.mint(starknet_contract_address, int_to_uint256(1)).execute() + await system_operations.test__exec_create__should_return_a_new_context_with_bytecode_from_memory_at_expected_address( int(evm_caller_address, 16), salt, @@ -133,7 +140,7 @@ async def test_create_has_deterministic_address(self, system_operations, nonce): int(expected_create_addr, 16), ).call() - async def test_create2(self, system_operations): + async def test_create2(self, system_operations, eth): # we store a memory word in memory # and have our bytecode as the memory read from an offset and size # we take that word at an offset and size and use it as the bytecode to determine the expected create2 evm contract address @@ -143,17 +150,24 @@ async def test_create2(self, system_operations): size = 4 salt = 5 padded_salt = salt.to_bytes(32, byteorder="big") - evm_caller_address_int = 15 - evm_caller_address_bytes = evm_caller_address_int.to_bytes(20, byteorder="big") - evm_caller_address = to_checksum_address(evm_caller_address_bytes) + evm_caller_address = to_checksum_address( + 0xF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266 + ) bytecode = to_bytes(memory_word)[offset : offset + size] + starknet_contract_address = ( + await system_operations.compute_starknet_address( + int(evm_caller_address, 16) + ).call() + ).result.contract_address + await eth.mint(starknet_contract_address, int_to_uint256(1)).execute() + expected_create2_addr = get_create2_address( evm_caller_address, padded_salt, bytecode ) await system_operations.test__exec_create2__should_return_a_new_context_with_bytecode_from_memory_at_expected_address( - evm_caller_address_int, + int(evm_caller_address, 16), offset, size, salt,