@@ -2907,6 +2907,74 @@ fn test_min_funding_bps_allows_release_above_threshold() {
29072907 assert_eq ! ( tk. balance( & recipient) , 900 ) ;
29082908}
29092909
2910+ // ---------------------------------------------------------------------------
2911+ // Issue #695: validate velocity_window is non-zero when velocity_limit is set
2912+ // ---------------------------------------------------------------------------
2913+
2914+ #[ test]
2915+ #[ should_panic]
2916+ fn test_velocity_limit_without_window_rejected ( ) {
2917+ // velocity_limit=1000 with velocity_window=0 must be rejected with ContractError::InvalidAmount.
2918+ let ( env, contract_id, token_id) = setup_initialized ( ) ;
2919+ let c = client ( & env, & contract_id) ;
2920+
2921+ let creator = Address :: generate ( & env) ;
2922+ let recipient = Address :: generate ( & env) ;
2923+
2924+ env. ledger ( ) . set_timestamp ( 1_000 ) ;
2925+
2926+ let mut recipients = Vec :: new ( & env) ;
2927+ recipients. push_back ( recipient. clone ( ) ) ;
2928+ let mut amounts = Vec :: new ( & env) ;
2929+ amounts. push_back ( 1_000_i128 ) ;
2930+
2931+ // velocity_limit > 0 but velocity_window == 0 — undefined behaviour; must panic.
2932+ c. create_invoice (
2933+ & creator,
2934+ & recipients,
2935+ & amounts,
2936+ & token_id,
2937+ & 9_999_u64 ,
2938+ & InvoiceOptions {
2939+ velocity_limit : 1_000 ,
2940+ velocity_window : 0 ,
2941+ ..default_options ( & env)
2942+ } ,
2943+ ) ;
2944+ }
2945+
2946+ #[ test]
2947+ fn test_velocity_limit_with_valid_window_accepted ( ) {
2948+ // velocity_limit=1000, velocity_window=3600 is a valid configuration and must be accepted.
2949+ let ( env, contract_id, token_id) = setup_initialized ( ) ;
2950+ let c = client ( & env, & contract_id) ;
2951+
2952+ let creator = Address :: generate ( & env) ;
2953+ let recipient = Address :: generate ( & env) ;
2954+
2955+ env. ledger ( ) . set_timestamp ( 1_000 ) ;
2956+
2957+ let mut recipients = Vec :: new ( & env) ;
2958+ recipients. push_back ( recipient. clone ( ) ) ;
2959+ let mut amounts = Vec :: new ( & env) ;
2960+ amounts. push_back ( 1_000_i128 ) ;
2961+
2962+ // Both limit and window are set — valid; invoice creation must succeed.
2963+ let id = c. create_invoice (
2964+ & creator,
2965+ & recipients,
2966+ & amounts,
2967+ & token_id,
2968+ & 9_999_u64 ,
2969+ & InvoiceOptions {
2970+ velocity_limit : 1_000 ,
2971+ velocity_window : 3_600 ,
2972+ ..default_options ( & env)
2973+ } ,
2974+ ) ;
2975+ assert_eq ! ( c. get_invoice( & id) . status, InvoiceStatus :: Pending ) ;
2976+ }
2977+
29102978// ---------------------------------------------------------------------------
29112979// Issue #85: generate_payment_proof
29122980// ---------------------------------------------------------------------------
0 commit comments