@@ -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,104 @@ 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 ( ( ( * * test_contract_casm) . clone ( ) , sierra_version. clone ( ) ) ) ,
992
+ sierra_program_length : test_contract_sierra. sierra_program . len ( ) ,
993
+ abi_length : test_contract_sierra. abi . len ( ) ,
994
+ sierra_version,
995
+ } ;
996
+ let tx =
997
+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
998
+ test_manager. add_cairo1_declare_tx ( tx, test_contract_sierra) ;
999
+
1000
+ // Deploy it (from funded account).
1001
+ let private_key = Felt :: ONE ;
1002
+ let public_key = get_public_key ( & private_key) ;
1003
+ let salt = Felt :: ZERO ;
1004
+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
1005
+ class_hash,
1006
+ Calldata ( Arc :: new ( vec ! [ public_key] ) ) ,
1007
+ nonce_manager. next ( * FUNDED_ACCOUNT_ADDRESS ) ,
1008
+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
1009
+ salt,
1010
+ ) ;
1011
+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
1012
+
1013
+ // Transfer funds to the account.
1014
+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( max_tip) . 0 ;
1015
+ let transfer_tx_args = invoke_tx_args ! {
1016
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
1017
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
1018
+ calldata: create_calldata(
1019
+ * STRK_FEE_TOKEN_ADDRESS ,
1020
+ "transfer" ,
1021
+ & [ * * v1_bound_account_address, Felt :: from( transfer_amount) , Felt :: ZERO ]
1022
+ ) ,
1023
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1024
+ } ;
1025
+ test_manager. add_invoke_tx_from_args ( transfer_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
1026
+
1027
+ // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
1028
+ let invoke_tx_args = invoke_tx_args ! {
1029
+ sender_address: v1_bound_account_address,
1030
+ nonce: nonce_manager. next( v1_bound_account_address) ,
1031
+ calldata: Calldata ( Arc :: new( vec![ Felt :: ZERO ] ) ) ,
1032
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1033
+ } ;
1034
+ let invoke_tx =
1035
+ InvokeTransaction :: create ( invoke_tx ( invoke_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1036
+ assert_eq ! ( invoke_tx. version( ) , TransactionVersion :: THREE ) ;
1037
+ let Signature { r, s } = ecdsa_sign ( & private_key, & invoke_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
1038
+ let invoke_tx_args = invoke_tx_args ! {
1039
+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
1040
+ ..invoke_tx_args
1041
+ } ;
1042
+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
968
1043
969
- // TODO(Dori): Impl the test.
1044
+ // Run the test, and make sure the account storage has the expected changes.
1045
+ let test_output =
1046
+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
1047
+ let isrc6_id = Felt :: from_hex_unchecked (
1048
+ "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD" ,
1049
+ ) ;
1050
+ let expected_storage_updates = HashMap :: from ( [ (
1051
+ v1_bound_account_address,
1052
+ HashMap :: from ( [
1053
+ (
1054
+ StarknetStorageKey ( selector_from_name ( "Account_public_key" ) . 0 . try_into ( ) . unwrap ( ) ) ,
1055
+ StarknetStorageValue ( public_key) ,
1056
+ ) ,
1057
+ (
1058
+ StarknetStorageKey (
1059
+ Pedersen :: hash ( & selector_from_name ( "SRC5_supported_interfaces" ) . 0 , & isrc6_id)
1060
+ . try_into ( )
1061
+ . unwrap ( ) ,
1062
+ ) ,
1063
+ StarknetStorageValue ( Felt :: ONE ) ,
1064
+ ) ,
1065
+ ] ) ,
1066
+ ) ] ) ;
1067
+ let perform_global_validations = true ;
1068
+ let partial_state_diff =
1069
+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
1070
+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
970
1071
}
0 commit comments