impl tests for allocated addresses

This commit is contained in:
collin 2020-08-19 03:11:30 -07:00
parent 5aad40a678
commit a86018c0ea
4 changed files with 85 additions and 78 deletions

View File

@ -69,7 +69,7 @@ impl Address {
} }
pub(crate) fn from_input<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>( pub(crate) fn from_input<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
_cs: &mut CS, cs: &mut CS,
name: String, name: String,
input_value: Option<InputValue>, input_value: Option<InputValue>,
span: Span, span: Span,
@ -78,17 +78,23 @@ impl Address {
let address_value = match input_value { let address_value = match input_value {
Some(input) => { Some(input) => {
if let InputValue::Address(string) = input { if let InputValue::Address(string) = input {
let address = Address::constant(string, span)?; Some(string)
address
} else { } else {
return Err(AddressError::invalid_address(name, span)); 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<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>>( pub(crate) fn alloc_helper<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>>(

View File

@ -14,10 +14,11 @@
// 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, 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_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8";
// static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r"; static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r";
#[test] #[test]
fn test_valid() { fn test_valid() {
@ -67,72 +68,72 @@ fn test_implicit_invalid() {
let _output = expect_compiler_error(program); let _output = expect_compiler_error(program);
} }
// #[test] #[test]
// fn test_assert_eq_pass() { fn test_console_assert_pass() {
// let bytes = include_bytes!("assert_eq_pass.leo"); let bytes = include_bytes!("console_assert_pass.leo");
// let program = parse_program(bytes).unwrap(); let program = parse_program(bytes).unwrap();
//
// assert_satisfied(program); assert_satisfied(program);
// } }
//
// #[test] #[test]
// fn test_assert_eq_fail() { fn test_console_assert_fail() {
// let bytes = include_bytes!("assert_eq_fail.leo"); let bytes = include_bytes!("console_assert_fail.leo");
// let program = parse_program(bytes).unwrap(); let program = parse_program(bytes).unwrap();
//
// let _output = expect_compiler_error(program); let _output = expect_compiler_error(program);
// } }
//
// #[test] #[test]
// fn test_ternary() { fn test_ternary() {
// let bytes = include_bytes!("ternary.leo"); let bytes = include_bytes!("ternary.leo");
// let mut program = parse_program(bytes).unwrap(); let mut program = parse_program(bytes).unwrap();
//
// let main_input = generate_main_input(vec![ let main_input = generate_main_input(vec![
// ("s", Some(InputValue::Boolean(true))), ("s", Some(InputValue::Boolean(true))),
// ("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), ("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
// ]); ]);
//
// program.set_main_input(main_input); program.set_main_input(main_input);
//
// assert_satisfied(program); assert_satisfied(program);
//
// let mut program = parse_program(bytes).unwrap(); let mut program = parse_program(bytes).unwrap();
//
// let main_input = generate_main_input(vec![ let main_input = generate_main_input(vec![
// ("s", Some(InputValue::Boolean(false))), ("s", Some(InputValue::Boolean(false))),
// ("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), ("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
// ]); ]);
//
// program.set_main_input(main_input); program.set_main_input(main_input);
//
// assert_satisfied(program); assert_satisfied(program);
// } }
//
// #[test] #[test]
// fn test_equal() { fn test_equal() {
// let bytes = include_bytes!("equal.leo"); let bytes = include_bytes!("equal.leo");
// let mut program = parse_program(bytes).unwrap(); let mut program = parse_program(bytes).unwrap();
//
// let main_input = generate_main_input(vec![ let main_input = generate_main_input(vec![
// ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
// ("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), ("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
// ("c", Some(InputValue::Boolean(true))), ("c", Some(InputValue::Boolean(true))),
// ]); ]);
//
// program.set_main_input(main_input); program.set_main_input(main_input);
//
// assert_satisfied(program); assert_satisfied(program);
//
// let mut program = parse_program(bytes).unwrap(); let mut program = parse_program(bytes).unwrap();
//
// let main_input = generate_main_input(vec![ let main_input = generate_main_input(vec![
// ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))), ("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
// ("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))), ("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
// ("c", Some(InputValue::Boolean(false))), ("c", Some(InputValue::Boolean(false))),
// ]); ]);
//
// program.set_main_input(main_input); program.set_main_input(main_input);
//
// assert_satisfied(program); assert_satisfied(program);
// } }