@@ -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
@@ -865,13 +870,85 @@ async fn test_os_logic(#[values(1, 3)] n_blocks_in_multi_block: usize) {
865
870
async fn test_v1_bound_accounts_cairo0 ( ) {
866
871
let test_contract = & V1_BOUND_CAIRO0_CONTRACT ;
867
872
let class_hash = ClassHash ( compute_deprecated_class_hash ( test_contract) . unwrap ( ) ) ;
873
+ let vc = VersionedConstants :: latest_constants ( ) ;
874
+ let ( mut test_manager, mut nonce_manager, _) =
875
+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ ] ) . await ;
868
876
869
- assert ! (
870
- VersionedConstants :: latest_constants( )
871
- . os_constants
872
- . v1_bound_accounts_cairo0
873
- . contains( & class_hash)
877
+ assert ! ( vc. os_constants. v1_bound_accounts_cairo0. contains( & class_hash) ) ;
878
+
879
+ // Declare the V1-bound account.
880
+ let declare_args = declare_tx_args ! {
881
+ version: TransactionVersion :: ZERO ,
882
+ max_fee: Fee ( 1_000_000_000_000_000 ) ,
883
+ class_hash,
884
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
885
+ } ;
886
+ let account_declare_tx = declare_tx ( declare_args) ;
887
+ let class_info = get_class_info_of_cairo0_contract ( ( * * test_contract) . clone ( ) ) ;
888
+ let tx =
889
+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
890
+ test_manager. add_cairo0_declare_tx ( tx, StarknetAPICompiledClassHash ( class_hash. 0 ) ) ;
891
+
892
+ // Deploy it.
893
+ let salt = Felt :: ZERO ;
894
+ let ( deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt (
895
+ class_hash,
896
+ Calldata :: default ( ) ,
897
+ nonce_manager. next ( * FUNDED_ACCOUNT_ADDRESS ) ,
898
+ * NON_TRIVIAL_RESOURCE_BOUNDS ,
899
+ salt,
874
900
) ;
901
+ test_manager. add_invoke_tx ( deploy_tx, None ) ;
902
+
903
+ // Initialize the account.
904
+ let private_key = Felt :: ONE ;
905
+ let public_key = get_public_key ( & private_key) ;
906
+ let guardian = Felt :: ZERO ;
907
+ let invoke_tx_args = invoke_tx_args ! {
908
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
909
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
910
+ calldata: create_calldata( v1_bound_account_address, "initialize" , & [ public_key, guardian] ) ,
911
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
912
+ } ;
913
+ test_manager. add_invoke_tx_from_args ( invoke_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
875
914
876
- // TODO(Dori): Implement the test.
915
+ // Create a validate tx and add signature to the transaction. The dummy account used to call
916
+ // `__validate__` does not check the signature, so we can use the signature field for
917
+ // `__validate__`. This is done after creating the transaction so that we will have access
918
+ // to the transaction hash.
919
+ let validate_tx_args = invoke_tx_args ! {
920
+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
921
+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
922
+ calldata: create_calldata(
923
+ v1_bound_account_address, "__validate__" , & [ Felt :: ZERO , Felt :: ZERO ]
924
+ ) ,
925
+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
926
+ tip: vc. os_constants. v1_bound_accounts_max_tip,
927
+ } ;
928
+ let validate_tx =
929
+ InvokeTransaction :: create ( invoke_tx ( validate_tx_args. clone ( ) ) , & CHAIN_ID_FOR_TESTS )
930
+ . unwrap ( ) ;
931
+ assert_eq ! ( validate_tx. version( ) , TransactionVersion :: THREE ) ;
932
+ let Signature { r, s } = ecdsa_sign ( & private_key, & validate_tx. tx_hash ( ) ) . unwrap ( ) . into ( ) ;
933
+ let validate_tx_args = invoke_tx_args ! {
934
+ signature: TransactionSignature ( Arc :: new( vec![ r, s] ) ) ,
935
+ ..validate_tx_args
936
+ } ;
937
+ test_manager. add_invoke_tx_from_args ( validate_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
938
+
939
+ // Run test and verify the signer was set.
940
+ let test_output =
941
+ test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
942
+
943
+ let expected_storage_updates = HashMap :: from ( [ (
944
+ v1_bound_account_address,
945
+ HashMap :: from ( [ (
946
+ StarknetStorageKey ( get_storage_var_address ( "_signer" , & [ ] ) ) ,
947
+ StarknetStorageValue ( public_key) ,
948
+ ) ] ) ,
949
+ ) ] ) ;
950
+ let perform_global_validations = true ;
951
+ let partial_state_diff =
952
+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ;
953
+ test_output. perform_validations ( perform_global_validations, partial_state_diff) ;
877
954
}
0 commit comments