mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
Merge pull request #520 from AleoHQ/fix/conditional-logging
fix conditional logging bug #407
This commit is contained in:
commit
2cde6d0659
@ -137,9 +137,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the indicator boolean gadget value.
|
/// Unwraps the indicator boolean gadget value or `false` if `None`.
|
||||||
/// We can directly compare a boolean constant to the indicator since we are not enforcing any
|
/// This method is used by logging methods only.
|
||||||
/// constraints
|
/// 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 {
|
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
|
// 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/>.
|
// 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;
|
use leo_ast::InputValue;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -84,6 +84,22 @@ fn test_log_input() {
|
|||||||
assert_satisfied(program);
|
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
|
// Debug
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user