@@ -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 ,
@@ -62,6 +63,7 @@ use starknet_crypto::{get_public_key, Signature};
6263use starknet_os:: hints:: hint_implementation:: deprecated_compiled_class:: class_hash:: compute_deprecated_class_hash;
6364use starknet_os:: io:: os_output:: MessageToL2 ;
6465use starknet_types_core:: felt:: Felt ;
66+ use starknet_types_core:: hash:: { Pedersen , StarkHash } ;
6567
6668use crate :: initial_state:: {
6769 create_default_initial_state_data,
@@ -889,10 +891,94 @@ async fn test_v1_bound_accounts_cairo0() {
889891#[ tokio:: test]
890892async fn test_v1_bound_accounts_cairo1 ( ) {
891893 let test_contract_sierra = & V1_BOUND_CAIRO1_CONTRACT_SIERRA ;
892- let _test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
894+ let test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
893895 let class_hash = test_contract_sierra. calculate_class_hash ( ) ;
896+ let compiled_class_hash = test_contract_casm. hash ( & HashVersion :: V2 ) ;
894897 let vc = VersionedConstants :: latest_constants ( ) ;
898+ let max_tip = vc. os_constants . v1_bound_accounts_max_tip ;
895899 assert ! ( vc. os_constants. v1_bound_accounts_cairo1. contains( & class_hash) ) ;
900+ let ( mut test_manager, _) =
901+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
902+
903+ // Declare the V1-bound account.
904+ let declare_args = declare_tx_args ! {
905+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
906+ nonce: test_manager. next_nonce( * FUNDED_ACCOUNT_ADDRESS ) ,
907+ class_hash,
908+ compiled_class_hash,
909+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
910+ } ;
911+ let account_declare_tx = declare_tx ( declare_args) ;
912+ let sierra_version = test_contract_sierra. get_sierra_version ( ) . unwrap ( ) ;
913+ let class_info = ClassInfo {
914+ contract_class : ContractClass :: V1 ( ( ( * * test_contract_casm) . clone ( ) , sierra_version. clone ( ) ) ) ,
915+ sierra_program_length : test_contract_sierra. sierra_program . len ( ) ,
916+ abi_length : test_contract_sierra. abi . len ( ) ,
917+ sierra_version,
918+ } ;
919+ let tx =
920+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
921+ test_manager. add_cairo1_declare_tx ( tx, test_contract_sierra) ;
922+
923+ // Deploy it (from funded account).
924+ let private_key = Felt :: ONE ;
925+ let public_key = get_public_key ( & private_key) ;
926+ let salt = ContractAddressSalt ( Felt :: ZERO ) ;
927+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
928+ class_hash,
929+ Calldata ( Arc :: new ( vec ! [ public_key] ) ) ,
930+ test_manager. next_nonce ( * FUNDED_ACCOUNT_ADDRESS ) ,
931+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
932+ salt,
933+ ) ;
934+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
935+
936+ // Transfer funds to the account.
937+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( max_tip) . 0 ;
938+ test_manager. add_fund_address_tx ( v1_bound_account_address, transfer_amount) ;
939+
940+ // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
941+ let invoke_tx_args = invoke_tx_args ! {
942+ sender_address: v1_bound_account_address,
943+ nonce: test_manager. next_nonce( v1_bound_account_address) ,
944+ calldata: Calldata ( Arc :: new( vec![ Felt :: ZERO ] ) ) ,
945+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
946+ } ;
947+ let invoke_tx =
948+ InvokeTransaction :: create ( invoke_tx ( invoke_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
949+ assert_eq ! ( invoke_tx. version( ) , TransactionVersion :: THREE ) ;
950+ let Signature { r, s } = ecdsa_sign ( & private_key, & invoke_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
951+ let invoke_tx_args = invoke_tx_args ! {
952+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
953+ ..invoke_tx_args
954+ } ;
955+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
896956
897- // TODO(Dori): Impl the test.
957+ // Run the test, and make sure the account storage has the expected changes.
958+ let test_output =
959+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
960+ let isrc6_id = Felt :: from_hex_unchecked (
961+ "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD" ,
962+ ) ;
963+ let expected_storage_updates = HashMap :: from ( [ (
964+ v1_bound_account_address,
965+ HashMap :: from ( [
966+ (
967+ StarknetStorageKey ( selector_from_name ( "Account_public_key" ) . 0 . try_into ( ) . unwrap ( ) ) ,
968+ StarknetStorageValue ( public_key) ,
969+ ) ,
970+ (
971+ StarknetStorageKey (
972+ Pedersen :: hash ( & selector_from_name ( "SRC5_supported_interfaces" ) . 0 , & isrc6_id)
973+ . try_into ( )
974+ . unwrap ( ) ,
975+ ) ,
976+ StarknetStorageValue ( Felt :: ONE ) ,
977+ ) ,
978+ ] ) ,
979+ ) ] ) ;
980+ let perform_global_validations = true ;
981+ let partial_state_diff =
982+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
983+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
898984}
0 commit comments