@@ -8,7 +8,8 @@ use blockifier_test_utils::calldata::create_calldata;
8
8
use blockifier_test_utils:: contracts:: FeatureContract ;
9
9
use rstest:: rstest;
10
10
use 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 } ;
12
13
use starknet_api:: core:: {
13
14
calculate_contract_address,
14
15
ClassHash ,
@@ -63,6 +64,7 @@ use starknet_crypto::{get_public_key, Signature};
63
64
use starknet_os:: hints:: hint_implementation:: deprecated_compiled_class:: class_hash:: compute_deprecated_class_hash;
64
65
use starknet_os:: io:: os_output:: MessageToL2 ;
65
66
use starknet_types_core:: felt:: Felt ;
67
+ use starknet_types_core:: hash:: { Pedersen , StarkHash } ;
66
68
67
69
use crate :: initial_state:: {
68
70
create_default_initial_state_data,
@@ -73,7 +75,12 @@ use crate::special_contracts::{
73
75
V1_BOUND_CAIRO1_CONTRACT_CASM ,
74
76
V1_BOUND_CAIRO1_CONTRACT_SIERRA ,
75
77
} ;
76
- use crate :: test_manager:: { TestManager , TestParameters , FUNDED_ACCOUNT_ADDRESS } ;
78
+ use crate :: test_manager:: {
79
+ TestManager ,
80
+ TestParameters ,
81
+ FUNDED_ACCOUNT_ADDRESS ,
82
+ STRK_FEE_TOKEN_ADDRESS ,
83
+ } ;
77
84
use crate :: utils:: {
78
85
divide_vec_into_n_parts,
79
86
get_class_hash_of_feature_contract,
@@ -961,10 +968,107 @@ async fn test_v1_bound_accounts_cairo0() {
961
968
#[ tokio:: test]
962
969
async fn test_v1_bound_accounts_cairo1 ( ) {
963
970
let test_contract_sierra = & V1_BOUND_CAIRO1_CONTRACT_SIERRA ;
964
- let _test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
971
+ let test_contract_casm = & V1_BOUND_CAIRO1_CONTRACT_CASM ;
965
972
let class_hash = test_contract_sierra. calculate_class_hash ( ) ;
973
+ let compiled_class_hash = test_contract_casm. hash ( & HashVersion :: V2 ) ;
966
974
let vc = VersionedConstants :: latest_constants ( ) ;
975
+ let max_tip = vc. os_constants . v1_bound_accounts_max_tip ;
967
976
assert ! ( vc. os_constants. v1_bound_accounts_cairo1. contains( & class_hash) ) ;
977
+ let ( mut test_manager, mut nonce_manager, _) =
978
+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
979
+
980
+ // Declare the V1-bound account.
981
+ let declare_args = declare_tx_args ! {
982
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
983
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
984
+ class_hash,
985
+ compiled_class_hash,
986
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
987
+ } ;
988
+ let account_declare_tx = declare_tx ( declare_args) ;
989
+ let sierra_version = test_contract_sierra. get_sierra_version ( ) . unwrap ( ) ;
990
+ let class_info = ClassInfo {
991
+ contract_class : ContractClass :: V1 ( (
992
+ ( & * * test_contract_casm) . clone ( ) ,
993
+ sierra_version. clone ( ) ,
994
+ ) ) ,
995
+ sierra_program_length : test_contract_sierra. sierra_program . len ( ) ,
996
+ abi_length : test_contract_sierra. abi . len ( ) ,
997
+ sierra_version,
998
+ } ;
999
+ let tx =
1000
+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1001
+ test_manager. add_cairo1_declare_tx ( tx, test_contract_sierra) ;
1002
+
1003
+ // Deploy it (from funded account).
1004
+ let private_key = Felt :: ONE ;
1005
+ let public_key = get_public_key ( & private_key) ;
1006
+ let salt = Felt :: ZERO ;
1007
+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
1008
+ class_hash,
1009
+ Calldata ( Arc :: new ( vec ! [ public_key] ) ) ,
1010
+ nonce_manager. next ( * FUNDED_ACCOUNT_ADDRESS ) ,
1011
+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
1012
+ salt,
1013
+ ) ;
1014
+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
1015
+
1016
+ // Transfer funds to the account.
1017
+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( max_tip) . 0 ;
1018
+ let transfer_tx_args = invoke_tx_args ! {
1019
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
1020
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
1021
+ calldata: create_calldata(
1022
+ * STRK_FEE_TOKEN_ADDRESS ,
1023
+ "transfer" ,
1024
+ & [ * * v1_bound_account_address, Felt :: from( transfer_amount) , Felt :: ZERO ]
1025
+ ) ,
1026
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1027
+ } ;
1028
+ test_manager. add_invoke_tx_from_args ( transfer_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
1029
+
1030
+ // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
1031
+ let invoke_tx_args = invoke_tx_args ! {
1032
+ sender_address: v1_bound_account_address,
1033
+ nonce: nonce_manager. next( v1_bound_account_address) ,
1034
+ calldata: Calldata ( Arc :: new( vec![ Felt :: ZERO ] ) ) ,
1035
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1036
+ } ;
1037
+ let invoke_tx =
1038
+ InvokeTransaction :: create ( invoke_tx ( invoke_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1039
+ assert_eq ! ( invoke_tx. version( ) , TransactionVersion :: THREE ) ;
1040
+ let Signature { r, s } = ecdsa_sign ( & private_key, & invoke_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
1041
+ let invoke_tx_args = invoke_tx_args ! {
1042
+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
1043
+ ..invoke_tx_args
1044
+ } ;
1045
+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
968
1046
969
- // TODO(Dori): Impl the test.
1047
+ // Run the test, and make sure the account storage has the expected changes.
1048
+ let test_output =
1049
+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
1050
+ let isrc6_id = Felt :: from_hex_unchecked (
1051
+ "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD" ,
1052
+ ) ;
1053
+ let expected_storage_updates = HashMap :: from ( [ (
1054
+ v1_bound_account_address,
1055
+ HashMap :: from ( [
1056
+ (
1057
+ StarknetStorageKey ( selector_from_name ( "Account_public_key" ) . 0 . try_into ( ) . unwrap ( ) ) ,
1058
+ StarknetStorageValue ( public_key) ,
1059
+ ) ,
1060
+ (
1061
+ StarknetStorageKey (
1062
+ Pedersen :: hash ( & selector_from_name ( "SRC5_supported_interfaces" ) . 0 , & isrc6_id)
1063
+ . try_into ( )
1064
+ . unwrap ( ) ,
1065
+ ) ,
1066
+ StarknetStorageValue ( Felt :: ONE ) ,
1067
+ ) ,
1068
+ ] ) ,
1069
+ ) ] ) ;
1070
+ let perform_global_validations = true ;
1071
+ let partial_state_diff =
1072
+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
1073
+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
970
1074
}
0 commit comments