cargo clippy

This commit is contained in:
collin 2022-02-07 11:58:41 -05:00
parent b31071777b
commit 815bddce94
7 changed files with 246 additions and 231 deletions

125
Cargo.lock generated
View File

@ -112,6 +112,15 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -823,12 +832,6 @@ version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.11" version = "0.3.11"
@ -960,30 +963,6 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "include_dir"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24b56e147e6187d61e9d0f039f10e070d0c0a887e24fe0bb9ca3f29bfde62cab"
dependencies = [
"glob",
"include_dir_impl",
"proc-macro-hack",
]
[[package]]
name = "include_dir_impl"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a0c890c85da4bab7bce4204c707396bbd3c6c8a681716a51c8814cfc2b682df"
dependencies = [
"anyhow",
"proc-macro-hack",
"proc-macro2 1.0.36",
"quote 1.0.15",
"syn 1.0.86",
]
[[package]] [[package]]
name = "indenter" name = "indenter"
version = "0.3.3" version = "0.3.3"
@ -1142,17 +1121,6 @@ dependencies = [
"tendril", "tendril",
] ]
[[package]]
name = "leo-ast-passes"
version = "1.5.3"
dependencies = [
"indexmap",
"leo-ast",
"leo-errors",
"leo-parser",
"leo-stdlib",
]
[[package]] [[package]]
name = "leo-compiler" name = "leo-compiler"
version = "1.5.3" version = "1.5.3"
@ -1219,6 +1187,7 @@ dependencies = [
"self_update", "self_update",
"serde", "serde",
"serde_json", "serde_json",
"snarkvm-utilities",
"structopt", "structopt",
"test_dir", "test_dir",
"toml", "toml",
@ -1273,17 +1242,6 @@ dependencies = [
"tendril", "tendril",
] ]
[[package]]
name = "leo-stdlib"
version = "1.5.3"
dependencies = [
"include_dir",
"indexmap",
"leo-ast",
"leo-errors",
"leo-parser",
]
[[package]] [[package]]
name = "leo-test-framework" name = "leo-test-framework"
version = "1.5.3" version = "1.5.3"
@ -1526,6 +1484,27 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.14" version = "0.2.14"
@ -1761,6 +1740,15 @@ dependencies = [
"termtree", "termtree",
] ]
[[package]]
name = "proc-macro-crate"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785"
dependencies = [
"toml",
]
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -1785,12 +1773,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "0.4.30" version = "0.4.30"
@ -2281,6 +2263,33 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "snarkvm-derives"
version = "0.7.5"
source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661"
dependencies = [
"proc-macro-crate",
"proc-macro-error",
"proc-macro2 1.0.36",
"quote 1.0.15",
"syn 1.0.86",
]
[[package]]
name = "snarkvm-utilities"
version = "0.7.5"
source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661"
dependencies = [
"anyhow",
"bincode",
"itertools 0.10.3",
"num-bigint",
"rand 0.8.4",
"serde",
"snarkvm-derives",
"thiserror",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.4.4" version = "0.4.4"

View File

@ -30,7 +30,7 @@ members = [
# "asg", # "asg",
# "asg-passes", # "asg-passes",
"ast", "ast",
"ast-passes", # "ast-passes",
"compiler", "compiler",
"errors", "errors",
"grammar", "grammar",
@ -102,9 +102,9 @@ version = "1.5.3"
#rev = "51633e2" #rev = "51633e2"
#default-features = false #default-features = false
# #
#[dependencies.snarkvm-utilities] [dependencies.snarkvm-utilities]
#git = "https://github.com/AleoHQ/snarkVM.git" git = "https://github.com/AleoHQ/snarkVM.git"
#rev = "51633e2" rev = "51633e2"
[dependencies.clap] [dependencies.clap]
version = "3.0.10" version = "3.0.10"

View File

@ -36,6 +36,6 @@ version = "1.5.3"
path = "../parser" path = "../parser"
version = "1.5.3" version = "1.5.3"
[dependencies.leo-stdlib] #[dependencies.leo-stdlib]
path = "../stdlib" #path = "../stdlib"
version = "1.5.3" #version = "1.5.3"

View File

@ -21,6 +21,8 @@ use std::{
fmt::{Debug, Display}, fmt::{Debug, Display},
}; };
// todo (collin): redo these after Mazdak finishes error indexing.
create_errors!( create_errors!(
/// PackageError enum that represents all the errors for the `leo-package` crate. /// PackageError enum that represents all the errors for the `leo-package` crate.
PackageError, PackageError,

View File

@ -29,6 +29,7 @@ use commands::{
// Deploy, Init, Lint, New, Prove, Run, Setup, Test, Update, Watch, // Deploy, Init, Lint, New, Prove, Run, Setup, Test, Update, Watch,
}; };
use leo_errors::Result; use leo_errors::Result;
use snarkvm_utilities::Write;
use std::{path::PathBuf, process::exit}; use std::{path::PathBuf, process::exit};
use structopt::{clap::AppSettings, StructOpt}; use structopt::{clap::AppSettings, StructOpt};

View File

@ -19,8 +19,10 @@ use std::path::PathBuf;
use crate::{ use crate::{
commands::{ commands::{
package::{Login, Logout}, // package::{Login, Logout},
Build, Command, Prove, Run, Setup, Test, Build,
Command,
// Prove, Run, Setup, Test,
}, },
context::{create_context, Context}, context::{create_context, Context},
}; };
@ -51,170 +53,171 @@ pub fn build_pedersen_hash() -> Result<()> {
Ok(()) Ok(())
} }
#[test] // todo (collin): uncomment after refactor
pub fn setup_pedersen_hash() -> Result<()> { // #[test]
let build = (Build { // pub fn setup_pedersen_hash() -> Result<()> {
compiler_options: Default::default(), // let build = (Build {
}) // compiler_options: Default::default(),
.apply(context()?, ())?; // })
(Setup { // .apply(context()?, ())?;
skip_key_check: false, // (Setup {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, build.clone())?; // })
(Setup { // .apply(context()?, build.clone())?;
skip_key_check: true, // (Setup {
compiler_options: Default::default(), // skip_key_check: true,
}) // compiler_options: Default::default(),
.apply(context()?, build)?; // })
Ok(()) // .apply(context()?, build)?;
} // Ok(())
// }
#[test] //
pub fn prove_pedersen_hash() -> Result<()> { // #[test]
let build = (Build { // pub fn prove_pedersen_hash() -> Result<()> {
compiler_options: Default::default(), // let build = (Build {
}) // compiler_options: Default::default(),
.apply(context()?, ())?; // })
let setup = (Setup { // .apply(context()?, ())?;
skip_key_check: false, // let setup = (Setup {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, build)?; // })
(Prove { // .apply(context()?, build)?;
skip_key_check: false, // (Prove {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, setup.clone())?; // })
(Prove { // .apply(context()?, setup.clone())?;
skip_key_check: true, // (Prove {
compiler_options: Default::default(), // skip_key_check: true,
}) // compiler_options: Default::default(),
.apply(context()?, setup)?; // })
Ok(()) // .apply(context()?, setup)?;
} // Ok(())
// }
#[test] //
pub fn run_pedersen_hash() -> Result<()> { // #[test]
let build = (Build { // pub fn run_pedersen_hash() -> Result<()> {
compiler_options: Default::default(), // let build = (Build {
}) // compiler_options: Default::default(),
.apply(context()?, ())?; // })
let setup = (Setup { // .apply(context()?, ())?;
skip_key_check: false, // let setup = (Setup {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, build)?; // })
let prove = (Prove { // .apply(context()?, build)?;
skip_key_check: false, // let prove = (Prove {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, setup)?; // })
(Run { // .apply(context()?, setup)?;
skip_key_check: false, // (Run {
compiler_options: Default::default(), // skip_key_check: false,
}) // compiler_options: Default::default(),
.apply(context()?, prove.clone())?; // })
(Run { // .apply(context()?, prove.clone())?;
skip_key_check: true, // (Run {
compiler_options: Default::default(), // skip_key_check: true,
}) // compiler_options: Default::default(),
.apply(context()?, prove)?; // })
Ok(()) // .apply(context()?, prove)?;
} // Ok(())
// }
#[test] //
pub fn test_pedersen_hash() -> Result<()> { // #[test]
let mut main_file = PathBuf::from(PEDERSEN_HASH_PATH); // pub fn test_pedersen_hash() -> Result<()> {
main_file.push("src/main.leo"); // let mut main_file = PathBuf::from(PEDERSEN_HASH_PATH);
// main_file.push("src/main.leo");
(Test { //
files: vec![], // (Test {
compiler_options: Default::default(), // files: vec![],
}) // compiler_options: Default::default(),
.apply(context()?, ())?; // })
(Test { // .apply(context()?, ())?;
files: vec![main_file], // (Test {
compiler_options: Default::default(), // files: vec![main_file],
}) // compiler_options: Default::default(),
.apply(context()?, ())?; // })
Ok(()) // .apply(context()?, ())?;
} // Ok(())
// }
#[test] //
pub fn test_logout() -> Result<()> { // #[test]
let logout = (Logout {}).apply(context()?, ()); // pub fn test_logout() -> Result<()> {
assert!(logout.is_err()); // let logout = (Logout {}).apply(context()?, ());
Ok(()) // assert!(logout.is_err());
} // Ok(())
// }
// Decided to not go all-in on error messages since they might change in the future //
// So this test only tells that error cases are errors // // Decided to not go all-in on error messages since they might change in the future
#[test] // // So this test only tells that error cases are errors
pub fn login_incorrect_credentials_or_token() -> Result<()> { // #[test]
test_logout()?; // pub fn login_incorrect_credentials_or_token() -> Result<()> {
// test_logout()?;
// no credentials passed //
let login = Login::new(None, None, None).apply(context()?, ()); // // no credentials passed
assert!(login.is_err()); // let login = Login::new(None, None, None).apply(context()?, ());
// assert!(login.is_err());
// incorrect token //
let login = Login::new(Some("none".to_string()), None, None).apply(context()?, ()); // // incorrect token
assert!(login.is_err()); // let login = Login::new(Some("none".to_string()), None, None).apply(context()?, ());
// assert!(login.is_err());
// only user, no pass //
let login = Login::new(None, Some("user".to_string()), None).apply(context()?, ()); // // only user, no pass
assert!(login.is_err()); // let login = Login::new(None, Some("user".to_string()), None).apply(context()?, ());
// assert!(login.is_err());
// no user, only pass //
let login = Login::new(None, None, Some("pass".to_string())).apply(context()?, ()); // // no user, only pass
assert!(login.is_err()); // let login = Login::new(None, None, Some("pass".to_string())).apply(context()?, ());
// assert!(login.is_err());
Ok(()) //
} // Ok(())
// }
#[cfg(not(target_os = "macos"))] //
#[test] // #[cfg(not(target_os = "macos"))]
pub fn leo_update_and_update_automatic() -> Result<()> { // #[test]
use crate::commands::{Update, UpdateAutomatic}; // pub fn leo_update_and_update_automatic() -> Result<()> {
// use crate::commands::{Update, UpdateAutomatic};
let update = Update { //
list: true, // let update = Update {
studio: true, // list: true,
automatic: None, // studio: true,
}; // automatic: None,
update.apply(context()?, ())?; // };
// update.apply(context()?, ())?;
let update = Update { //
list: false, // let update = Update {
studio: true, // list: false,
automatic: None, // studio: true,
}; // automatic: None,
update.apply(context()?, ())?; // };
// update.apply(context()?, ())?;
let update = Update { //
list: false, // let update = Update {
studio: false, // list: false,
automatic: None, // studio: false,
}; // automatic: None,
update.apply(context()?, ())?; // };
// update.apply(context()?, ())?;
let update = Update { //
list: false, // let update = Update {
studio: false, // list: false,
automatic: Some(UpdateAutomatic::Automatic { value: true }), // studio: false,
}; // automatic: Some(UpdateAutomatic::Automatic { value: true }),
update.apply(context()?, ())?; // };
// update.apply(context()?, ())?;
let update = Update { //
list: false, // let update = Update {
studio: false, // list: false,
automatic: Some(UpdateAutomatic::Automatic { value: false }), // studio: false,
}; // automatic: Some(UpdateAutomatic::Automatic { value: false }),
update.apply(context()?, ())?; // };
// update.apply(context()?, ())?;
Ok(()) //
} // Ok(())
// }
/// Create context for Pedersen Hash example /// Create context for Pedersen Hash example
fn context() -> Result<Context> { fn context() -> Result<Context> {