Skip to content

Commit

Permalink
fix end-to-end test requiring account deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Apr 30, 2024
1 parent 6bc402e commit 69d8511
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/end_to_end/bytecodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 10 additions & 9 deletions tests/end_to_end/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
)
Expand Down
26 changes: 23 additions & 3 deletions tests/fixtures/EVM.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 69d8511

Please sign in to comment.