Skip to content

Commit

Permalink
feat: account_exists (#435)
Browse files Browse the repository at this point in the history
Close #422
  • Loading branch information
obatirou authored Jan 15, 2025
1 parent 406d8d0 commit e12b8cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cairo/ethereum/cancun/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,14 @@ func account_has_code_or_nonce{poseidon_ptr: PoseidonBuiltin*, state: State}(
tempvar res = bool(0);
return res;
}

func account_exists{poseidon_ptr: PoseidonBuiltin*, state: State}(address: Address) -> bool {
let account = get_account_optional(address);

if (cast(account.value, felt) == 0) {
tempvar result = bool(0);
return result;
}
tempvar result = bool(1);
return result;
}
8 changes: 8 additions & 0 deletions cairo/tests/ethereum/cancun/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ethereum.cancun.fork_types import Address
from ethereum.cancun.state import (
account_exists,
account_has_code_or_nonce,
get_account,
get_account_optional,
Expand Down Expand Up @@ -74,6 +75,13 @@ def test_account_has_code_or_nonce(self, cairo_run, data):
assert result_cairo == account_has_code_or_nonce(state, address)
assert state_cairo == state

@given(data=state_and_address_and_optional_key())
def test_account_exists(self, cairo_run, data):
state, address = data
state_cairo, result_cairo = cairo_run("account_exists", state, address)
assert result_cairo == account_exists(state, address)
assert state_cairo == state


class TestStateStorage:
@given(data=state_and_address_and_optional_key(key_strategy=bytes32))
Expand Down

0 comments on commit e12b8cc

Please sign in to comment.