fix test, login, build console output

This commit is contained in:
collin 2020-08-21 17:39:48 -07:00
parent 098ca28231
commit 2e3333cd25
7 changed files with 69 additions and 54 deletions

View File

@ -120,22 +120,21 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
input, // pass program input into every test
);
if result.is_ok() {
tracing::info!(
"test {} compiled successfully. Constraint system satisfied: {}",
full_test_name,
cs.is_satisfied()
);
match (result.is_ok(), cs.is_satisfied()) {
(true, true) => {
tracing::info!("{} ... ok", full_test_name);
// write result to file
let output = result?;
let output_file = OutputFile::new(&output_file_name);
// write result to file
let output = result?;
let output_file = OutputFile::new(&output_file_name);
tracing::info!("\tWriting output to registers in `{}.out` ...", output_file_name);
output_file.write(output_directory, output.bytes()).unwrap();
} else {
// tracing::error!("test {} errored: {}", full_test_name, result.unwrap_err());
output_file.write(output_directory, output.bytes()).unwrap();
}
(true, false) => tracing::error!("{} constraint system not satisfied", full_test_name),
(false, _) => {
let error = result.unwrap_err();
tracing::error!("{} failed due to error\n{}", full_test_name, error);
}
}
}

View File

@ -71,7 +71,7 @@ impl CLI for BuildCommand {
let mut output_directory = package_path.clone();
output_directory.push(OUTPUTS_DIRECTORY_NAME);
// Begin "Compiling" context for logging
// Begin "Compiling" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Compiling");
let enter = span.enter();
@ -178,10 +178,12 @@ impl CLI for BuildCommand {
tracing::debug!("Checksum saved ({:?})", path);
}
// Drop "Compiling" context for console logging
drop(enter);
// Begin "Finished" context for console logging todo: @collin figure a way to get this output with tracing without dropping span
tracing::span!(tracing::Level::INFO, " Finished").in_scope(|| {
tracing::info!("in {} milliseconds", start.elapsed().as_millis());
tracing::info!("compiled in {} milliseconds", start.elapsed().as_millis());
});
return Ok(Some((program, checksum_differs)));

View File

@ -25,10 +25,7 @@ use crate::{
cli::CLI,
cli_types::*,
config::*,
errors::{
CLIError::LoginError,
LoginError::{CannotGetToken, NoConnectionFound, NoCredentialsProvided, WrongLoginOrPassword},
},
errors::LoginError::{CannotGetToken, NoConnectionFound, NoCredentialsProvided, WrongLoginOrPassword},
};
use std::collections::HashMap;
@ -78,6 +75,10 @@ impl CLI for LoginCommand {
}
fn output(options: Self::Options) -> Result<Self::Output, crate::errors::CLIError> {
// Begin "Login" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Login");
let _enter = span.enter();
let token = match options {
// Login using existing token
(Some(token), _, _) => Some(token),
@ -95,22 +96,19 @@ impl CLI for LoginCommand {
Ok(result) => match result.json() {
Ok(json) => json,
Err(_error) => {
tracing::error!("Wrong login or password");
return Err(WrongLoginOrPassword("Wrong login or password".into()).into());
return Err(WrongLoginOrPassword.into());
}
},
//Cannot connect to the server
Err(_error) => {
return Err(LoginError(NoConnectionFound(
"Could not connect to the package manager".into(),
)));
return Err(NoConnectionFound.into());
}
};
match response.get("token") {
Some(token) => Some(token.clone()),
None => {
return Err(CannotGetToken("No token was provided in the response".into()).into());
return Err(CannotGetToken.into());
}
}
}
@ -124,7 +122,7 @@ impl CLI for LoginCommand {
Some(token) => {
write_token(token.as_str())?;
tracing::info!("login successful.");
tracing::info!("success");
Ok(token)
}

View File

@ -66,6 +66,13 @@ impl CLI for SetupCommand {
match BuildCommand::output(options)? {
Some((program, checksum_differs)) => {
// Begin "Setup" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Setup");
let enter = span.enter();
// Start the timer
let start = Instant::now();
// Check if a proving key and verification key already exists
let keys_exist = ProvingKeyFile::new(&package_name).exists_at(&path)
&& VerificationKeyFile::new(&package_name).exists_at(&path);
@ -117,7 +124,13 @@ impl CLI for SetupCommand {
(proving_key, prepared_verifying_key)
};
tracing::info!("Program setup complete");
// Drop "Setup" context for console logging
drop(enter);
// Begin "Finished" context for console logging
tracing::span!(tracing::Level::INFO, " Finished").in_scope(|| {
tracing::info!("setup in {} seconds", start.elapsed().as_secs());
});
Ok((program, proving_key, prepared_verifying_key))
}

View File

@ -17,20 +17,20 @@
use crate::{
cli::*,
cli_types::*,
errors::{CLIError, TestError},
errors::{CLIError, TestError::ProgramFileDoesNotExist},
};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
root::Manifest,
source::{MainFile, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
source::{LibFile, MainFile, LIB_FILE_NAME, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
};
use snarkos_curves::edwards_bls12::Fq;
use clap::ArgMatches;
use std::{convert::TryFrom, env::current_dir};
use std::{convert::TryFrom, env::current_dir, time::Instant};
#[derive(Debug)]
pub struct TestCommand;
@ -65,15 +65,17 @@ impl CLI for TestCommand {
package_path.pop();
}
// Verify the main file exists
if !MainFile::exists_at(&package_path) {
return Err(TestError::MainFileDoesNotExist(package_path.as_os_str().to_owned()).into());
}
let mut file_path = package_path.clone();
file_path.push(SOURCE_DIRECTORY_NAME);
// Construct the path to the main file in the source directory
let mut main_file_path = package_path.clone();
main_file_path.push(SOURCE_DIRECTORY_NAME);
main_file_path.push(MAIN_FILE_NAME);
// Verify a main or library file exists
if MainFile::exists_at(&package_path) {
file_path.push(MAIN_FILE_NAME);
} else if LibFile::exists_at(&package_path) {
file_path.push(LIB_FILE_NAME);
} else {
return Err(ProgramFileDoesNotExist(package_path.into()).into());
}
// Construct the path to the output directory;
let mut output_directory = package_path.clone();
@ -82,10 +84,17 @@ impl CLI for TestCommand {
// Create the output directory
OutputsDirectory::create(&package_path)?;
// Begin "Test" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Test");
let enter = span.enter();
// Start the timer
let start = Instant::now();
// Parse the current main program file
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
package_name.clone(),
main_file_path.clone(),
file_path.clone(),
output_directory,
)?;
@ -95,7 +104,6 @@ impl CLI for TestCommand {
// Run tests
let temporary_program = program.clone();
let output = temporary_program.compile_test_constraints(pairs)?;
tracing::debug!("Compiled constraints - {:#?}", output);
Ok(())
}

View File

@ -14,19 +14,17 @@
// 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 std::ffi::OsString;
#[derive(Debug, Error)]
pub enum LoginError {
#[error("{:?}", _0)]
CannotGetToken(OsString),
#[error("No token was provided in the response")]
CannotGetToken,
#[error("No connection found {:?}", _0)]
NoConnectionFound(OsString),
#[error("Could not connect to the package manager")]
NoConnectionFound,
#[error("No login credentials were provided")]
NoCredentialsProvided,
#[error("Wrong login or password {:?}", _0)]
WrongLoginOrPassword(OsString),
#[error("Wrong login or password")]
WrongLoginOrPassword,
}

View File

@ -20,9 +20,6 @@ use std::ffi::OsString;
#[derive(Debug, Error)]
pub enum TestError {
#[error("main file {:?} does not exist", _0)]
MainFileDoesNotExist(OsString),
#[error("{}", _0)]
ManifestError(#[from] ManifestError),
#[error("could not find main or library file in {:?}", _0)]
ProgramFileDoesNotExist(OsString),
}