Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure Nargo CLI functions #4744

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

Conversation

michaeljklein
Copy link
Contributor

@michaeljklein michaeljklein commented Apr 9, 2024

Description

Problem*

Test nargo's primary commands (check, compile, ..) without touching the filesystem.

Summary*

TODO:

  • test against example json file
  • make example json file unit test case

Each CLI command has a run function.

This PR splits that function into run and run_pure, where run reads/writes files and run_pure does everything else.

It also adds Serialize/Deserialize impl's for FileManager and Workspace, to allow specifying an entire workspace as a single json file. (Enable with --features "fm/serde nargo/serde")

Additional Context

I attempted to implement a pure version of verify but it has two stages of pure execution (compile, read inputs, then verify) which got complex so leaving it and test out for now: check/compile/execute are the focus of most tests I'm looking at anyway.

Example application

Dumping all compilation test cases as json:

pub fn compile_workspace_full_pure(
    workspace: &Workspace,
    workspace_file_manager: FileManager,
    compile_options: &CompileOptions,
) -> Result<(ExpressionWidth, Vec<CompiledProgram>, Vec<CompiledContract>), CliError> {

    // this is added
    use std::fs::OpenOptions;
    use std::io::prelude::*;

    let mut file = OpenOptions::new()
        .create(true)
        .write(true)
        .append(true)
        .open("test_cases_compile.json")
        .unwrap();

    writeln!(file, "{:?}", serde_json::to_string(&(workspace, workspace_file_manager.clone())).unwrap()).unwrap();

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@michaeljklein michaeljklein mentioned this pull request Apr 22, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant