Skip to content

Commit

Permalink
feat: enable registration checks (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Oct 4, 2024
1 parent f6c15f5 commit 992b891
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
6 changes: 4 additions & 2 deletions crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const INVOKE_ETH_CALL_FORBIDDEN: felt252 = 'KKT: Cannot invoke eth_call';
pub mod KakarotCore {
use core::num::traits::Zero;
use core::starknet::event::EventEmitter;
use core::starknet::get_caller_address;
use core::starknet::storage::{
Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess,
StoragePointerWriteAccess
Expand Down Expand Up @@ -184,8 +185,9 @@ pub mod KakarotCore {
assert(existing_address.is_zero(), 'Account already exists');

let starknet_address = self.compute_starknet_address(evm_address);
//TODO: enable this assertion. Will require changing test runner to snfoundry
// assert!(starknet_address == caller, "Account must be registered by the caller");
assert!(
starknet_address == get_caller_address(), "Account must be registered by the caller"
);

self.Kakarot_evm_to_starknet_address.write(evm_address, starknet_address);
self.emit(AccountDeployed { evm_address, starknet_address });
Expand Down
1 change: 0 additions & 1 deletion crates/contracts/src/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ pub fn setup_contracts_for_testing() -> (IERC20CamelDispatcher, IExtendedKakarot

let sequencer_sn_address = kakarot_core.address_registry(sequencer);
start_cheat_sequencer_address_global(sequencer_sn_address);
start_cheat_caller_address_global(kakarot_core.contract_address);
start_cheat_chain_id_global(chain_id().into());
return (native_token, kakarot_core);
}
2 changes: 0 additions & 2 deletions crates/contracts/tests/test_execution_from_outside.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ fn set_up() -> (IExtendedKakarotCoreDispatcher, IAccountDispatcher, IERC20CamelD
let eoa = IAccountDispatcher {
contract_address: kakarot_core.deploy_externally_owned_account(transaction_signer())
};
start_cheat_caller_address_global(kakarot_core.contract_address);

start_cheat_block_timestamp(eoa.contract_address, 999);
start_cheat_chain_id_global(chain_id().into());

Expand Down
5 changes: 2 additions & 3 deletions 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, load
cheat_caller_address, CheatSpan, store, load, stop_cheat_caller_address_global
};
use snforge_utils::snforge_utils::{EventsFilterBuilderTrait, ContractEventsTrait};
use starknet::storage::StorageTrait;
Expand Down Expand Up @@ -274,7 +274,6 @@ fn test_eth_call() {

let evm_address = test_utils::evm_address();
kakarot_core.deploy_externally_owned_account(evm_address);

let account = contract_utils::deploy_contract_account(
kakarot_core, test_utils::other_evm_address(), counter_evm_bytecode()
);
Expand Down Expand Up @@ -326,7 +325,7 @@ fn test_eth_send_transaction_deploy_tx() {
gas_limit,
input: deploy_counter_calldata()
};
start_cheat_caller_address(kakarot_core.contract_address, eoa);
cheat_caller_address(kakarot_core.contract_address, eoa, CheatSpan::TargetCalls(1));
let (_, deploy_result, _) = kakarot_core.eth_send_transaction(Transaction::Legacy(tx));

// Then
Expand Down

0 comments on commit 992b891

Please sign in to comment.