-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests_generator.rs
38 lines (30 loc) · 1.54 KB
/
tests_generator.rs
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
use sierra_analyzer_lib::sierra_program::SierraProgram;
use sierra_analyzer_lib::sym_exec::sym_exec::generate_test_cases_for_function;
fn main() {
// Read the content of the Sierra program file
// The file `symbolic_execution_test.sierra` contains a function `symbolic::symbolic::symbolic_execution_test`
// that takes 4 parameters (v0, v1, v2, and v3) as input.
// To pass all the conditions in the function, the values of the parameters should be:
// v0: 102, v1: 117, v2: 122, v3: 122 ("f", "u", "z", "z").
let content = include_str!("../../examples/sierra/symbolic_execution_test.sierra").to_string();
// Initialize a new SierraProgram with the content of the .sierra file
let program = SierraProgram::new(content);
// Disable verbose output for the decompiler
let verbose_output = false;
// Create a decompiler instance for the Sierra program
let mut decompiler = program.decompiler(verbose_output);
// Decompile the Sierra program
let use_color = false;
decompiler.decompile(use_color);
// Retrieve the decompiled functions
let mut functions = decompiler.functions;
// Generate test cases for the `symbolic::symbolic::symbolic_execution_test` function
// This should return the input values that maximize code coverage:
// ["v0: 102", "v1: 117", "v2: 122", "v3: 122"]
let test_cases = generate_test_cases_for_function(
&mut functions[0],
decompiler.declared_libfuncs_names.clone(),
);
// Print the generated test cases
println!("{}", test_cases);
}