File size: 907 Bytes
224e773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
//! DSL to constraint compilation

use super::language::ValidityProgram;
use crate::Result;
use hyperkitty_core::Error;

pub fn compile(source: &str) -> Result<ValidityProgram> {
    // Stub: simplified compilation (parser integration deferred)
    let mut prog = ValidityProgram::new();

    if source.contains("balance") {
        prog.add_constraint(super::language::Constraint::Balance("main".to_string()));
    }
    if source.contains("reject") {
        prog.set_reject_on_fail(true);
    }

    Ok(prog)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn compile_simple() {
        let prog = compile("require balance").unwrap();
        assert!(!prog.constraints.is_empty());
    }

    #[test]
    fn compile_with_reject() {
        let prog = compile("require balance otherwise reject").unwrap();
        assert!(prog.otherwise_reject);
    }
}