mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
impl tests for allocated addresses
This commit is contained in:
parent
5aad40a678
commit
a86018c0ea
@ -69,7 +69,7 @@ impl Address {
|
||||
}
|
||||
|
||||
pub(crate) fn from_input<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
_cs: &mut CS,
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
input_value: Option<InputValue>,
|
||||
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<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>>(
|
||||
|
@ -14,10 +14,11 @@
|
||||
// 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, 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user