Skip to content

Commit e9ba8d0

Browse files
committed
Verify --clarity_version flag takes effect for clarity-cli check
1 parent 0dc24b3 commit e9ba8d0

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

stackslib/src/clarity_cli.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,4 +2394,93 @@ mod test {
23942394
})
23952395
);
23962396
}
2397+
2398+
#[test]
2399+
fn test_check_clarity3_contract_passes_with_clarity3_flag() {
2400+
// Arrange
2401+
let clar_path = format!(
2402+
"/tmp/version-flag-c3-allow-{}.clar",
2403+
rand::thread_rng().gen::<i32>()
2404+
);
2405+
fs::write(
2406+
&clar_path,
2407+
// Valid only in Clarity 3.
2408+
r#"
2409+
(define-read-only (get-tenure-info (h uint))
2410+
(ok
2411+
{
2412+
tenure-time: (get-tenure-info? time h),
2413+
tenure-miner-address: (get-tenure-info? miner-address h),
2414+
})
2415+
)
2416+
"#,
2417+
)
2418+
.unwrap();
2419+
2420+
// Act
2421+
let invoked = invoke_command(
2422+
"test",
2423+
&[
2424+
"check".to_string(),
2425+
clar_path,
2426+
"--clarity_version".to_string(),
2427+
"clarity3".to_string(),
2428+
],
2429+
);
2430+
2431+
// Assert
2432+
let exit_code = invoked.0;
2433+
let result_json = invoked.1.unwrap();
2434+
assert_eq!(
2435+
exit_code, 0,
2436+
"expected check to pass under Clarity 3, got: {}",
2437+
result_json
2438+
);
2439+
assert_eq!(result_json["message"], "Checks passed.");
2440+
}
2441+
2442+
#[test]
2443+
fn test_check_clarity3_contract_fails_with_clarity2_flag() {
2444+
// Arrange
2445+
let clar_path = format!(
2446+
"/tmp/version-flag-c2-reject-{}.clar",
2447+
rand::thread_rng().gen::<i32>()
2448+
);
2449+
fs::write(
2450+
&clar_path,
2451+
// Valid only in Clarity 3, should fail in 2.
2452+
r#"
2453+
(define-read-only (get-tenure-info (h uint))
2454+
(ok
2455+
{
2456+
tenure-time: (get-tenure-info? time h),
2457+
tenure-miner-address: (get-tenure-info? miner-address h),
2458+
})
2459+
)
2460+
"#,
2461+
)
2462+
.unwrap();
2463+
2464+
// Act
2465+
let invoked = invoke_command(
2466+
"test",
2467+
&[
2468+
"check".to_string(),
2469+
clar_path,
2470+
"--clarity_version".to_string(),
2471+
"clarity2".to_string(),
2472+
],
2473+
);
2474+
2475+
// Assert
2476+
let exit_code = invoked.0;
2477+
let result_json = invoked.1.unwrap();
2478+
assert_eq!(
2479+
exit_code, 1,
2480+
"expected check to fail under Clarity 2, got: {}",
2481+
result_json
2482+
);
2483+
assert_eq!(result_json["message"], "Checks failed.");
2484+
assert!(result_json["error"]["analysis"] != json!(null));
2485+
}
23972486
}

0 commit comments

Comments
 (0)