@@ -2483,4 +2483,102 @@ mod test {
2483
2483
assert_eq ! ( result_json[ "message" ] , "Checks failed." ) ;
2484
2484
assert ! ( result_json[ "error" ] [ "analysis" ] != json!( null) ) ;
2485
2485
}
2486
+
2487
+ #[ test]
2488
+ fn test_launch_clarity3_contract_passes_with_clarity3_flag ( ) {
2489
+ // Arrange
2490
+ let db_name = format ! ( "/tmp/db_{}" , rand:: thread_rng( ) . gen :: <i32 >( ) ) ;
2491
+ invoke_command ( "test" , & [ "initialize" . to_string ( ) , db_name. clone ( ) ] ) ;
2492
+
2493
+ let clar_path = format ! (
2494
+ "/tmp/version-flag-launch-c3-{}.clar" ,
2495
+ rand:: thread_rng( ) . gen :: <i32 >( )
2496
+ ) ;
2497
+ fs:: write (
2498
+ & clar_path,
2499
+ // Valid only in Clarity 3.
2500
+ r#"
2501
+ (define-read-only (get-tenure-info (h uint))
2502
+ (ok
2503
+ {
2504
+ tenure-time: (get-tenure-info? time h),
2505
+ tenure-miner-address: (get-tenure-info? miner-address h),
2506
+ })
2507
+ )
2508
+ "# ,
2509
+ )
2510
+ . unwrap ( ) ;
2511
+
2512
+ // Act
2513
+ let invoked = invoke_command (
2514
+ "test" ,
2515
+ & [
2516
+ "launch" . to_string ( ) ,
2517
+ "S1G2081040G2081040G2081040G208105NK8PE5.tenure" . to_string ( ) ,
2518
+ clar_path,
2519
+ db_name,
2520
+ "--clarity_version" . to_string ( ) ,
2521
+ "clarity3" . to_string ( ) ,
2522
+ ] ,
2523
+ ) ;
2524
+
2525
+ // Assert
2526
+ let exit_code = invoked. 0 ;
2527
+ let result_json = invoked. 1 . unwrap ( ) ;
2528
+ assert_eq ! (
2529
+ exit_code, 0 ,
2530
+ "expected launch to pass under Clarity 3, got: {}" ,
2531
+ result_json
2532
+ ) ;
2533
+ assert_eq ! ( result_json[ "message" ] , "Contract initialized!" ) ;
2534
+ }
2535
+
2536
+ #[ test]
2537
+ fn test_launch_clarity3_contract_fails_with_clarity2_flag ( ) {
2538
+ // Arrange
2539
+ let db_name = format ! ( "/tmp/db_{}" , rand:: thread_rng( ) . gen :: <i32 >( ) ) ;
2540
+ invoke_command ( "test" , & [ "initialize" . to_string ( ) , db_name. clone ( ) ] ) ;
2541
+
2542
+ let clar_path = format ! (
2543
+ "/tmp/version-flag-launch-c2-{}.clar" ,
2544
+ rand:: thread_rng( ) . gen :: <i32 >( )
2545
+ ) ;
2546
+ fs:: write (
2547
+ & clar_path,
2548
+ // Valid only in Clarity 3, should fail in 2.
2549
+ r#"
2550
+ (define-read-only (get-tenure-info (h uint))
2551
+ (ok
2552
+ {
2553
+ tenure-time: (get-tenure-info? time h),
2554
+ tenure-miner-address: (get-tenure-info? miner-address h),
2555
+ })
2556
+ )
2557
+ "# ,
2558
+ )
2559
+ . unwrap ( ) ;
2560
+
2561
+ // Act
2562
+ let invoked = invoke_command (
2563
+ "test" ,
2564
+ & [
2565
+ "launch" . to_string ( ) ,
2566
+ "S1G2081040G2081040G2081040G208105NK8PE5.tenure" . to_string ( ) ,
2567
+ clar_path,
2568
+ db_name,
2569
+ "--clarity_version" . to_string ( ) ,
2570
+ "clarity2" . to_string ( ) ,
2571
+ ] ,
2572
+ ) ;
2573
+
2574
+ // Assert
2575
+ let exit_code = invoked. 0 ;
2576
+ let result_json = invoked. 1 . unwrap ( ) ;
2577
+ assert_eq ! (
2578
+ exit_code, 1 ,
2579
+ "expected launch to fail under Clarity 2, got: {}" ,
2580
+ result_json
2581
+ ) ;
2582
+ assert ! ( result_json[ "error" ] [ "initialization" ] != json!( null) ) ;
2583
+ }
2486
2584
}
0 commit comments