mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-25 05:36:50 +03:00
Rename all instances of 'ctx' to 'context'
This commit is contained in:
parent
e9c832c871
commit
2e00ff451e
@ -40,7 +40,7 @@ fn load_asg_imports<'a, T: ImportResolver<'a>>(
|
||||
InternalProgram::new(context, &ast.as_repr(), imports)
|
||||
}
|
||||
|
||||
fn mocked_resolver<'a>(_ctx: AsgContext<'a>) -> MockedImportResolver<'a> {
|
||||
fn mocked_resolver<'a>(_context: AsgContext<'a>) -> MockedImportResolver<'a> {
|
||||
let packages = indexmap::IndexMap::new();
|
||||
MockedImportResolver { packages }
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ use std::path::Path;
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let program_string = include_str!("./circuits/pedersen_mock.leo");
|
||||
let ctx = new_context();
|
||||
let asg = load_asg(&ctx, program_string).unwrap();
|
||||
let context = new_context();
|
||||
let asg = load_asg(&context, program_string).unwrap();
|
||||
let reformed_ast = leo_asg::reform_ast(&asg);
|
||||
println!("{}", reformed_ast);
|
||||
// panic!();
|
||||
@ -51,8 +51,8 @@ fn test_function_rename() {
|
||||
console.assert(total == 20);
|
||||
}
|
||||
"#;
|
||||
let ctx = new_context();
|
||||
let asg = load_asg(&ctx, program_string).unwrap();
|
||||
let context = new_context();
|
||||
let asg = load_asg(&context, program_string).unwrap();
|
||||
let reformed_ast = leo_asg::reform_ast(&asg);
|
||||
println!("{}", reformed_ast);
|
||||
// panic!();
|
||||
@ -60,8 +60,8 @@ fn test_function_rename() {
|
||||
|
||||
#[test]
|
||||
fn test_imports() {
|
||||
let ctx = new_context();
|
||||
let mut imports = crate::mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = crate::mocked_resolver(&context);
|
||||
let test_import = r#"
|
||||
circuit Point {
|
||||
x: u32
|
||||
@ -74,7 +74,7 @@ fn test_imports() {
|
||||
"#;
|
||||
imports
|
||||
.packages
|
||||
.insert("test-import".to_string(), load_asg(&ctx, test_import).unwrap());
|
||||
.insert("test-import".to_string(), load_asg(&context, test_import).unwrap());
|
||||
let program_string = r#"
|
||||
import test-import.foo;
|
||||
|
||||
@ -95,7 +95,7 @@ fn test_imports() {
|
||||
serde_json::to_string(Ast::new("test", &test_grammar).unwrap().as_repr()).unwrap()
|
||||
);
|
||||
|
||||
let asg = crate::load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
let asg = crate::load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
let reformed_ast = leo_asg::reform_ast(&asg);
|
||||
println!("{}", serde_json::to_string(&reformed_ast).unwrap());
|
||||
// panic!();
|
||||
|
@ -20,138 +20,139 @@ use crate::{load_asg, load_asg_imports, mocked_resolver};
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
let program_string = include_str!("basic.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
let program_string = include_str!("multiple.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_star() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
|
||||
let program_string = include_str!("star.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alias() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
|
||||
let program_string = include_str!("alias.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
// naming tests
|
||||
#[test]
|
||||
fn test_name() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"hello-world".to_string(),
|
||||
load_asg(&ctx, include_str!("src/hello-world.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/hello-world.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"a0-f".to_string(),
|
||||
load_asg(&ctx, include_str!("src/a0-f.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/a0-f.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"a-9".to_string(),
|
||||
load_asg(&context, include_str!("src/a-9.leo")).unwrap(),
|
||||
);
|
||||
imports
|
||||
.packages
|
||||
.insert("a-9".to_string(), load_asg(&ctx, include_str!("src/a-9.leo")).unwrap());
|
||||
|
||||
let program_string = include_str!("names.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
// more complex tests
|
||||
#[test]
|
||||
fn test_many_import() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/lib.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.baz".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.baz".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.bat.bat".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"car".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/car/src/lib.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(),
|
||||
);
|
||||
|
||||
let program_string = include_str!("many_import.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_many_import_star() {
|
||||
let ctx = new_context();
|
||||
let mut imports = mocked_resolver(&ctx);
|
||||
let context = new_context();
|
||||
let mut imports = mocked_resolver(&context);
|
||||
imports.packages.insert(
|
||||
"test-import".to_string(),
|
||||
load_asg(&ctx, include_str!("src/test-import.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/lib.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.baz".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.baz".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"bar.bat.bat".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
|
||||
);
|
||||
imports.packages.insert(
|
||||
"car".to_string(),
|
||||
load_asg(&ctx, include_str!("imports/car/src/lib.leo")).unwrap(),
|
||||
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(),
|
||||
);
|
||||
|
||||
let program_string = include_str!("many_import_star.leo");
|
||||
load_asg_imports(&ctx, program_string, &mut imports).unwrap();
|
||||
load_asg_imports(&context, program_string, &mut imports).unwrap();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ pub struct Compiler<'a, F: PrimeField, G: GroupType<F>> {
|
||||
output_directory: PathBuf,
|
||||
program: Program,
|
||||
program_input: Input,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
asg: Option<Asg<'a>>,
|
||||
_engine: PhantomData<F>,
|
||||
_group: PhantomData<G>,
|
||||
@ -73,7 +73,12 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
///
|
||||
/// Returns a new Leo program compiler.
|
||||
///
|
||||
pub fn new(package_name: String, main_file_path: PathBuf, output_directory: PathBuf, ctx: AsgContext<'a>) -> Self {
|
||||
pub fn new(
|
||||
package_name: String,
|
||||
main_file_path: PathBuf,
|
||||
output_directory: PathBuf,
|
||||
context: AsgContext<'a>,
|
||||
) -> Self {
|
||||
Self {
|
||||
program_name: package_name.clone(),
|
||||
main_file_path,
|
||||
@ -81,7 +86,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
program: Program::new(package_name),
|
||||
program_input: Input::new(),
|
||||
asg: None,
|
||||
ctx,
|
||||
context,
|
||||
_engine: PhantomData,
|
||||
_group: PhantomData,
|
||||
}
|
||||
@ -98,9 +103,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
package_name: String,
|
||||
main_file_path: PathBuf,
|
||||
output_directory: PathBuf,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
) -> Result<Self, CompilerError> {
|
||||
let mut compiler = Self::new(package_name, main_file_path, output_directory, ctx);
|
||||
let mut compiler = Self::new(package_name, main_file_path, output_directory, context);
|
||||
|
||||
compiler.parse_program()?;
|
||||
|
||||
@ -124,9 +129,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
input_path: &Path,
|
||||
state_string: &str,
|
||||
state_path: &Path,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
) -> Result<Self, CompilerError> {
|
||||
let mut compiler = Self::new(package_name, main_file_path, output_directory, ctx);
|
||||
let mut compiler = Self::new(package_name, main_file_path, output_directory, context);
|
||||
|
||||
compiler.parse_input(input_string, input_path, state_string, state_path)?;
|
||||
|
||||
@ -205,7 +210,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
tracing::debug!("Program parsing complete\n{:#?}", self.program);
|
||||
|
||||
// Create a new symbol table from the program, imported_programs, and program_input.
|
||||
let asg = Asg::new(self.ctx, &core_ast, &mut leo_imports::ImportParser::default())?;
|
||||
let asg = Asg::new(self.context, &core_ast, &mut leo_imports::ImportParser::default())?;
|
||||
|
||||
tracing::debug!("ASG generation complete");
|
||||
|
||||
|
@ -34,7 +34,7 @@ pub struct ImportParser<'a> {
|
||||
impl<'a> ImportResolver<'a> for ImportParser<'a> {
|
||||
fn resolve_package(
|
||||
&mut self,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
package_segments: &[&str],
|
||||
span: &Span,
|
||||
) -> Result<Option<Program<'a>>, AsgConvertError> {
|
||||
@ -51,7 +51,7 @@ impl<'a> ImportResolver<'a> for ImportParser<'a> {
|
||||
|
||||
self.partial_imports.insert(full_path.clone());
|
||||
let program = imports
|
||||
.parse_package(ctx, path, package_segments, span)
|
||||
.parse_package(context, path, package_segments, span)
|
||||
.map_err(|x| -> AsgConvertError { x.into() })?;
|
||||
self.partial_imports.remove(&full_path);
|
||||
self.imports.insert(full_path, program.clone());
|
||||
|
@ -26,16 +26,16 @@ static IMPORTS_DIRECTORY_NAME: &str = "imports/";
|
||||
impl<'a> ImportParser<'a> {
|
||||
fn parse_package_access(
|
||||
&mut self,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
package: &DirEntry,
|
||||
remaining_segments: &[&str],
|
||||
span: &Span,
|
||||
) -> Result<Program<'a>, ImportParserError> {
|
||||
if !remaining_segments.is_empty() {
|
||||
return self.parse_package(ctx, package.path(), remaining_segments, span);
|
||||
return self.parse_package(context, package.path(), remaining_segments, span);
|
||||
}
|
||||
let program = Self::parse_import_file(package, span)?;
|
||||
let asg = leo_asg::InternalProgram::new(ctx, &program, self)?;
|
||||
let asg = leo_asg::InternalProgram::new(context, &program, self)?;
|
||||
|
||||
Ok(asg)
|
||||
}
|
||||
@ -47,7 +47,7 @@ impl<'a> ImportParser<'a> {
|
||||
///
|
||||
pub(crate) fn parse_package(
|
||||
&mut self,
|
||||
ctx: AsgContext<'a>,
|
||||
context: AsgContext<'a>,
|
||||
mut path: PathBuf,
|
||||
segments: &[&str],
|
||||
span: &Span,
|
||||
@ -113,8 +113,8 @@ impl<'a> ImportParser<'a> {
|
||||
package_name,
|
||||
span,
|
||||
))),
|
||||
(Some(source_entry), None) => self.parse_package_access(ctx, &source_entry, &segments[1..], span),
|
||||
(None, Some(import_entry)) => self.parse_package_access(ctx, &import_entry, &segments[1..], span),
|
||||
(Some(source_entry), None) => self.parse_package_access(context, &source_entry, &segments[1..], span),
|
||||
(None, Some(import_entry)) => self.parse_package_access(context, &import_entry, &segments[1..], span),
|
||||
(None, None) => Err(ImportParserError::unknown_package(Identifier::new_with_span(
|
||||
package_name,
|
||||
span,
|
||||
@ -123,7 +123,7 @@ impl<'a> ImportParser<'a> {
|
||||
} else {
|
||||
// Enforce local package access with no found imports directory
|
||||
match matched_source_entry {
|
||||
Some(source_entry) => self.parse_package_access(ctx, &source_entry, &segments[1..], span),
|
||||
Some(source_entry) => self.parse_package_access(context, &source_entry, &segments[1..], span),
|
||||
None => Err(ImportParserError::unknown_package(Identifier::new_with_span(
|
||||
package_name,
|
||||
span,
|
||||
|
@ -58,9 +58,9 @@ impl Command for Build {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = ctx.dir()?;
|
||||
let package_name = ctx.manifest()?.get_package_name();
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = context.dir()?;
|
||||
let package_name = context.manifest()?.get_package_name();
|
||||
|
||||
// Sanitize the package path to the root directory
|
||||
let mut package_path = path.clone();
|
||||
|
@ -45,9 +45,9 @@ impl Command for Clean {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = ctx.dir()?;
|
||||
let package_name = ctx.manifest()?.get_package_name();
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = context.dir()?;
|
||||
let package_name = context.manifest()?.get_package_name();
|
||||
|
||||
// Remove the checksum from the output directory
|
||||
ChecksumFile::new(&package_name).remove(&path)?;
|
||||
|
@ -95,7 +95,7 @@ pub trait Command {
|
||||
|
||||
/// Core of the execution - do what is necessary. This function is run within
|
||||
/// context of 'execute' function, which sets logging and timers
|
||||
fn apply(self, ctx: Context, input: Self::Input) -> Result<Self::Output>
|
||||
fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output>
|
||||
where
|
||||
Self: std::marker::Sized;
|
||||
|
||||
|
@ -90,9 +90,9 @@ impl Command for Add {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
// checking that manifest exists...
|
||||
if ctx.manifest().is_err() {
|
||||
if context.manifest().is_err() {
|
||||
return Err(anyhow!("Package Manifest not found, try running leo init or leo new"));
|
||||
};
|
||||
|
||||
@ -109,8 +109,8 @@ impl Command for Add {
|
||||
version,
|
||||
};
|
||||
|
||||
let bytes = ctx.api.run_route(fetch)?.bytes()?;
|
||||
let mut path = ctx.dir()?;
|
||||
let bytes = context.api.run_route(fetch)?.bytes()?;
|
||||
let mut path = context.dir()?;
|
||||
|
||||
{
|
||||
// setup directory structure since request was success
|
||||
|
@ -58,14 +58,14 @@ impl Command for Login {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
// quick hack to check if user is already logged in. ;)
|
||||
if ctx.api.auth_token().is_some() {
|
||||
if context.api.auth_token().is_some() {
|
||||
tracing::info!("You are already logged in");
|
||||
return Ok(ctx.api.auth_token().unwrap());
|
||||
return Ok(context.api.auth_token().unwrap());
|
||||
};
|
||||
|
||||
let mut api = ctx.api;
|
||||
let mut api = context.api;
|
||||
|
||||
// ...or trying to use arguments to either get token or user-pass
|
||||
let token = match (self.token, self.user, self.pass) {
|
||||
|
@ -44,7 +44,7 @@ impl Command for Logout {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, _ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
// the only error we're interested here is NotFound
|
||||
// however err in this case can also be of kind PermissionDenied or other
|
||||
if let Err(err) = remove_token() {
|
||||
|
@ -56,10 +56,10 @@ impl Command for Publish {
|
||||
Build::new().execute()
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _input: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, context: Context, _input: Self::Input) -> Result<Self::Output> {
|
||||
// Get the package manifest
|
||||
let path = ctx.dir()?;
|
||||
let manifest = ctx.manifest()?;
|
||||
let path = context.dir()?;
|
||||
let manifest = context.manifest()?;
|
||||
|
||||
let package_name = manifest.get_package_name();
|
||||
let package_version = manifest.get_package_version();
|
||||
@ -99,7 +99,7 @@ impl Command for Publish {
|
||||
// Client for make POST request
|
||||
let client = Client::new();
|
||||
|
||||
let token = match ctx.api.auth_token() {
|
||||
let token = match context.api.auth_token() {
|
||||
Some(token) => token,
|
||||
None => return Err(anyhow!("Login before publishing package: try leo login --help")),
|
||||
};
|
||||
|
@ -47,8 +47,8 @@ impl Command for Remove {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = ctx.dir()?;
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let path = context.dir()?;
|
||||
let package_name = self.name;
|
||||
|
||||
LeoPackage::remove_imported_package(&package_name, &path)?;
|
||||
|
@ -53,12 +53,12 @@ impl Command for Prove {
|
||||
Setup::new(self.skip_key_check).execute()
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
let (program, parameters, prepared_verifying_key) = input;
|
||||
|
||||
// Get the package name
|
||||
let path = ctx.dir()?;
|
||||
let package_name = ctx.manifest()?.get_package_name();
|
||||
let path = context.dir()?;
|
||||
let package_name = context.manifest()?.get_package_name();
|
||||
|
||||
tracing::info!("Starting...");
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl Command for Run {
|
||||
Prove::new(self.skip_key_check).execute()
|
||||
}
|
||||
|
||||
fn apply(self, _ctx: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, _context: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
let (proof, prepared_verifying_key) = input;
|
||||
|
||||
tracing::info!("Starting...");
|
||||
|
@ -60,9 +60,9 @@ impl Command for Setup {
|
||||
Build::new().execute()
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
let path = ctx.dir()?;
|
||||
let package_name = ctx.manifest()?.get_package_name();
|
||||
fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output> {
|
||||
let path = context.dir()?;
|
||||
let package_name = context.manifest()?.get_package_name();
|
||||
|
||||
match input {
|
||||
Some((program, checksum_differs)) => {
|
||||
|
@ -57,12 +57,12 @@ impl Command for Test {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
// Get the package name
|
||||
let package_name = ctx.manifest()?.get_package_name();
|
||||
let package_name = context.manifest()?.get_package_name();
|
||||
|
||||
// Sanitize the package path to the root directory
|
||||
let mut package_path = ctx.dir()?;
|
||||
let mut package_path = context.dir()?;
|
||||
if package_path.is_file() {
|
||||
package_path.pop();
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl Command for Watch {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply(self, _ctx: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||
let (tx, rx) = channel();
|
||||
let mut watcher = watcher(tx, Duration::from_secs(self.interval)).unwrap();
|
||||
|
||||
|
@ -158,7 +158,12 @@ where
|
||||
N: for<'a> FormatFields<'a> + 'static,
|
||||
T: FormatTime,
|
||||
{
|
||||
fn format_event(&self, ctx: &FmtContext<'_, S, N>, writer: &mut dyn fmt::Write, event: &Event<'_>) -> fmt::Result {
|
||||
fn format_event(
|
||||
&self,
|
||||
context: &FmtContext<'_, S, N>,
|
||||
writer: &mut dyn fmt::Write,
|
||||
event: &Event<'_>,
|
||||
) -> fmt::Result {
|
||||
let meta = event.metadata();
|
||||
|
||||
if self.display_level {
|
||||
@ -174,7 +179,7 @@ where
|
||||
|
||||
let mut message = "".to_string();
|
||||
|
||||
let scope = ctx.scope();
|
||||
let scope = context.scope();
|
||||
for span in scope {
|
||||
message += span.metadata().name();
|
||||
|
||||
@ -190,7 +195,7 @@ where
|
||||
write!(writer, "{:>10} ", colored_string(meta.level(), &message)).expect("Error writing event");
|
||||
}
|
||||
|
||||
ctx.format_fields(writer, event)?;
|
||||
context.format_fields(writer, event)?;
|
||||
writeln!(writer)
|
||||
}
|
||||
}
|
||||
|
@ -39,34 +39,34 @@ const PEDERSEN_HASH_PATH: &str = "./examples/pedersen-hash/";
|
||||
|
||||
#[test]
|
||||
pub fn build_pedersen_hash() -> Result<()> {
|
||||
Build::new().apply(ctx()?, ())?;
|
||||
Build::new().apply(context()?, ())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn setup_pedersen_hash() -> Result<()> {
|
||||
let build = Build::new().apply(ctx()?, ())?;
|
||||
Setup::new(false).apply(ctx()?, build.clone())?;
|
||||
Setup::new(true).apply(ctx()?, build)?;
|
||||
let build = Build::new().apply(context()?, ())?;
|
||||
Setup::new(false).apply(context()?, build.clone())?;
|
||||
Setup::new(true).apply(context()?, build)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn prove_pedersen_hash() -> Result<()> {
|
||||
let build = Build::new().apply(ctx()?, ())?;
|
||||
let setup = Setup::new(false).apply(ctx()?, build)?;
|
||||
Prove::new(false).apply(ctx()?, setup.clone())?;
|
||||
Prove::new(true).apply(ctx()?, setup)?;
|
||||
let build = Build::new().apply(context()?, ())?;
|
||||
let setup = Setup::new(false).apply(context()?, build)?;
|
||||
Prove::new(false).apply(context()?, setup.clone())?;
|
||||
Prove::new(true).apply(context()?, setup)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn run_pedersen_hash() -> Result<()> {
|
||||
let build = Build::new().apply(ctx()?, ())?;
|
||||
let setup = Setup::new(false).apply(ctx()?, build)?;
|
||||
let prove = Prove::new(false).apply(ctx()?, setup)?;
|
||||
Run::new(false).apply(ctx()?, prove.clone())?;
|
||||
Run::new(true).apply(ctx()?, prove)?;
|
||||
let build = Build::new().apply(context()?, ())?;
|
||||
let setup = Setup::new(false).apply(context()?, build)?;
|
||||
let prove = Prove::new(false).apply(context()?, setup)?;
|
||||
Run::new(false).apply(context()?, prove.clone())?;
|
||||
Run::new(true).apply(context()?, prove)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -75,14 +75,14 @@ pub fn test_pedersen_hash() -> Result<()> {
|
||||
let mut main_file = PathBuf::from(PEDERSEN_HASH_PATH);
|
||||
main_file.push("src/main.leo");
|
||||
|
||||
Test::new(Vec::new()).apply(ctx()?, ())?;
|
||||
Test::new(vec![main_file]).apply(ctx()?, ())?;
|
||||
Test::new(Vec::new()).apply(context()?, ())?;
|
||||
Test::new(vec![main_file]).apply(context()?, ())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_logout() -> Result<()> {
|
||||
Logout::new().apply(ctx()?, ())?;
|
||||
Logout::new().apply(context()?, ())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -91,19 +91,19 @@ pub fn test_logout() -> Result<()> {
|
||||
#[test]
|
||||
pub fn login_incorrect_credentials_or_token() -> Result<()> {
|
||||
// no credentials passed
|
||||
let login = Login::new(None, None, None).apply(ctx()?, ());
|
||||
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(ctx()?, ());
|
||||
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(ctx()?, ());
|
||||
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(ctx()?, ());
|
||||
let login = Login::new(None, None, Some("pass".to_string())).apply(context()?, ());
|
||||
assert!(login.is_err());
|
||||
|
||||
Ok(())
|
||||
@ -111,20 +111,20 @@ pub fn login_incorrect_credentials_or_token() -> Result<()> {
|
||||
|
||||
#[test]
|
||||
pub fn leo_update_and_update_automatic() -> Result<()> {
|
||||
Update::new(true, true, None).apply(ctx()?, ())?;
|
||||
Update::new(false, true, None).apply(ctx()?, ())?;
|
||||
Update::new(false, false, None).apply(ctx()?, ())?;
|
||||
Update::new(true, true, None).apply(context()?, ())?;
|
||||
Update::new(false, true, None).apply(context()?, ())?;
|
||||
Update::new(false, false, None).apply(context()?, ())?;
|
||||
|
||||
Update::new(false, false, Some(UpdateAutomatic::Automatic { value: true })).apply(ctx()?, ())?;
|
||||
Update::new(false, false, Some(UpdateAutomatic::Automatic { value: false })).apply(ctx()?, ())?;
|
||||
Update::new(false, false, Some(UpdateAutomatic::Automatic { value: true })).apply(context()?, ())?;
|
||||
Update::new(false, false, Some(UpdateAutomatic::Automatic { value: false })).apply(context()?, ())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create context for Pedersen Hash example
|
||||
fn ctx() -> Result<Context> {
|
||||
fn context() -> Result<Context> {
|
||||
let path = PathBuf::from(&PEDERSEN_HASH_PATH);
|
||||
let ctx = create_context(path)?;
|
||||
let context = create_context(path)?;
|
||||
|
||||
Ok(ctx)
|
||||
Ok(context)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user