Merge pull request #520 from AleoHQ/fix/conditional-logging

fix conditional logging bug #407
This commit is contained in:
Howard Wu 2021-01-07 20:30:48 -04:00 committed by GitHub
commit 2cde6d0659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 5 deletions

View File

@ -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)
} }

View File

@ -0,0 +1,3 @@
[main]
a: u32 = 1;
b: u32 = 1;

View File

@ -0,0 +1,3 @@
[main]
a: u32 = 1;
b: u32 = 0;

View 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.
}
}

View File

@ -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]