diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index abb82c48e3..98e1dd34e9 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -69,7 +69,7 @@ impl Address { } pub(crate) fn from_input, CS: ConstraintSystem>( - _cs: &mut CS, + cs: &mut CS, name: String, input_value: Option, span: Span, @@ -78,17 +78,23 @@ impl Address { let address_value = match input_value { Some(input) => { if let InputValue::Address(string) = input { - let address = Address::constant(string, span)?; - - address + Some(string) } else { return Err(AddressError::invalid_address(name, span)); } } - None => unimplemented!(), + None => None, }; - Ok(ConstrainedValue::Address(address_value)) + let address_name = format!("{}: address", name); + let address_namespace = format!("`{}` {}:{}", address_name, span.line, span.start); + + let address = Address::alloc(cs.ns(|| address_namespace), || { + address_value.ok_or(SynthesisError::AssignmentMissing) + }) + .map_err(|_| AddressError::missing_address(span))?; + + Ok(ConstrainedValue::Address(address)) } pub(crate) fn alloc_helper Result, T: Borrow>( diff --git a/compiler/tests/address/assert_fail.leo b/compiler/tests/address/console_assert_fail.leo similarity index 100% rename from compiler/tests/address/assert_fail.leo rename to compiler/tests/address/console_assert_fail.leo diff --git a/compiler/tests/address/assert_pass.leo b/compiler/tests/address/console_assert_pass.leo similarity index 100% rename from compiler/tests/address/assert_pass.leo rename to compiler/tests/address/console_assert_pass.leo diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index aace594bf6..96615fd29c 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_compiler_error, parse_program}; +use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program}; +use leo_typed::InputValue; -// static TEST_ADDRESS_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; -// static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r"; +static TEST_ADDRESS_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; +static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r"; #[test] fn test_valid() { @@ -67,72 +68,72 @@ fn test_implicit_invalid() { let _output = expect_compiler_error(program); } -// #[test] -// fn test_assert_eq_pass() { -// let bytes = include_bytes!("assert_eq_pass.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_assert_eq_fail() { -// let bytes = include_bytes!("assert_eq_fail.leo"); -// let program = parse_program(bytes).unwrap(); -// -// let _output = expect_compiler_error(program); -// } -// -// #[test] -// fn test_ternary() { -// let bytes = include_bytes!("ternary.leo"); -// let mut program = parse_program(bytes).unwrap(); -// -// let main_input = generate_main_input(vec![ -// ("s", Some(InputValue::Boolean(true))), -// ("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), -// ]); -// -// program.set_main_input(main_input); -// -// assert_satisfied(program); -// -// let mut program = parse_program(bytes).unwrap(); -// -// let main_input = generate_main_input(vec![ -// ("s", Some(InputValue::Boolean(false))), -// ("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), -// ]); -// -// program.set_main_input(main_input); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_equal() { -// let bytes = include_bytes!("equal.leo"); -// let mut program = parse_program(bytes).unwrap(); -// -// let main_input = generate_main_input(vec![ -// ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), -// ("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), -// ("c", Some(InputValue::Boolean(true))), -// ]); -// -// program.set_main_input(main_input); -// -// assert_satisfied(program); -// -// let mut program = parse_program(bytes).unwrap(); -// -// let main_input = generate_main_input(vec![ -// ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), -// ("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), -// ("c", Some(InputValue::Boolean(false))), -// ]); -// -// program.set_main_input(main_input); -// -// assert_satisfied(program); -// } +#[test] +fn test_console_assert_pass() { + let bytes = include_bytes!("console_assert_pass.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_console_assert_fail() { + let bytes = include_bytes!("console_assert_fail.leo"); + let program = parse_program(bytes).unwrap(); + + let _output = expect_compiler_error(program); +} + +#[test] +fn test_ternary() { + let bytes = include_bytes!("ternary.leo"); + let mut program = parse_program(bytes).unwrap(); + + let main_input = generate_main_input(vec![ + ("s", Some(InputValue::Boolean(true))), + ("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), + ]); + + program.set_main_input(main_input); + + assert_satisfied(program); + + let mut program = parse_program(bytes).unwrap(); + + let main_input = generate_main_input(vec![ + ("s", Some(InputValue::Boolean(false))), + ("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), + ]); + + program.set_main_input(main_input); + + assert_satisfied(program); +} + +#[test] +fn test_equal() { + let bytes = include_bytes!("equal.leo"); + let mut program = parse_program(bytes).unwrap(); + + let main_input = generate_main_input(vec![ + ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), + ("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), + ("c", Some(InputValue::Boolean(true))), + ]); + + program.set_main_input(main_input); + + assert_satisfied(program); + + let mut program = parse_program(bytes).unwrap(); + + let main_input = generate_main_input(vec![ + ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), + ("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), + ("c", Some(InputValue::Boolean(false))), + ]); + + program.set_main_input(main_input); + + assert_satisfied(program); +}