Skip to content

Commit

Permalink
Improve tests_generator example
Browse files Browse the repository at this point in the history
  • Loading branch information
Rog3rSm1th committed Aug 8, 2024
1 parent a787652 commit af60843
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/examples/tests_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@ use sierra_analyzer_lib::sierra_program::SierraProgram;
use sierra_analyzer_lib::sym_exec::sym_exec::generate_test_cases_for_function;

fn main() {
// Read file content
// 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();

// Init a new SierraProgram with the .sierra file content
// Initialize a new SierraProgram with the content of the .sierra file
let program = SierraProgram::new(content);

// Don't use the verbose output
// Disable verbose output for the decompiler
let verbose_output = false;

// Decompile the Sierra program
// Create a decompiler instance for the Sierra program
let mut decompiler = program.decompiler(verbose_output);

// Decompile the sierra program
// Decompile the Sierra program
let use_color = false;
decompiler.decompile(use_color);

// Generate test cases
// 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);
}

0 comments on commit af60843

Please sign in to comment.