mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-22 09:01:35 +03:00
fix conditional logging bug #407
This commit is contained in:
parent
bf2280e400
commit
d28e161706
@ -137,9 +137,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the indicator boolean gadget value.
|
||||
/// We can directly compare a boolean constant to the indicator since we are not enforcing any
|
||||
/// constraints
|
||||
/// Unwraps the indicator boolean gadget value or `false` if `None`.
|
||||
/// This method is used by logging methods only.
|
||||
/// We can directly get the boolean value of the indicator since we are not enforcing any
|
||||
/// constraints.
|
||||
pub fn get_indicator_value(indicator: &Boolean) -> bool {
|
||||
indicator.eq(&Boolean::constant(true))
|
||||
indicator.get_value().unwrap_or(false)
|
||||
}
|
||||
|
3
compiler/tests/console/input/input_equal.in
Normal file
3
compiler/tests/console/input/input_equal.in
Normal file
@ -0,0 +1,3 @@
|
||||
[main]
|
||||
a: u32 = 1;
|
||||
b: u32 = 1;
|
3
compiler/tests/console/input/input_unequal.in
Normal file
3
compiler/tests/console/input/input_unequal.in
Normal file
@ -0,0 +1,3 @@
|
||||
[main]
|
||||
a: u32 = 1;
|
||||
b: u32 = 0;
|
6
compiler/tests/console/log_conditional.leo
Normal file
6
compiler/tests/console/log_conditional.leo
Normal file
@ -0,0 +1,6 @@
|
||||
// Conditionally add two u32 integers and log the result to the console.
|
||||
function main(a: u32, b: u32) {
|
||||
if a == b {
|
||||
console.log("{}=={}",a,b); // This line should not fail.
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program};
|
||||
use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program, parse_program_with_input};
|
||||
use leo_ast::InputValue;
|
||||
|
||||
#[test]
|
||||
@ -84,6 +84,22 @@ fn test_log_input() {
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_log_conditional() {
|
||||
let program_string = include_str!("log_conditional.leo");
|
||||
let input_equal_string = include_str!("input/input_equal.in");
|
||||
|
||||
let program = parse_program_with_input(program_string.clone(), input_equal_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
|
||||
let input_unequal_string = include_str!("input/input_unequal.in");
|
||||
|
||||
let program = parse_program_with_input(program_string, input_unequal_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
// Debug
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user