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