@@ -19,11 +19,13 @@ use starknet_api::core::{
19
19
} ;
20
20
use starknet_api:: executable_transaction:: {
21
21
DeclareTransaction ,
22
+ InvokeTransaction ,
22
23
L1HandlerTransaction as ExecutableL1HandlerTransaction ,
23
24
} ;
24
25
use starknet_api:: execution_resources:: GasAmount ;
25
26
use starknet_api:: state:: StorageKey ;
26
27
use starknet_api:: test_utils:: declare:: declare_tx;
28
+ use starknet_api:: test_utils:: invoke:: invoke_tx;
27
29
use starknet_api:: test_utils:: {
28
30
CHAIN_ID_FOR_TESTS ,
29
31
CURRENT_BLOCK_TIMESTAMP ,
@@ -56,6 +58,8 @@ use starknet_committer::block_committer::input::{
56
58
StateDiff ,
57
59
} ;
58
60
use starknet_committer:: patricia_merkle_tree:: types:: CompiledClassHash ;
61
+ use starknet_core:: crypto:: ecdsa_sign;
62
+ use starknet_crypto:: { get_public_key, Signature } ;
59
63
use starknet_os:: hints:: hint_implementation:: deprecated_compiled_class:: class_hash:: compute_deprecated_class_hash;
60
64
use starknet_os:: io:: os_output:: MessageToL2 ;
61
65
use starknet_types_core:: felt:: Felt ;
@@ -69,6 +73,7 @@ use crate::test_manager::{TestManager, TestParameters, FUNDED_ACCOUNT_ADDRESS};
69
73
use crate :: utils:: {
70
74
divide_vec_into_n_parts,
71
75
get_class_hash_of_feature_contract,
76
+ get_class_info_of_cairo0_contract,
72
77
get_class_info_of_feature_contract,
73
78
} ;
74
79
@@ -862,13 +867,85 @@ async fn test_os_logic(#[values(1, 3)] n_blocks_in_multi_block: usize) {
862
867
async fn test_v1_bound_accounts_cairo0 ( ) {
863
868
let test_contract = & V1_BOUND_CAIRO0_CONTRACT ;
864
869
let class_hash = ClassHash ( compute_deprecated_class_hash ( test_contract) . unwrap ( ) ) ;
870
+ let vc = VersionedConstants :: latest_constants ( ) ;
871
+ let ( mut test_manager, mut nonce_manager, _) =
872
+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
865
873
866
- assert ! (
867
- VersionedConstants :: latest_constants( )
868
- . os_constants
869
- . v1_bound_accounts_cairo0
870
- . contains( & class_hash)
874
+ assert ! ( vc. os_constants. v1_bound_accounts_cairo0. contains( & class_hash) ) ;
875
+
876
+ // Declare the V1-bound account.
877
+ let declare_args = declare_tx_args ! {
878
+ version: TransactionVersion :: ZERO ,
879
+ max_fee: Fee ( 1_000_000_000_000_000 ) ,
880
+ class_hash,
881
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
882
+ } ;
883
+ let account_declare_tx = declare_tx ( declare_args) ;
884
+ let class_info = get_class_info_of_cairo0_contract ( ( & * * test_contract) . clone ( ) ) ;
885
+ let tx =
886
+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
887
+ test_manager. add_cairo0_declare_tx ( tx, StarknetAPICompiledClassHash ( class_hash. 0 ) ) ;
888
+
889
+ // Deploy it.
890
+ let salt = Felt :: ZERO ;
891
+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
892
+ class_hash,
893
+ Calldata :: default ( ) ,
894
+ nonce_manager. next ( * FUNDED_ACCOUNT_ADDRESS ) ,
895
+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
896
+ salt,
871
897
) ;
898
+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
899
+
900
+ // Initialize the account.
901
+ let private_key = Felt :: ONE ;
902
+ let public_key = get_public_key ( & private_key) ;
903
+ let guardian = Felt :: ZERO ;
904
+ let invoke_tx_args = invoke_tx_args ! {
905
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
906
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
907
+ calldata: create_calldata( v1_bound_account_address, "initialize" , & [ public_key, guardian] ) ,
908
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
909
+ } ;
910
+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
872
911
873
- // TODO(Dori): Implement the test.
912
+ // Create a validate tx and add signature to the transaction. The dummy account used to call
913
+ // `__validate__` does not check the signature, so we can use the signature field for
914
+ // `__validate__`. This is done after creating the transaction so that we will have access
915
+ // to the transaction hash.
916
+ let validate_tx_args = invoke_tx_args ! {
917
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
918
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
919
+ calldata: create_calldata(
920
+ v1_bound_account_address, "__validate__" , & [ Felt :: ZERO , Felt :: ZERO ]
921
+ ) ,
922
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
923
+ tip: vc. os_constants. v1_bound_accounts_max_tip,
924
+ } ;
925
+ let validate_tx =
926
+ InvokeTransaction :: create ( invoke_tx ( validate_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS )
927
+ . unwrap ( ) ;
928
+ assert_eq ! ( validate_tx. version( ) , TransactionVersion :: THREE ) ;
929
+ let Signature { r, s } = ecdsa_sign ( & private_key, & validate_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
930
+ let validate_tx_args = invoke_tx_args ! {
931
+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
932
+ ..validate_tx_args
933
+ } ;
934
+ test_manager. add_invoke_tx_from_args ( validate_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
935
+
936
+ // Run test and verify the signer was set.
937
+ let test_output =
938
+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
939
+
940
+ let expected_storage_updates = HashMap :: from ( [ (
941
+ v1_bound_account_address,
942
+ HashMap :: from ( [ (
943
+ StarknetStorageKey ( get_storage_var_address ( "_signer" , & [ ] ) ) ,
944
+ StarknetStorageValue ( public_key) ,
945
+ ) ] ) ,
946
+ ) ] ) ;
947
+ let perform_global_validations = true ;
948
+ let partial_state_diff =
949
+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
950
+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
874
951
}
0 commit comments