Merge pull request #157 from AleoHQ/fix/leo-test

fix leo test to run tests in isolation
This commit is contained in:
Howard Wu 2020-08-03 21:58:17 -07:00 committed by GitHub
commit 1e7a6bf4ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 109 additions and 12 deletions

86
.github/workflows/leo.yml vendored Normal file
View File

@ -0,0 +1,86 @@
name: Leo Programs
on:
pull_request:
push:
branches:
- master
env:
RUST_BACKTRACE: 1
jobs:
new:
name: Hello Leo (from 'leo new')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Load snarkOS
run: |
mkdir ~/.ssh
echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent -s)
ssh-add -k ~/.ssh/id_rsa
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- name: Install Leo
uses: actions-rs/cargo@v1
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
with:
command: install
args: --path .
- name: 'leo new'
run: |
cd ..
leo new hello_world
ls -la
cd hello_world && ls -la
leo run
init:
name: Hello Leo (from 'leo init')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Load snarkOS
run: |
mkdir ~/.ssh
echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent -s)
ssh-add -k ~/.ssh/id_rsa
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- name: Install Leo
uses: actions-rs/cargo@v1
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
with:
command: install
args: --path .
- name: 'leo init'
run: |
cd .. && mkdir hello_world && cd hello_world
leo init
ls -la
leo run

View File

@ -345,8 +345,8 @@ input_keyword = { "input" }
// Declared in functions/input/input.rs
input = {
input_keyword
| function_input
function_input
| input_keyword
}
input_list = _{ (input ~ ("," ~ NEWLINE* ~ input)*)? }

View File

@ -15,7 +15,7 @@ use leo_typed::{Input, LeoTypedAst, MainInput, Program};
use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem, TestConstraintSystem},
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
};
use sha2::{Digest, Sha256};
@ -150,8 +150,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
}
/// Synthesizes the circuit for test functions with program input.
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
generate_test_constraints::<F, G>(cs, self.program, self.program_input, &self.imported_programs)
pub fn compile_test_constraints(self) -> Result<(), CompilerError> {
generate_test_constraints::<F, G>(self.program, self.program_input, &self.imported_programs)
}
/// Calls the internal generate_constraints method with arguments

View File

@ -42,7 +42,6 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
}
pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
cs: &mut TestConstraintSystem<F>,
program: Program,
input: Input,
imported_programs: &ImportParser,
@ -57,6 +56,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
log::info!("Running {} tests", tests.len());
for (test_name, test_function) in tests.into_iter() {
let cs = &mut TestConstraintSystem::<F>::new();
let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string());
let result = resolved_program.enforce_main_function(
@ -68,7 +68,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
if result.is_ok() {
log::info!(
"test {} passed. Constraint system satisfied: {}",
"test {} compiled successfully. Constraint system satisfied: {}",
full_test_name,
cs.is_satisfied()
);

View File

@ -76,10 +76,17 @@ impl CLI for InitCommand {
// Verify the input file does not exist
let input_file = InputFile::new(&package_name);
if !input_file.exists_at(&path) {
// Create the input file in the input directory
// Create the input file in the inputs directory
input_file.write_to(&path)?;
}
// Verify the state file does not exist
let state_file = StateFile::new(&package_name);
if !state_file.exists_at(&path) {
// Create the state file in the inputs directory
state_file.write_to(&path)?;
}
// Verify the main file does not exist
if !MainFile::exists_at(&path) {
// Create the main file in the source directory

View File

@ -90,9 +90,12 @@ impl CLI for NewCommand {
// Create the input directory
InputsDirectory::create(&path)?;
// Create the input file in the input directory
// Create the input file in the inputs directory
InputFile::new(&package_name).write_to(&path)?;
// Create the state file in the inputs directory
StateFile::new(&package_name).write_to(&path)?;
// Create the main file in the source directory
MainFile::new(&package_name).write_to(&path)?;
}

View File

@ -12,7 +12,6 @@ use leo_package::{
};
use snarkos_curves::edwards_bls12::Fq;
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
use clap::ArgMatches;
use std::{convert::TryFrom, env::current_dir};
@ -81,9 +80,8 @@ impl CLI for TestCommand {
// Generate the program on the constraint system and verify correctness
{
let mut cs = TestConstraintSystem::<Fq>::new();
let temporary_program = program.clone();
let output = temporary_program.compile_test_constraints(&mut cs)?;
let output = temporary_program.compile_test_constraints()?;
log::debug!("Compiled constraints - {:#?}", output);
}

View File

@ -50,6 +50,9 @@ impl InputFile {
[main]
a: u32 = 1;
b: u32 = 2;
[registers]
r0: u32 = 0;
"#,
self.package_name
)