()
| 963 | // test the extract window fn |
| 964 | #[test] |
| 965 | fn test_extract_window() { |
| 966 | let mut prng = ChaCha20Rng::seed_from_u64(8); |
| 967 | |
| 968 | for _ in 0..100 { |
| 969 | // generate random start_index and window |
| 970 | let start_index = prng.gen_range(1..=31); |
| 971 | let window = prng.gen_range(1..=start_index); |
| 972 | |
| 973 | // generate a random u32 |
| 974 | let random_u32: u32 = prng.gen(); |
| 975 | |
| 976 | // compute the values by shifting |
| 977 | let initial_limb = random_u32 >> (32u32 - start_index); |
| 978 | let expected_window = initial_limb >> (start_index - window); |
| 979 | let modified_limb = if start_index == window { |
| 980 | 0 |
| 981 | } else { |
| 982 | (initial_limb << (32u32 - start_index + window)) >> (32u32 - start_index + window) |
| 983 | }; |
| 984 | |
| 985 | let script = script!( |
| 986 | {initial_limb} |
| 987 | |
| 988 | {extract_digits(start_index,window)} |
| 989 | |
| 990 | {modified_limb} |
| 991 | OP_EQUALVERIFY |
| 992 | |
| 993 | {expected_window} |
| 994 | OP_EQUAL |
| 995 | ); |
| 996 | |
| 997 | let res = crate::execute_script(script.clone()); |
| 998 | assert!(res.success); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | // manual test of transform to and from U256. |
| 1003 | #[test] |
nothing calls this directly
no test coverage detected