diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90173b333e..eaad4d0bfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 @@ -101,7 +101,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 @@ -150,7 +150,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 @@ -164,7 +164,7 @@ jobs: RUSTFLAGS: "-Dwarnings" steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 @@ -176,7 +176,7 @@ jobs: env: MDBOOK_VERSION: 0.4.31 steps: - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 @@ -197,4 +197,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: typos-action - uses: crate-ci/typos@v1.22.3 + uses: crate-ci/typos@v1.22.9 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c7849e1a6a..7d3a97d769 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,7 +28,7 @@ jobs: env: MDBOOK_VERSION: 0.4.31 steps: - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c43239d6b..04b356bbce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,7 @@ jobs: - name: Get version from Cargo.toml id: lookupVersion - uses: mikefarah/yq@557dcb87b8efe786f89a12c09e9046b4753ab72e + uses: mikefarah/yq@f15500b20a1c991c8729870ba60a4dc3524b6a94 with: cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml' @@ -99,7 +99,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: stable target: ${{ matrix.target }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 4164ed5b56..2a063617a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added -- `verify` subcommand to verify contract. [Read more here](./docs/src/appendix/sncast/verify.md) +- `verify` subcommand to verify contract (walnut APIs supported as of this version). [Read more here](./docs/src/appendix/sncast/verify.md) + +## [0.26.0] - 2024-07-03 + +### Forge + +#### Changed +- Updated event testing - read more [here](./docs/src/testing/testing-events.md) on how it now works and [here](./docs/src/appendix/cheatcodes/spy_events.md) +about updated `spy_events` cheatcode ## [0.25.0] - 2024-06-12 @@ -20,8 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Changed - `SyscallResultStringErrorTrait::map_error_to_string` removed in favor of utility function (`snforge_std::byte_array::try_deserialize_bytearray_error`) -- Updated event testing - read more [here](./docs/src/testing/testing-events.md) on how it now works and [here](./docs/src/appendix/cheatcodes/spy_events.md) -about updated `spy_events` cheatcode + ### Cast diff --git a/Cargo.lock b/Cargo.lock index 5ca8de28c8..d11537baff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,7 +317,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -806,7 +806,7 @@ checksum = "cd65bf4d71ebc1efb0181b6c4d27c93e7e01fe5d521a15f2a5695cd7b5d79f36" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1121,7 +1121,7 @@ version = "1.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1249,9 +1249,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", "clap_derive", @@ -1259,9 +1259,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstream", "anstyle", @@ -1271,14 +1271,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1513,7 +1513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1570,7 +1570,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1592,7 +1592,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -1970,7 +1970,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "forge" -version = "0.25.0" +version = "0.26.0" dependencies = [ "anyhow", "ark-ff", @@ -2039,7 +2039,7 @@ dependencies = [ [[package]] name = "forge_runner" -version = "0.25.0" +version = "0.26.0" dependencies = [ "anyhow", "bimap", @@ -2185,7 +2185,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -2237,7 +2237,7 @@ checksum = "d4cf186fea4af17825116f72932fe52cce9a13bae39ff63b4dc0cfdb3fb4bde1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -2695,18 +2695,18 @@ dependencies = [ [[package]] name = "include_dir" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" dependencies = [ "include_dir_macros", ] [[package]] name = "include_dir_macros" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" dependencies = [ "proc-macro2", "quote", @@ -2916,11 +2916,11 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.5.2", + "spin", ] [[package]] @@ -3148,9 +3148,9 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits 0.2.19", @@ -3295,7 +3295,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -3495,7 +3495,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -3539,7 +3539,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -3681,9 +3681,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -3915,7 +3915,7 @@ dependencies = [ "cc", "getrandom", "libc", - "spin 0.9.8", + "spin", "untrusted", "windows-sys 0.48.0", ] @@ -4210,7 +4210,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4305,7 +4305,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4316,14 +4316,14 @@ checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "e8eddb61f0697cc3989c5d64b452f5488e2b8a60fd7d5076a3045076ffef8cb0" dependencies = [ "itoa", "ryu", @@ -4397,7 +4397,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4534,7 +4534,7 @@ dependencies = [ [[package]] name = "sncast" -version = "0.25.0" +version = "0.26.0" dependencies = [ "anyhow", "async-trait", @@ -4607,12 +4607,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -4766,7 +4760,7 @@ checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" dependencies = [ "starknet-curve 0.4.0", "starknet-ff 0.3.5", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4776,7 +4770,7 @@ source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869#d980869d44 dependencies = [ "starknet-curve 0.4.1", "starknet-ff 0.3.6", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4837,7 +4831,7 @@ version = "0.1.6" source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "starknet-core", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -4987,9 +4981,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.65" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -5061,7 +5055,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -5072,7 +5066,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", "test-case-core", ] @@ -5125,7 +5119,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -5228,7 +5222,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -5462,9 +5456,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -5551,7 +5545,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -5585,7 +5579,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5902,7 +5896,7 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] [[package]] @@ -5922,5 +5916,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.68", ] diff --git a/Cargo.toml b/Cargo.toml index 523bb1bc43..8bbea9248b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ ] [workspace.package] -version = "0.25.0" +version = "0.26.0" edition = "2021" repository = "https://github.com/foundry-rs/starknet-foundry" license = "MIT" @@ -51,9 +51,9 @@ cairo-felt = "0.9.1" anyhow = "1.0.86" assert_fs = "1.1.1" camino = { version = "1.1.7", features = ["serde1"] } -clap = { version = "4.5.7", features = ["derive"] } +clap = { version = "4.5.8", features = ["derive"] } console = "0.15.8" -include_dir = "0.7.3" +include_dir = "0.7.4" indoc = "2" itertools = "0.12.1" num-traits = "0.2.19" @@ -61,18 +61,18 @@ once_cell = "1.18.0" rayon = "1.10" regex = "1.10.5" serde = { version = "1.0.203", features = ["derive"] } -serde_json = "1.0.117" +serde_json = "1.0.119" starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "d980869" } starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "d980869" } trace-data = { git = "https://github.com/software-mansion/cairo-profiler/", rev = "e031b09" } tempfile = "3.10.1" thiserror = "1.0.61" ctor = "0.2.8" -url = "2.5.0" +url = "2.5.2" tokio = { version = "1.38.0", features = ["full"] } tokio-util = "0.7.11" futures = "0.3.30" -num-bigint = { version = "0.4.5", features = ["rand"] } +num-bigint = { version = "0.4.6", features = ["rand"] } walkdir = "2.5.0" rand = "0.8.5" project-root = "0.2.2" @@ -104,7 +104,7 @@ ark-secp256r1 = "0.4.0" openssl = { version = "0.10", features = ["vendored"] } toml_edit = "0.22.12" axum = "0.7.5" -lazy_static = "1.4.0" +lazy_static = "1.5.0" fs2 = "0.4.3" flate2 = "1.0.30" k256 = { version = "0.13.2", features = ["sha256", "ecdsa", "serde"] } diff --git a/crates/conversions/cairo-serde-macros/Cargo.toml b/crates/conversions/cairo-serde-macros/Cargo.toml index 8126bdfab3..106375e983 100644 --- a/crates/conversions/cairo-serde-macros/Cargo.toml +++ b/crates/conversions/cairo-serde-macros/Cargo.toml @@ -7,6 +7,6 @@ edition.workspace = true proc-macro = true [dependencies] -syn = "2.0.65" +syn = "2.0.68" quote = "1.0.36" -proc-macro2 = "1.0.85" +proc-macro2 = "1.0.86" diff --git a/crates/forge/tests/e2e/running.rs b/crates/forge/tests/e2e/running.rs index c6d72e1ec6..5851f0bbf3 100644 --- a/crates/forge/tests/e2e/running.rs +++ b/crates/forge/tests/e2e/running.rs @@ -6,7 +6,7 @@ use camino::Utf8PathBuf; use forge::CAIRO_EDITION; use indoc::{formatdoc, indoc}; use shared::test_utils::output_assert::assert_stdout_contains; -use std::{fs, path::Path, str::FromStr}; +use std::{env, fs, path::Path, str::FromStr}; use test_utils::tempdir_with_tool_versions; use toml_edit::{value, DocumentMut, Item}; @@ -680,6 +680,8 @@ fn with_exit_first_flag() { ); } +// TODO (2274): This test has inherently flawed logic, needs to be re-written +#[ignore] #[test] fn init_new_project_test() { let temp = tempdir_with_tool_versions().unwrap(); diff --git a/crates/sncast/src/main.rs b/crates/sncast/src/main.rs index 0561cdd540..8654e7b51f 100644 --- a/crates/sncast/src/main.rs +++ b/crates/sncast/src/main.rs @@ -432,17 +432,29 @@ async fn run_async_command( } Commands::Verify(verify) => { let manifest_path = assert_manifest_path_exists()?; + let package_metadata = get_package_metadata(&manifest_path, &None)?; + 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.yes, &manifest_path, + &artifacts, ) .await; print_command_result("verify", &mut result, numbers_format, &output_format)?; - return Ok(()); + Ok(()) } Commands::Script(_) => unreachable!(), } diff --git a/crates/sncast/src/starknet_commands/mod.rs b/crates/sncast/src/starknet_commands/mod.rs index cdbb79d247..4a96b853bc 100644 --- a/crates/sncast/src/starknet_commands/mod.rs +++ b/crates/sncast/src/starknet_commands/mod.rs @@ -6,5 +6,5 @@ pub mod invoke; pub mod multicall; pub mod script; pub mod show_config; -pub mod verify; pub mod tx_status; +pub mod verify; diff --git a/crates/sncast/src/starknet_commands/verify.rs b/crates/sncast/src/starknet_commands/verify.rs index 1937e5bc3e..7465d62af3 100644 --- a/crates/sncast/src/starknet_commands/verify.rs +++ b/crates/sncast/src/starknet_commands/verify.rs @@ -1,11 +1,14 @@ -use anyhow::Ok; use anyhow::{anyhow, Context, Result}; +use anyhow::{bail, Ok}; use camino::Utf8PathBuf; use clap::Args; +use promptly::prompt; use reqwest::StatusCode; +use scarb_api::StarknetContractArtifacts; use serde::Serialize; use sncast::response::structs::VerifyResponse; use starknet::core::types::FieldElement; +use std::collections::HashMap; use std::env; use std::ffi::OsStr; use walkdir::WalkDir; @@ -178,18 +181,15 @@ impl VerificationInterface for WalnutVerificationInterface { .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)) - } + if api_res.status() == StatusCode::OK { + let message = api_res + .text() + .await + .context("Failed to read verifier API response")?; + Ok(VerifyResponse { message }) + } else { + let message = api_res.text().await.context("Failed to verify contract")?; + Err(anyhow!(message)) } } @@ -201,7 +201,7 @@ impl VerificationInterface for WalnutVerificationInterface { "sepolia" => "/v1/sn_sepolia/verify", _ => return Err(anyhow!("Unknown network")), }; - Ok(format!("{}{}", api_base_url, path)) + Ok(format!("{api_base_url}{path}")) } } @@ -217,12 +217,16 @@ pub struct Verify { pub contract_name: String, /// Block explorer to use for the verification - #[clap(short = 'v', long = "verifier", value_parser = ["voyager", "walnut"])] + #[clap(short = 'v', long = "verifier", value_parser = [ "voyager" , "walnut"], default_value = "walnut")] pub verifier: String, /// The network on which block explorer will do the verification #[clap(short = 'n', long = "network", value_parser = ["mainnet", "sepolia"])] pub network: String, + + /// Assume "yes" as answer to confirmation prompt and run non-interactively + #[clap(long, default_value = "false")] + pub yes: bool, } #[derive(Serialize, Debug)] @@ -237,8 +241,25 @@ pub async fn verify( contract_name: String, verifier: String, network: String, + yes: bool, manifest_path: &Utf8PathBuf, + artifacts: &HashMap, ) -> Result { + // Let's ask confirmation + if !yes { + let prompt_text = + format!("You are about to submit the entire workspace's code to the third-party chosen verifier at {verifier}, and the code will be publicly available through {verifier}'s APIs. Are you sure? (Y/n)"); + let input: String = prompt(prompt_text)?; + + if !input.starts_with('Y') { + bail!("Verification aborted"); + } + } + + if !artifacts.contains_key(&contract_name) { + return Err(anyhow!("Contract named '{contract_name}' was not found")); + } + // Build JSON Payload for the verification request // get the parent dir of the manifest path let workspace_dir = manifest_path diff --git a/crates/sncast/tests/e2e/script/general.rs b/crates/sncast/tests/e2e/script/general.rs index d525fc2e26..198186ee15 100644 --- a/crates/sncast/tests/e2e/script/general.rs +++ b/crates/sncast/tests/e2e/script/general.rs @@ -133,7 +133,7 @@ async fn test_incompatible_sncast_std_version() { snapbox.assert().success().stdout_matches(indoc! {r" ... - [WARNING] Package sncast_std version does not meet the recommended version requirement =0.25.0, it might result in unexpected behaviour + [WARNING] Package sncast_std version does not meet the recommended version requirement =0.26.0, it might result in unexpected behaviour ... "}); } diff --git a/crates/sncast/tests/e2e/verify.rs b/crates/sncast/tests/e2e/verify.rs index 0a3801401c..2494d3e757 100644 --- a/crates/sncast/tests/e2e/verify.rs +++ b/crates/sncast/tests/e2e/verify.rs @@ -53,11 +53,13 @@ async fn test_happy_case() { let snapbox_voyager = runner(&args_voyager) .env("VOYAGER_API_URL", &mock_server.uri()) - .current_dir(contract_path.path()); + .current_dir(contract_path.path()) + .stdin("Y"); let snapbox_walnut = runner(&args_walnut) .env("WALNUT_API_URL", &mock_server.uri()) - .current_dir(contract_path.path()); + .current_dir(contract_path.path()) + .stdin("Y"); let output_voyager = snapbox_voyager.assert().success(); let output_walnut = snapbox_walnut.assert().success(); @@ -91,7 +93,7 @@ async fn test_failed_verification() { let mock_server = MockServer::start().await; - let verifier_response = "An error occurred during verification: wrong contract class name"; + let verifier_response = "An error occurred during verification: contract class isn't declared"; Mock::given(method("POST")) .and(path("/v1/sn_sepolia/verify")) @@ -122,7 +124,7 @@ async fn test_failed_verification() { "--contract-address", MAP_CONTRACT_ADDRESS_SEPOLIA, "--contract-name", - "nonexistent", + "Map", "--verifier", "walnut", "--network", @@ -131,11 +133,13 @@ async fn test_failed_verification() { let snapbox_voyager = runner(&args_voyager) .env("VOYAGER_API_URL", &mock_server.uri()) - .current_dir(contract_path.path()); + .current_dir(contract_path.path()) + .stdin("Y"); let snapbox_walnut = runner(&args_walnut) .env("WALNUT_API_URL", &mock_server.uri()) - .current_dir(contract_path.path()); + .current_dir(contract_path.path()) + .stdin("Y"); let output_voyager = snapbox_voyager.assert().success(); @@ -163,3 +167,67 @@ async fn test_failed_verification() { ), ); } + +#[tokio::test] +async fn test_verification_abort() { + let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map"); + + let mut args = default_cli_args(); + args.append(&mut vec![ + "verify", + "--contract-address", + MAP_CONTRACT_ADDRESS_SEPOLIA, + "--contract-name", + "nonexistent", + "--verifier", + "walnut", + "--network", + "sepolia", + ]); + + let snapbox = runner(&args).current_dir(contract_path.path()).stdin("n"); + + let output = snapbox.assert().success(); + + assert_stderr_contains( + output, + formatdoc!( + r" + command: verify + error: Verification aborted + " + ), + ); +} + +#[tokio::test] +async fn test_wrong_contract_name_passed() { + let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map"); + + let mut args = default_cli_args(); + args.append(&mut vec![ + "verify", + "--contract-address", + MAP_CONTRACT_ADDRESS_SEPOLIA, + "--contract-name", + "nonexistent", + "--verifier", + "walnut", + "--network", + "sepolia", + ]); + + let snapbox = runner(&args).current_dir(contract_path.path()).stdin("Y"); + + let output = snapbox.assert().success(); + + assert_stderr_contains( + output, + formatdoc!( + r" + command: verify + error: Contract named 'nonexistent' was not found + " + ), + ); +} diff --git a/sncast_std/Scarb.lock b/sncast_std/Scarb.lock index a02eb6cdcc..19a01d303a 100644 --- a/sncast_std/Scarb.lock +++ b/sncast_std/Scarb.lock @@ -3,4 +3,4 @@ version = 1 [[package]] name = "sncast_std" -version = "0.25.0" +version = "0.26.0" diff --git a/sncast_std/Scarb.toml b/sncast_std/Scarb.toml index 956a94240d..09d2586a66 100644 --- a/sncast_std/Scarb.toml +++ b/sncast_std/Scarb.toml @@ -1,4 +1,4 @@ [package] name = "sncast_std" -version = "0.25.0" +version = "0.26.0" edition = "2023_11" diff --git a/snforge_std/Scarb.lock b/snforge_std/Scarb.lock index 5c160fe06b..2cdde97d97 100644 --- a/snforge_std/Scarb.lock +++ b/snforge_std/Scarb.lock @@ -3,4 +3,4 @@ version = 1 [[package]] name = "snforge_std" -version = "0.25.0" +version = "0.26.0" diff --git a/snforge_std/Scarb.toml b/snforge_std/Scarb.toml index 327ca40158..2652b873d3 100644 --- a/snforge_std/Scarb.toml +++ b/snforge_std/Scarb.toml @@ -1,4 +1,4 @@ [package] name = "snforge_std" -version = "0.25.0" +version = "0.26.0" edition = "2023_10"