diff --git a/.tool-versions b/.tool-versions index 49edbb5364..179f2a8c28 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.5.4 +scarb 2.6.5 diff --git a/crates/sncast/src/main.rs b/crates/sncast/src/main.rs index 6d5be21b38..e375c50b1b 100644 --- a/crates/sncast/src/main.rs +++ b/crates/sncast/src/main.rs @@ -155,19 +155,31 @@ fn main() -> Result<()> { let runtime = Runtime::new().expect("Failed to instantiate Runtime"); - if let Commands::Script(script) = &cli.command { - run_script_command(&cli, runtime, script, numbers_format, &output_format) - } else { - let mut config = load_global_config::(&None, &cli.profile)?; - update_cast_config(&mut config, &cli); - let provider = get_provider(&config.url)?; - runtime.block_on(run_async_command( - cli, - config, - provider, - numbers_format, - output_format, - )) + match &cli.command { + Commands::Script(script) => { + run_script_command(&cli, runtime, script, numbers_format, &output_format) + } + Commands::Verify(verify) => { + // run_verify_command(&cli, runtime, verify, numbers_format, &output_format) + runtime.block_on(run_verify_command( + &cli, + verify, + numbers_format, + &output_format, + )) + } + _ => { + let mut config = load_global_config::(&None, &cli.profile)?; + update_cast_config(&mut config, &cli); + let provider = get_provider(&config.url)?; + runtime.block_on(run_async_command( + cli, + config, + provider, + numbers_format, + output_format, + )) + } } } @@ -430,32 +442,7 @@ async fn run_async_command( print_command_result("tx-status", &mut result, numbers_format, &output_format)?; Ok(()) } - Commands::Verify(verify) => { - let manifest_path = assert_manifest_path_exists()?; - let package_metadata = get_package_metadata(&manifest_path, &verify.package)?; - let artifacts = build_and_load_artifacts( - &package_metadata, - &BuildConfig { - scarb_toml_path: manifest_path.clone(), - json: cli.json, - profile: cli.profile.unwrap_or("dev".to_string()), - }, - ) - .expect("Failed to build contract"); - let mut result = starknet_commands::verify::verify( - verify.contract_address, - verify.contract_name, - verify.verifier, - verify.network, - verify.confirm_verification, - &package_metadata.manifest_path, - &artifacts, - ) - .await; - - print_command_result("verify", &mut result, numbers_format, &output_format)?; - Ok(()) - } + Commands::Verify(_) => unreachable!(), Commands::Script(_) => unreachable!(), } } @@ -536,6 +523,39 @@ fn run_script_command( Ok(()) } +async fn run_verify_command( + cli: &Cli, + verify: &Verify, + numbers_format: NumbersFormat, + output_format: &OutputFormat, +) -> Result<()> { + let manifest_path = assert_manifest_path_exists()?; + let package_metadata = get_package_metadata(&manifest_path, &verify.package)?; + + let artifacts = build_and_load_artifacts( + &package_metadata, + &BuildConfig { + scarb_toml_path: manifest_path.clone(), + json: cli.json, + profile: cli.profile.clone().unwrap_or("dev".to_string()), + }, + ) + .expect("Failed to build contract"); + let mut result = starknet_commands::verify::verify( + verify.contract_address, + verify.contract_name.clone(), + verify.verifier.clone(), + verify.network.clone(), + verify.confirm_verification, + &package_metadata.manifest_path, + &artifacts, + ) + .await; + + print_command_result("verify", &mut result, numbers_format, &output_format)?; + Ok(()) +} + fn update_cast_config(config: &mut CastConfig, cli: &Cli) { macro_rules! clone_or_else { ($field:expr, $config_field:expr) => { diff --git a/crates/sncast/src/starknet_commands/verify.rs b/crates/sncast/src/starknet_commands/verify.rs index 41f57238fb..aee21906cc 100644 --- a/crates/sncast/src/starknet_commands/verify.rs +++ b/crates/sncast/src/starknet_commands/verify.rs @@ -14,6 +14,11 @@ use std::ffi::OsStr; use std::{env, fmt}; use walkdir::WalkDir; +struct VoyagerVerificationInterface { + network: Network, + workspace_dir: Utf8PathBuf, +} + struct WalnutVerificationInterface { network: Network, workspace_dir: Utf8PathBuf, @@ -30,6 +35,92 @@ trait VerificationInterface { fn gen_explorer_url(&self) -> Result; } +#[async_trait::async_trait] +impl VerificationInterface for VoyagerVerificationInterface { + fn new(network: Network, workspace_dir: Utf8PathBuf) -> Self { + VoyagerVerificationInterface { + network, + workspace_dir, + } + } + + async fn verify( + &self, + contract_address: FieldElement, + contract_name: String, + ) -> Result { + // Read all files name along with their contents in a JSON format + // in the workspace dir recursively + // key is the file name and value is the file content + let mut file_data = serde_json::Map::new(); + + // Recursively read files and their contents in workspace directory + for entry in WalkDir::new(self.workspace_dir.clone()).follow_links(true) { + let entry = entry?; + let path = entry.path(); + if path.is_file() { + if let Some(extension) = path.extension() { + if extension == OsStr::new("cairo") || extension == OsStr::new("toml") { + let relative_path = path.strip_prefix(self.workspace_dir.clone())?; + let file_content = std::fs::read_to_string(path)?; + file_data.insert( + relative_path.to_string_lossy().into_owned(), + serde_json::Value::String(file_content), + ); + } + } + } + } + + // Serialize the JSON object to a JSON string + let source_code = serde_json::Value::Object(file_data); + + // Create the JSON payload with "contract name," "address," and "source_code" fields + let payload = VerificationPayload { + contract_name: contract_name.to_string(), + contract_address: contract_address.to_string(), + source_code, + }; + + // Serialize the payload to a JSON string for the POST request + let json_payload = serde_json::to_string(&payload)?; + + // Send the POST request to the explorer + let client = reqwest::Client::new(); + let api_res = client + .post(self.gen_explorer_url()?) + .header("Content-Type", "application/json") + .body(json_payload) + .send() + .await + .context("Failed to send request to verifier API")?; + + match api_res.status() { + StatusCode::OK => { + let message = api_res + .text() + .await + .context("Failed to read verifier API response")?; + Ok(VerifyResponse { message }) + } + _ => { + let message = api_res.text().await.context("Failed to verify contract")?; + Err(anyhow!(message)) + } + } + } + + fn gen_explorer_url(&self) -> Result { + let api_base_url = env::var("VOYAGER_API_URL") + .unwrap_or_else(|_| "https://api.voyager.online/beta".to_string()); + let path = match self.network { + Network::Mainnet => "/v1/sn_main/verify", + Network::Sepolia => "/v1/sn_sepolia/verify", + }; + Ok(format!("{}{}", api_base_url, path)) + } +} + #[async_trait::async_trait] impl VerificationInterface for WalnutVerificationInterface { fn new(network: Network, workspace_dir: Utf8PathBuf) -> Self { @@ -44,11 +135,16 @@ impl VerificationInterface for WalnutVerificationInterface { contract_address: FieldElement, contract_name: String, ) -> Result { + + println!("Verifying contract {contract_name} at address {contract_address}"); + // Read all files name along with their contents in a JSON format // in the workspace dir recursively // key is the file name and value is the file content let mut file_data = serde_json::Map::new(); + println!("directory: {0}", self.workspace_dir); + // Recursively read files and their contents in workspace directory for entry in WalkDir::new(self.workspace_dir.clone()).follow_links(true) { let entry = entry?; @@ -144,12 +240,14 @@ pub struct Verify { #[derive(ValueEnum, Clone, Debug)] pub enum Verifier { Walnut, + Voyager } impl fmt::Display for Verifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Verifier::Walnut => write!(f, "walnut"), + Verifier::Voyager => write!(f, "voyager"), } } } @@ -196,5 +294,9 @@ pub async fn verify( let walnut = WalnutVerificationInterface::new(network, workspace_dir.to_path_buf()); walnut.verify(contract_address, contract_name).await } + Verifier::Voyager => { + let voyager = VoyagerVerificationInterface::new(network, workspace_dir.to_path_buf()); + voyager.verify(contract_address, contract_name).await + } } } diff --git a/crates/sncast/tests/data/contracts/virtual_workspace/a.log b/crates/sncast/tests/data/contracts/virtual_workspace/a.log new file mode 100644 index 0000000000..5bf52a1909 --- /dev/null +++ b/crates/sncast/tests/data/contracts/virtual_workspace/a.log @@ -0,0 +1,1109 @@ +PackageMetadata { + id: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + version: Version { + major: 0, + minor: 1, + patch: 0, + }, + edition: Some( + "2023_01", + ), + source: SourceId { + repr: "path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + }, + manifest_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + root: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition", + dependencies: [ + DependencyMetadata { + name: "core", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "starknet", + version_req: VersionReq { + comparators: [ + Comparator { + op: Caret, + major: 2, + minor: Some( + 4, + ), + patch: Some( + 0, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "test_plugin", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: Some( + Dev, + ), + extra: {}, + }, + ], + targets: [ + TargetMetadata { + kind: "lib", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "starknet-contract", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "test", + name: "cast_addition_unittest", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [], + extra: {}, +} +Metadata { + version: VersionPin, + app_exe: Some( + "/Users/rohit/.asdf/installs/scarb/2.6.5/bin/scarb", + ), + app_version_info: VersionInfo { + version: Version { + major: 2, + minor: 6, + patch: 5, + }, + commit_info: Some( + CommitInfo { + short_commit_hash: "d49f54394", + commit_hash: "d49f543948a7ae8a7d3108c8ff8f6b17dc15ef78", + commit_date: Some( + "2024-06-11", + ), + }, + ), + cairo: CairoVersionInfo { + version: Version { + major: 2, + minor: 6, + patch: 4, + }, + commit_info: None, + extra: {}, + }, + extra: {}, + }, + target_dir: Some( + "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/target", + ), + runtime_manifest: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + workspace: WorkspaceMetadata { + manifest_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/Scarb.toml", + root: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace", + members: [ + PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + ], + extra: {}, + }, + packages: [ + PackageMetadata { + id: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + version: Version { + major: 0, + minor: 1, + patch: 0, + }, + edition: Some( + "2023_01", + ), + source: SourceId { + repr: "path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + }, + manifest_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + root: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition", + dependencies: [ + DependencyMetadata { + name: "core", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "starknet", + version_req: VersionReq { + comparators: [ + Comparator { + op: Caret, + major: 2, + minor: Some( + 4, + ), + patch: Some( + 0, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "test_plugin", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: Some( + Dev, + ), + extra: {}, + }, + ], + targets: [ + TargetMetadata { + kind: "lib", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "starknet-contract", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "test", + name: "cast_addition_unittest", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [], + extra: {}, + }, + PackageMetadata { + id: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + name: "cast_fibonacci", + version: Version { + major: 0, + minor: 1, + patch: 0, + }, + edition: Some( + "2023_01", + ), + source: SourceId { + repr: "path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml", + }, + manifest_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml", + root: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci", + dependencies: [ + DependencyMetadata { + name: "cast_addition", + version_req: VersionReq { + comparators: [], + }, + source: SourceId { + repr: "path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "core", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "starknet", + version_req: VersionReq { + comparators: [ + Comparator { + op: Caret, + major: 2, + minor: Some( + 4, + ), + patch: Some( + 0, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + DependencyMetadata { + name: "test_plugin", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: Some( + Dev, + ), + extra: {}, + }, + ], + targets: [ + TargetMetadata { + kind: "lib", + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "starknet-contract", + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object { + "build-external-contracts": Array [ + String("cast_addition::AdditionContract"), + ], + }, + extra: {}, + }, + TargetMetadata { + kind: "test", + name: "cast_fibonacci_unittest", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [], + extra: {}, + }, + PackageMetadata { + id: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + version: Version { + major: 2, + minor: 6, + patch: 4, + }, + edition: Some( + "2023_11", + ), + source: SourceId { + repr: "std", + }, + manifest_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/Scarb.toml", + root: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core", + dependencies: [ + DependencyMetadata { + name: "test_plugin", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: Some( + Dev, + ), + extra: {}, + }, + ], + targets: [ + TargetMetadata { + kind: "lib", + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + params: Object {}, + extra: {}, + }, + TargetMetadata { + kind: "test", + name: "core_unittest", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [ + "coupons", + "negative_impls", + ], + extra: {}, + }, + PackageMetadata { + id: PackageId { + repr: "starknet 2.6.4 (std)", + }, + name: "starknet", + version: Version { + major: 2, + minor: 6, + patch: 4, + }, + edition: Some( + "2023_01", + ), + source: SourceId { + repr: "std", + }, + manifest_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/starknet/Scarb.toml", + root: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/starknet", + dependencies: [ + DependencyMetadata { + name: "core", + version_req: VersionReq { + comparators: [ + Comparator { + op: Exact, + major: 2, + minor: Some( + 6, + ), + patch: Some( + 4, + ), + pre: Prerelease(""), + }, + ], + }, + source: SourceId { + repr: "registry+https://there-is-no-default-registry-yet.com/", + }, + kind: None, + extra: {}, + }, + ], + targets: [ + TargetMetadata { + kind: "cairo-plugin", + name: "starknet", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/starknet/src/lib.cairo", + params: Object { + "builtin": Bool(true), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [], + extra: {}, + }, + PackageMetadata { + id: PackageId { + repr: "test_plugin 2.6.4 (std)", + }, + name: "test_plugin", + version: Version { + major: 2, + minor: 6, + patch: 4, + }, + edition: Some( + "2023_01", + ), + source: SourceId { + repr: "std", + }, + manifest_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/test_plugin/Scarb.toml", + root: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/test_plugin", + dependencies: [], + targets: [ + TargetMetadata { + kind: "cairo-plugin", + name: "test_plugin", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/test_plugin/src/lib.cairo", + params: Object { + "builtin": Bool(true), + }, + extra: {}, + }, + ], + manifest_metadata: ManifestMetadata { + authors: None, + description: None, + documentation: None, + homepage: None, + keywords: None, + license: None, + license_file: None, + readme: None, + repository: None, + urls: None, + tool: None, + }, + experimental_features: [], + extra: {}, + }, + ], + compilation_units: [ + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_addition-eek73dk05g7n0", + }, + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + target: TargetMetadata { + kind: "lib", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: None, + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "lib", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_addition-lku86m7pefpsg", + }, + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + target: TargetMetadata { + kind: "starknet-contract", + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object {}, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: None, + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "starknet-contract", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_addition-n236gfrbi6utc", + }, + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + target: TargetMetadata { + kind: "test", + name: "cast_addition_unittest", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: Some( + [ + KV( + "target", + "test", + ), + ], + ), + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "test_plugin 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "test", + ), + Name( + "test", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_fibonacci-pj89dd0fe5h6a", + }, + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + target: TargetMetadata { + kind: "lib", + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object {}, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: None, + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "lib", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_fibonacci-lk8hp8d874f2k", + }, + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + target: TargetMetadata { + kind: "starknet-contract", + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object { + "build-external-contracts": Array [ + String("cast_addition::AdditionContract"), + ], + }, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: None, + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "starknet-contract", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + CompilationUnitMetadata { + id: CompilationUnitId { + repr: "cast_fibonacci-9ijl61fc9b00e", + }, + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + target: TargetMetadata { + kind: "test", + name: "cast_fibonacci_unittest", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + params: Object { + "test-type": String("unit"), + }, + extra: {}, + }, + compiler_config: Object { + "allow_warnings": Bool(true), + "enable_gas": Bool(true), + "sierra_replace_ids": Bool(true), + }, + components: [ + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)", + }, + name: "cast_addition", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/src/lib.cairo", + cfg: Some( + [ + KV( + "target", + "test", + ), + ], + ), + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)", + }, + name: "cast_fibonacci", + source_path: "/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/src/lib.cairo", + cfg: None, + extra: {}, + }, + CompilationUnitComponentMetadata { + package: PackageId { + repr: "core 2.6.4 (std)", + }, + name: "core", + source_path: "/Users/rohit/Library/Caches/com.swmansion.scarb/registry/std/v2.6.4/core/src/lib.cairo", + cfg: Some( + [ + KV( + "target", + "test", + ), + ], + ), + extra: {}, + }, + ], + cairo_plugins: [ + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "starknet 2.6.4 (std)", + }, + extra: {}, + }, + CompilationUnitCairoPluginMetadata { + package: PackageId { + repr: "test_plugin 2.6.4 (std)", + }, + extra: {}, + }, + ], + cfg: [ + KV( + "target", + "test", + ), + Name( + "test", + ), + ], + extra: { + "components": Array [ + String("cast_addition 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml)"), + String("cast_fibonacci 0.1.0 (path+file:///Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_fibonacci/Scarb.toml)"), + String("core 2.6.4 (std)"), + ], + }, + }, + ], + current_profile: "dev", + profiles: [ + "dev", + "release", + ], + extra: {}, +} + Compiling lib(cast_addition) cast_addition v0.1.0 (/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml) + Compiling starknet-contract(cast_addition) cast_addition v0.1.0 (/Users/rohit/nmd/starknet-foundry/crates/sncast/tests/data/contracts/virtual_workspace/crates/cast_addition/Scarb.toml) + Finished release target(s) in 2 seconds +[?2004h You are about to submit the entire workspace's code to the third-party chosen verifier at walnut, and the code will be publicly available through walnut's APIs. Are you sure? (Y/n): [?2004l diff --git a/crates/sncast/tests/data/contracts/virtual_workspace/snfoundry.toml b/crates/sncast/tests/data/contracts/virtual_workspace/snfoundry.toml new file mode 100644 index 0000000000..d6a1abd653 --- /dev/null +++ b/crates/sncast/tests/data/contracts/virtual_workspace/snfoundry.toml @@ -0,0 +1,5 @@ + +[sncast.account1] +account = "account2" +accounts-file = "/Users/rohit/.starknet_accounts/starknet_open_zeppelin_accounts.json" +url = "https://free-rpc.nethermind.io/sepolia-juno" diff --git a/crates/sncast/tests/e2e/verify.rs b/crates/sncast/tests/e2e/verify.rs index c61c0bc563..5bab877103 100644 --- a/crates/sncast/tests/e2e/verify.rs +++ b/crates/sncast/tests/e2e/verify.rs @@ -5,7 +5,7 @@ use indoc::formatdoc; use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_contains}; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; - + #[tokio::test] async fn test_happy_case() { let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map"); @@ -24,8 +24,22 @@ async fn test_happy_case() { .mount(&mock_server) .await; - let mut args = default_cli_args(); - args.append(&mut vec![ + let mut args_voyager = default_cli_args(); + + args_voyager.append(&mut vec![ + "verify", + "--contract-address", + MAP_CONTRACT_ADDRESS_SEPOLIA, + "--contract-name", + "Map", + "--verifier", + "voyager", + "--network", + "sepolia", + ]); + + let mut args_walnut = default_cli_args(); + args_walnut.append(&mut vec![ "verify", "--contract-address", MAP_CONTRACT_ADDRESS_SEPOLIA, @@ -37,15 +51,32 @@ async fn test_happy_case() { "sepolia", ]); - let snapbox = runner(&args) - .env("WALNUT_API_URL", mock_server.uri()) + let snapbox_voyager = runner(&args_voyager) + .env("VOYAGER_API_URL", &mock_server.uri()) .current_dir(contract_path.path()) .stdin("Y"); - let output = snapbox.assert().success(); + let snapbox_walnut = runner(&args_walnut) + .env("WALNUT_API_URL", &mock_server.uri()) + .current_dir(contract_path.path()) + .stdin("Y"); + + let output_voyager = snapbox_voyager.assert().success(); + let output_walnut = snapbox_walnut.assert().success(); assert_stdout_contains( - output, + output_voyager, + formatdoc!( + r" + command: verify + message: {} + ", + verifier_response + ), + ); + + assert_stdout_contains( + output_walnut, formatdoc!( r" command: verify @@ -74,8 +105,21 @@ async fn test_failed_verification() { .mount(&mock_server) .await; - let mut args = default_cli_args(); - args.append(&mut vec![ + let mut args_voyager = default_cli_args(); + args_voyager.append(&mut vec![ + "verify", + "--contract-address", + MAP_CONTRACT_ADDRESS_SEPOLIA, + "--contract-name", + "nonexistent", + "--verifier", + "voyager", + "--network", + "sepolia", + ]); + + let mut args_walnut = default_cli_args(); + args_walnut.append(&mut vec![ "verify", "--contract-address", MAP_CONTRACT_ADDRESS_SEPOLIA, @@ -86,16 +130,34 @@ async fn test_failed_verification() { "--network", "sepolia", ]); + + let snapbox_voyager = runner(&args_voyager) + .env("VOYAGER_API_URL", &mock_server.uri()) + .current_dir(contract_path.path()) + .stdin("Y"); - let snapbox = runner(&args) - .env("WALNUT_API_URL", mock_server.uri()) + let snapbox_walnut = runner(&args_walnut) + .env("WALNUT_API_URL", &mock_server.uri()) .current_dir(contract_path.path()) .stdin("Y"); - let output = snapbox.assert().success(); + let output_voyager = snapbox_voyager.assert().success(); + + let output_walnut = snapbox_walnut.assert().success(); assert_stderr_contains( - output, + output_voyager, + formatdoc!( + r" + command: verify + error: {} + ", + verifier_response + ), + ); + + assert_stderr_contains( + output_walnut, formatdoc!( r" command: verify diff --git a/docs/src/appendix/sncast/verify.md b/docs/src/appendix/sncast/verify.md index 7dcb27c67d..a75808ecf1 100644 --- a/docs/src/appendix/sncast/verify.md +++ b/docs/src/appendix/sncast/verify.md @@ -15,6 +15,7 @@ The name of the contract. The contract name is the part after the `mod` keyword Optional. The verification provider to use for the verification. Possible values are: +* `voyager` * `walnut` ## `--network, -n `