Skip to content

Commit

Permalink
test: get_starknet_address (#1006)
Browse files Browse the repository at this point in the history
* test_kakarot_core_get_starknet_address

* ci: downgrade cairo native (#1008)

* dev: use checked math (#1009)

* fix get_starknet_address test

---------

Co-authored-by: Mathieu <[email protected]>
  • Loading branch information
saimeunt and enitrat authored Oct 2, 2024
1 parent dcbb421 commit 7048c0d
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion crates/contracts/tests/test_kakarot_core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use evm::test_utils::chain_id;
use evm::test_utils;
use snforge_std::{
declare, DeclareResultTrait, start_cheat_caller_address, spy_events, EventSpyTrait,
cheat_caller_address, CheatSpan, store
cheat_caller_address, CheatSpan, store, load
};
use snforge_utils::snforge_utils::{EventsFilterBuilderTrait, ContractEventsTrait};
use starknet::storage::StorageTrait;
Expand Down Expand Up @@ -159,6 +159,49 @@ fn test_kakarot_core_upgrade_contract() {
assert(version == 1, 'version is not 1');
}

#[test]
fn test_kakarot_core_get_starknet_address() {
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let mut kakarot_state = KakarotCore::unsafe_new_contract_state();

let registered_evm_address = test_utils::evm_address();
let registered_starknet_address = test_utils::starknet_address();
let registered_map_entry_address = kakarot_state
.snapshot_deref()
.storage()
.Kakarot_evm_to_starknet_address
.entry(registered_evm_address)
.deref()
.__storage_pointer_address__;
// store the registered address in the mapping
store(
kakarot_core.contract_address,
registered_map_entry_address.into(),
[registered_starknet_address.into()].span()
);
// when the address is registered in the mapping, it's returned
assert_eq!(
kakarot_core.get_starknet_address(registered_evm_address), registered_starknet_address
);

let unregistered_evm_address = test_utils::other_evm_address();
let unregistered_map_entry_address = kakarot_state
.snapshot_deref()
.storage()
.Kakarot_evm_to_starknet_address
.entry(unregistered_evm_address)
.deref()
.__storage_pointer_address__;
let map_data = load(kakarot_core.contract_address, unregistered_map_entry_address.into(), 1);
// when the map entry is empty
assert_eq!(*map_data[0], 0);
// then an unregistered address should return the same as compute_starknet_address
assert_eq!(
kakarot_core.get_starknet_address(unregistered_evm_address),
kakarot_core.compute_starknet_address(unregistered_evm_address)
);
}

#[test]
fn test_eth_send_transaction_non_deploy_tx() {
// Given
Expand Down

0 comments on commit 7048c0d

Please sign in to comment.