Skip to content

Commit 1e6aead

Browse files
committed
add unit tests for recent typeck bug fixes
These unit tests were written with the help of Claude 4 (it wrong the tests and I just fixed its miniscript syntax by adding s wrappers). If you want to try reordering this commit to two commits back (where it will fail), you need to tweak it a bit because the data structures were rearranged. This diff will work. diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 2435e50f..cb0b3530 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -1892,8 +1892,8 @@ mod tests { // With the fix, or_d dissatisfaction should not have the extra +1 // Both branches have exec_stack_count of 1, so dissat should be max(1,1) = 1, not 2 - if let Some(dissat_data) = ms.ext.dissat_data { - assert_eq!(dissat_data.max_exec_stack_count, 1); + if let Some(dissat_data) = ms.ext.exec_stack_elem_count_dissat{ + assert_eq!(dissat_data, 1); } else { panic!("Expected dissat_data to be Some"); } @@ -1908,8 +1908,8 @@ mod tests { // Each pk has exec_stack_count of 1 // With the fix, threshold should take max(1,1,1) = 1, not sum 1+1+1 = 3 - if let Some(sat_data) = ms.ext.sat_data { - assert_eq!(sat_data.max_exec_stack_count, 1); + if let Some(sat_data) = ms.ext.exec_stack_elem_count_sat{ + assert_eq!(sat_data, 1); } else { panic!("Expected sat_data to be Some"); } @@ -1920,8 +1920,8 @@ mod tests { // and_v has exec_stack_count of 2, pk has 1 // With the fix: max(2,1) = 2, old code would sum to 3 - if let Some(sat_data) = complex_ms.ext.sat_data { - assert_eq!(sat_data.max_exec_stack_count, 2); + if let Some(sat_data) = complex_ms.ext.exec_stack_elem_count_sat{ + assert_eq!(sat_data, 2); } else { panic!("Expected sat_data to be Some"); }
1 parent 5f0072c commit 1e6aead

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/miniscript/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,50 @@ mod tests {
18831883
Tapscript::decode_insane(&script.into_script()).unwrap_err();
18841884
}
18851885

1886+
#[test]
1887+
fn test_or_d_exec_stack_count_fix() {
1888+
// Test for the or_d dissat_data.max_exec_stack_count fix
1889+
// The old code incorrectly added +1 to the exec stack count for or_d dissatisfaction
1890+
let ms_str = "or_d(pk(A),pk(B))";
1891+
let ms = Miniscript::<String, Segwitv0>::from_str_insane(ms_str).unwrap();
1892+
1893+
// With the fix, or_d dissatisfaction should not have the extra +1
1894+
// Both branches have exec_stack_count of 1, so dissat should be max(1,1) = 1, not 2
1895+
if let Some(dissat_data) = ms.ext.dissat_data {
1896+
assert_eq!(dissat_data.max_exec_stack_count, 1);
1897+
} else {
1898+
panic!("Expected dissat_data to be Some");
1899+
}
1900+
}
1901+
1902+
#[test]
1903+
fn test_threshold_exec_stack_count_max_not_sum() {
1904+
// Test for the threshold max_exec_stack_count fix
1905+
// The old code incorrectly summed exec stack counts, new code takes max
1906+
let ms_str = "thresh(2,pk(A),s:pk(B),s:pk(C))";
1907+
let ms = Miniscript::<String, Segwitv0>::from_str_insane(ms_str).unwrap();
1908+
1909+
// Each pk has exec_stack_count of 1
1910+
// With the fix, threshold should take max(1,1,1) = 1, not sum 1+1+1 = 3
1911+
if let Some(sat_data) = ms.ext.sat_data {
1912+
assert_eq!(sat_data.max_exec_stack_count, 1);
1913+
} else {
1914+
panic!("Expected sat_data to be Some");
1915+
}
1916+
1917+
// Test with a more complex threshold to make the difference more obvious
1918+
let complex_ms_str = "thresh(1,and_b(pk(A),s:pk(B)),s:pk(C))";
1919+
let complex_ms = Miniscript::<String, Segwitv0>::from_str_insane(complex_ms_str).unwrap();
1920+
1921+
// and_v has exec_stack_count of 2, pk has 1
1922+
// With the fix: max(2,1) = 2, old code would sum to 3
1923+
if let Some(sat_data) = complex_ms.ext.sat_data {
1924+
assert_eq!(sat_data.max_exec_stack_count, 2);
1925+
} else {
1926+
panic!("Expected sat_data to be Some");
1927+
}
1928+
}
1929+
18861930
#[test]
18871931
fn test_context_global_consensus() {
18881932
// Test from string tests

0 commit comments

Comments
 (0)