@@ -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,
@@ -958,10 +960,107 @@ async fn test_v1_bound_accounts_cairo0() {
958960#[ tokio:: test]
959961async fn test_v1_bound_accounts_cairo1 ( ) {
960962 let test_contract_sierra = & V1_BOUND_CAIRO1_CONTRACT_SIERRA ;
961- let _test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
963+ let test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
962964 let class_hash = test_contract_sierra. calculate_class_hash ( ) ;
965+ let compiled_class_hash = test_contract_casm. hash ( & HashVersion :: V2 ) ;
963966 let vc = VersionedConstants :: latest_constants ( ) ;
967+ let max_tip = vc. os_constants . v1_bound_accounts_max_tip ;
964968 assert ! ( vc. os_constants. v1_bound_accounts_cairo1. contains( & class_hash) ) ;
969+ let ( mut test_manager, mut nonce_manager, _) =
970+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
971+
972+ // Declare the V1-bound account.
973+ let declare_args = declare_tx_args ! {
974+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
975+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
976+ class_hash,
977+ compiled_class_hash,
978+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
979+ } ;
980+ let account_declare_tx = declare_tx ( declare_args) ;
981+ let sierra_version = test_contract_sierra. get_sierra_version ( ) . unwrap ( ) ;
982+ let class_info = ClassInfo {
983+ contract_class : ContractClass :: V1 ( (
984+ ( & * * test_contract_casm) . clone ( ) ,
985+ sierra_version. clone ( ) ,
986+ ) ) ,
987+ sierra_program_length : test_contract_sierra. sierra_program . len ( ) ,
988+ abi_length : test_contract_sierra. abi . len ( ) ,
989+ sierra_version,
990+ } ;
991+ let tx =
992+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
993+ test_manager. add_cairo1_declare_tx ( tx, test_contract_sierra) ;
994+
995+ // Deploy it (from funded account).
996+ let private_key = Felt :: ONE ;
997+ let public_key = get_public_key ( & private_key) ;
998+ let salt = Felt :: ZERO ;
999+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
1000+ class_hash,
1001+ Calldata ( Arc :: new ( vec ! [ public_key] ) ) ,
1002+ nonce_manager. next ( * FUNDED_ACCOUNT_ADDRESS ) ,
1003+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
1004+ salt,
1005+ ) ;
1006+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
9651007
966- // TODO(Dori): Impl the test.
1008+ // Transfer funds to the account.
1009+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( max_tip) . 0 ;
1010+ let transfer_tx_args = invoke_tx_args ! {
1011+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
1012+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
1013+ calldata: create_calldata(
1014+ * STRK_FEE_TOKEN_ADDRESS ,
1015+ "transfer" ,
1016+ & [ * * v1_bound_account_address, Felt :: from( transfer_amount) , Felt :: ZERO ]
1017+ ) ,
1018+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1019+ } ;
1020+ test_manager. add_invoke_tx_from_args ( transfer_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
1021+
1022+ // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
1023+ let invoke_tx_args = invoke_tx_args ! {
1024+ sender_address: v1_bound_account_address,
1025+ nonce: nonce_manager. next( v1_bound_account_address) ,
1026+ calldata: Calldata ( Arc :: new( vec![ Felt :: ZERO ] ) ) ,
1027+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1028+ } ;
1029+ let invoke_tx =
1030+ InvokeTransaction :: create ( invoke_tx ( invoke_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1031+ assert_eq ! ( invoke_tx. version( ) , TransactionVersion :: THREE ) ;
1032+ let Signature { r, s } = ecdsa_sign ( & private_key, & invoke_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
1033+ let invoke_tx_args = invoke_tx_args ! {
1034+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
1035+ ..invoke_tx_args
1036+ } ;
1037+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
1038+
1039+ // Run the test, and make sure the account storage has the expected changes.
1040+ let test_output =
1041+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
1042+ let isrc6_id = Felt :: from_hex_unchecked (
1043+ "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD" ,
1044+ ) ;
1045+ let expected_storage_updates = HashMap :: from ( [ (
1046+ v1_bound_account_address,
1047+ HashMap :: from ( [
1048+ (
1049+ StarknetStorageKey ( selector_from_name ( "Account_public_key" ) . 0 . try_into ( ) . unwrap ( ) ) ,
1050+ StarknetStorageValue ( public_key) ,
1051+ ) ,
1052+ (
1053+ StarknetStorageKey (
1054+ Pedersen :: hash ( & selector_from_name ( "SRC5_supported_interfaces" ) . 0 , & isrc6_id)
1055+ . try_into ( )
1056+ . unwrap ( ) ,
1057+ ) ,
1058+ StarknetStorageValue ( Felt :: ONE ) ,
1059+ ) ,
1060+ ] ) ,
1061+ ) ] ) ;
1062+ let perform_global_validations = true ;
1063+ let partial_state_diff =
1064+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
1065+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
9671066}
0 commit comments