@@ -8,7 +8,8 @@ use blockifier_test_utils::calldata::create_calldata;
88use blockifier_test_utils:: contracts:: FeatureContract ;
99use rstest:: rstest;
1010use starknet_api:: abi:: abi_utils:: { get_storage_var_address, selector_from_name} ;
11- use starknet_api:: contract_class:: compiled_class_hash:: HashVersion ;
11+ use starknet_api:: contract_class:: compiled_class_hash:: { HashVersion , HashableCompiledClass } ;
12+ use starknet_api:: contract_class:: { ClassInfo , ContractClass } ;
1213use starknet_api:: core:: {
1314 calculate_contract_address,
1415 ClassHash ,
@@ -63,6 +64,7 @@ use starknet_crypto::{get_public_key, Signature};
6364use starknet_os:: hints:: hint_implementation:: deprecated_compiled_class:: class_hash:: compute_deprecated_class_hash;
6465use starknet_os:: io:: os_output:: MessageToL2 ;
6566use starknet_types_core:: felt:: Felt ;
67+ use starknet_types_core:: hash:: { Pedersen , StarkHash } ;
6668
6769use crate :: initial_state:: {
6870 create_default_initial_state_data,
@@ -840,10 +842,94 @@ async fn test_v1_bound_accounts_cairo0() {
840842#[ tokio:: test]
841843async fn test_v1_bound_accounts_cairo1 ( ) {
842844 let test_contract_sierra = & V1_BOUND_CAIRO1_CONTRACT_SIERRA ;
843- let _test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
845+ let test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
844846 let class_hash = test_contract_sierra. calculate_class_hash ( ) ;
847+ let compiled_class_hash = test_contract_casm. hash ( & HashVersion :: V2 ) ;
845848 let vc = VersionedConstants :: latest_constants ( ) ;
849+ let max_tip = vc. os_constants . v1_bound_accounts_max_tip ;
846850 assert ! ( vc. os_constants. v1_bound_accounts_cairo1. contains( & class_hash) ) ;
851+ let ( mut test_manager, _) =
852+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
853+
854+ // Declare the V1-bound account.
855+ let declare_args = declare_tx_args ! {
856+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
857+ nonce: test_manager. next_nonce( * FUNDED_ACCOUNT_ADDRESS ) ,
858+ class_hash,
859+ compiled_class_hash,
860+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
861+ } ;
862+ let account_declare_tx = declare_tx ( declare_args) ;
863+ let sierra_version = test_contract_sierra. get_sierra_version ( ) . unwrap ( ) ;
864+ let class_info = ClassInfo {
865+ contract_class : ContractClass :: V1 ( ( ( * * test_contract_casm) . clone ( ) , sierra_version. clone ( ) ) ) ,
866+ sierra_program_length : test_contract_sierra. sierra_program . len ( ) ,
867+ abi_length : test_contract_sierra. abi . len ( ) ,
868+ sierra_version,
869+ } ;
870+ let tx =
871+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
872+ test_manager. add_cairo1_declare_tx ( tx, test_contract_sierra) ;
873+
874+ // Deploy it (from funded account).
875+ let private_key = Felt :: ONE ;
876+ let public_key = get_public_key ( & private_key) ;
877+ let salt = Felt :: ZERO ;
878+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
879+ class_hash,
880+ Calldata ( Arc :: new ( vec ! [ public_key] ) ) ,
881+ test_manager. next_nonce ( * FUNDED_ACCOUNT_ADDRESS ) ,
882+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
883+ salt,
884+ ) ;
885+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
886+
887+ // Transfer funds to the account.
888+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( max_tip) . 0 ;
889+ test_manager. add_fund_address_tx ( v1_bound_account_address, transfer_amount) ;
890+
891+ // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
892+ let invoke_tx_args = invoke_tx_args ! {
893+ sender_address: v1_bound_account_address,
894+ nonce: test_manager. next_nonce( v1_bound_account_address) ,
895+ calldata: Calldata ( Arc :: new( vec![ Felt :: ZERO ] ) ) ,
896+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
897+ } ;
898+ let invoke_tx =
899+ InvokeTransaction :: create ( invoke_tx ( invoke_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
900+ assert_eq ! ( invoke_tx. version( ) , TransactionVersion :: THREE ) ;
901+ let Signature { r, s } = ecdsa_sign ( & private_key, & invoke_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
902+ let invoke_tx_args = invoke_tx_args ! {
903+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
904+ ..invoke_tx_args
905+ } ;
906+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
847907
848- // TODO(Dori): Impl the test.
908+ // Run the test, and make sure the account storage has the expected changes.
909+ let test_output =
910+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
911+ let isrc6_id = Felt :: from_hex_unchecked (
912+ "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD" ,
913+ ) ;
914+ let expected_storage_updates = HashMap :: from ( [ (
915+ v1_bound_account_address,
916+ HashMap :: from ( [
917+ (
918+ StarknetStorageKey ( selector_from_name ( "Account_public_key" ) . 0 . try_into ( ) . unwrap ( ) ) ,
919+ StarknetStorageValue ( public_key) ,
920+ ) ,
921+ (
922+ StarknetStorageKey (
923+ Pedersen :: hash ( & selector_from_name ( "SRC5_supported_interfaces" ) . 0 , & isrc6_id)
924+ . try_into ( )
925+ . unwrap ( ) ,
926+ ) ,
927+ StarknetStorageValue ( Felt :: ONE ) ,
928+ ) ,
929+ ] ) ,
930+ ) ] ) ;
931+ let perform_global_validations = true ;
932+ let partial_state_diff =
933+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
934+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
849935}
0 commit comments