mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 19:51:52 +03:00
Merge pull request #157 from AleoHQ/fix/leo-test
fix leo test to run tests in isolation
This commit is contained in:
commit
1e7a6bf4ca
86
.github/workflows/leo.yml
vendored
Normal file
86
.github/workflows/leo.yml
vendored
Normal 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
|
@ -345,8 +345,8 @@ input_keyword = { "input" }
|
|||||||
|
|
||||||
// Declared in functions/input/input.rs
|
// Declared in functions/input/input.rs
|
||||||
input = {
|
input = {
|
||||||
input_keyword
|
function_input
|
||||||
| function_input
|
| input_keyword
|
||||||
}
|
}
|
||||||
input_list = _{ (input ~ ("," ~ NEWLINE* ~ input)*)? }
|
input_list = _{ (input ~ ("," ~ NEWLINE* ~ input)*)? }
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ use leo_typed::{Input, LeoTypedAst, MainInput, Program};
|
|||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
use snarkos_models::{
|
use snarkos_models::{
|
||||||
curves::{Field, PrimeField},
|
curves::{Field, PrimeField},
|
||||||
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem, TestConstraintSystem},
|
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
|
||||||
};
|
};
|
||||||
|
|
||||||
use sha2::{Digest, Sha256};
|
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.
|
/// Synthesizes the circuit for test functions with program input.
|
||||||
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
|
pub fn compile_test_constraints(self) -> Result<(), CompilerError> {
|
||||||
generate_test_constraints::<F, G>(cs, self.program, self.program_input, &self.imported_programs)
|
generate_test_constraints::<F, G>(self.program, self.program_input, &self.imported_programs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls the internal generate_constraints method with arguments
|
/// Calls the internal generate_constraints method with arguments
|
||||||
|
@ -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>>(
|
pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||||
cs: &mut TestConstraintSystem<F>,
|
|
||||||
program: Program,
|
program: Program,
|
||||||
input: Input,
|
input: Input,
|
||||||
imported_programs: &ImportParser,
|
imported_programs: &ImportParser,
|
||||||
@ -57,6 +56,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
|||||||
log::info!("Running {} tests", tests.len());
|
log::info!("Running {} tests", tests.len());
|
||||||
|
|
||||||
for (test_name, test_function) in tests.into_iter() {
|
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 full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string());
|
||||||
|
|
||||||
let result = resolved_program.enforce_main_function(
|
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() {
|
if result.is_ok() {
|
||||||
log::info!(
|
log::info!(
|
||||||
"test {} passed. Constraint system satisfied: {}",
|
"test {} compiled successfully. Constraint system satisfied: {}",
|
||||||
full_test_name,
|
full_test_name,
|
||||||
cs.is_satisfied()
|
cs.is_satisfied()
|
||||||
);
|
);
|
||||||
|
@ -76,10 +76,17 @@ impl CLI for InitCommand {
|
|||||||
// Verify the input file does not exist
|
// Verify the input file does not exist
|
||||||
let input_file = InputFile::new(&package_name);
|
let input_file = InputFile::new(&package_name);
|
||||||
if !input_file.exists_at(&path) {
|
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)?;
|
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
|
// Verify the main file does not exist
|
||||||
if !MainFile::exists_at(&path) {
|
if !MainFile::exists_at(&path) {
|
||||||
// Create the main file in the source directory
|
// Create the main file in the source directory
|
||||||
|
@ -90,9 +90,12 @@ impl CLI for NewCommand {
|
|||||||
// Create the input directory
|
// Create the input directory
|
||||||
InputsDirectory::create(&path)?;
|
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)?;
|
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
|
// Create the main file in the source directory
|
||||||
MainFile::new(&package_name).write_to(&path)?;
|
MainFile::new(&package_name).write_to(&path)?;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ use leo_package::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use snarkos_curves::edwards_bls12::Fq;
|
use snarkos_curves::edwards_bls12::Fq;
|
||||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use std::{convert::TryFrom, env::current_dir};
|
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
|
// Generate the program on the constraint system and verify correctness
|
||||||
{
|
{
|
||||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
|
||||||
let temporary_program = program.clone();
|
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);
|
log::debug!("Compiled constraints - {:#?}", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@ impl InputFile {
|
|||||||
[main]
|
[main]
|
||||||
a: u32 = 1;
|
a: u32 = 1;
|
||||||
b: u32 = 2;
|
b: u32 = 2;
|
||||||
|
|
||||||
|
[registers]
|
||||||
|
r0: u32 = 0;
|
||||||
"#,
|
"#,
|
||||||
self.package_name
|
self.package_name
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user