-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathmod.rs
More file actions
53 lines (44 loc) · 1.24 KB
/
mod.rs
File metadata and controls
53 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::error::{self, ErrorKind};
use super::test_stdlib;
use error::Result;
use rstest::rstest;
#[rstest]
#[case(r#"{"val": "0"}"#, vec!["0"])]
#[case(r#"{"val": "1"}"#, vec!["1"])]
fn test_bit_checked(#[case] public_inputs: &str, #[case] expected_output: Vec<&str>) -> Result<()> {
test_stdlib(
"bits/bit_checked.no",
None,
public_inputs,
r#"{}"#,
expected_output,
)?;
Ok(())
}
#[test]
fn test_bit_checked_witness_failure() -> Result<()> {
let public_inputs = r#"{"val": "2"}"#; // should break range check
let err = test_stdlib("bits/bit_checked.no", None, public_inputs, r#"{}"#, vec![])
.err()
.expect("expected witness error");
assert!(matches!(err.kind, ErrorKind::InvalidWitness(..)));
Ok(())
}
#[rstest]
#[case(r#"{"val": "0"}"#, vec!["0"])] // 0 => false
#[case(r#"{"val": "1"}"#, vec!["1"])] // 1 => true
#[case(r#"{"val": "2"}"#, vec!["0"])] // _ => false
#[case(r#"{"val": "99"}"#, vec!["0"])]
fn test_bit_unchecked(
#[case] public_inputs: &str,
#[case] expected_output: Vec<&str>,
) -> Result<()> {
test_stdlib(
"bits/bit_unchecked.no",
None,
public_inputs,
r#"{}"#,
expected_output,
)?;
Ok(())
}