From 0f7f4c93bba747ef999c680a81529abc6be1516b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C5=9Bkowicz?= Date: Wed, 10 Apr 2024 18:37:52 +0200 Subject: [PATCH 1/2] Add functions to retrieve `SEPOLIA_RPC_URL` commit-id:918e569e Fix cargo lint errors Change implementation of rpc_url() rpc_url() -> node_url() (to rebase) Apply review suggestions (to rebase) Envs from dotenv (to rebase) Add .env.template file, rename functions once again (to rebase) --- .env.template | 1 + .gitignore | 1 + Cargo.lock | 1 + crates/shared/Cargo.toml | 1 + crates/shared/src/consts.rs | 1 + crates/shared/src/test_utils/mod.rs | 1 + crates/shared/src/test_utils/node_url.rs | 29 ++++++++++++++++++++++++ 7 files changed, 35 insertions(+) create mode 100644 .env.template create mode 100644 crates/shared/src/test_utils/node_url.rs diff --git a/.env.template b/.env.template new file mode 100644 index 0000000000..1fdad8934b --- /dev/null +++ b/.env.template @@ -0,0 +1 @@ +SEPOLIA_RPC_URL=https://example.com/rpc/v0_7 diff --git a/.gitignore b/.gitignore index 05a1ece11b..500480a4b0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Scarb.lock .spr.yml .snfoundry_cache/ .snfoundry_trace/ +.env diff --git a/Cargo.lock b/Cargo.lock index 6f419d0ed1..7682457575 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4376,6 +4376,7 @@ dependencies = [ "cairo-felt", "cairo-lang-runner", "console", + "dotenv", "regex", "semver", "snapbox", diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index dd3b91ea4f..a7838773c7 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -8,6 +8,7 @@ anyhow.workspace = true cairo-felt.workspace = true cairo-lang-runner.workspace = true console.workspace = true +dotenv.workspace = true semver.workspace = true starknet.workspace = true url.workspace = true diff --git a/crates/shared/src/consts.rs b/crates/shared/src/consts.rs index d53ef5d1b1..612cefae44 100644 --- a/crates/shared/src/consts.rs +++ b/crates/shared/src/consts.rs @@ -1 +1,2 @@ pub const EXPECTED_RPC_VERSION: &str = "0.7.0"; +pub const RPC_URL_VERSION: &str = "v0_7"; diff --git a/crates/shared/src/test_utils/mod.rs b/crates/shared/src/test_utils/mod.rs index 825fb93c7e..ec44362ab1 100644 --- a/crates/shared/src/test_utils/mod.rs +++ b/crates/shared/src/test_utils/mod.rs @@ -1 +1,2 @@ +pub mod node_url; pub mod output_assert; diff --git a/crates/shared/src/test_utils/node_url.rs b/crates/shared/src/test_utils/node_url.rs new file mode 100644 index 0000000000..d8ef4098e6 --- /dev/null +++ b/crates/shared/src/test_utils/node_url.rs @@ -0,0 +1,29 @@ +use anyhow::{Context, Result}; +use std::env; +use url::Url; + +/// Loads node RPC URL from `SEPOLIA_RPC_URL` environmental variable set in dotenv. +/// +/// #### Note: +/// - `node_rpc_url()` -> +/// - `node_url()` -> +pub fn node_rpc_url() -> Result { + dotenv::dotenv().ok(); + let node_rpc_url = env::var("SEPOLIA_RPC_URL") + .context("The required environmental variable `SEPOLIA_RPC_URL` is not set. Please set it manually or in .env file" + )?; + + Url::parse(&node_rpc_url).with_context(|| { + format!("Failed to parse the URL from the `SEPOLIA_RPC_URL` environmental variable: {node_rpc_url}") + }) +} + +/// Loads node URL from `SEPOLIA_RPC_URL` environmental variable and parses it, +/// returning URL with no slug (`rpc/v0_7` suffix). +pub fn node_url() -> Result { + let mut node_url = node_rpc_url()?; + node_url.set_path(""); + node_url.set_query(None); + + Ok(node_url) +} From c7a419f50c3c889874e90a7e5512b7953b6ab7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C5=9Bkowicz?= Date: Thu, 11 Apr 2024 12:09:10 +0200 Subject: [PATCH 2/2] Update CI and tests with `SEPOLIA_RPC_URL` getter function commit-id:99e99636 Apply review suggestions to tests (to rebase) Update release workflow Replacing placeholders in a different test function (to rebase) Remove env var from forks (to rebase) Update tests once again fix invalid ci Tests, CI updates --- .github/workflows/ci.yml | 16 ++-- .github/workflows/release.yml | 4 +- Cargo.lock | 2 + crates/cheatnet/Cargo.toml | 1 + crates/cheatnet/tests/common/state.rs | 3 +- crates/cheatnet/tests/starknet/forking.rs | 2 +- crates/forge/Cargo.toml | 1 + .../tests/test_fork.cairo | 33 ++++--- crates/forge/tests/data/forking/src/lib.cairo | 10 +-- crates/forge/tests/e2e/common/runner.rs | 24 +++++ .../tests/e2e/diagnostics_and_plugins.rs | 87 ++++++++++--------- crates/forge/tests/e2e/fork_warning.rs | 80 ++++++++++------- crates/forge/tests/e2e/forking.rs | 12 +-- crates/forge/tests/integration/cheat_fork.rs | 13 ++- crates/forge/tests/integration/setup_fork.rs | 47 +++++----- crates/forge/tests/integration/spy_events.rs | 60 ++++++------- crates/forge/tests/integration/store_load.rs | 4 +- scripts/smoke_test.sh | 2 +- 18 files changed, 224 insertions(+), 177 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1ed99e55f..52f20b21d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,9 @@ on: - master workflow_dispatch: +env: + SEPOLIA_RPC_URL: ${{ secrets.NODE_URL }}:7070/rpc/v0_7 + jobs: test-forge-unit-and-integration: name: Test Forge / Unit and Integration Tests @@ -20,7 +23,8 @@ jobs: - uses: software-mansion/setup-universal-sierra-compiler@v1 - run: cargo test --release --lib -p forge - run: cargo test --release --bin snforge - - run: cargo test --release integration -p forge + - name: Run Forge unit and integration tests + run: cargo test --release integration -p forge test-forge-e2e: name: Test Forge / E2E Tests @@ -57,7 +61,8 @@ jobs: - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 - uses: software-mansion/setup-scarb@v1.3.2 - uses: software-mansion/setup-universal-sierra-compiler@v1 - - run: cargo test --release e2e -p forge + - name: Run Forge E2E tests + run: cargo test --release e2e -p forge test-forge-runner: name: Test Forge Runner @@ -93,11 +98,8 @@ jobs: run: ./scripts/install_devnet.sh - uses: software-mansion/setup-scarb@v1.3.2 - uses: software-mansion/setup-universal-sierra-compiler@v1 - - name: Run tests - env: - NODE_URL: ${{ secrets.NODE_URL }} - run: | - SEPOLIA_RPC_URL="${NODE_URL}:7070/rpc/v0_7" cargo test --release -p sncast + - name: Run Cast tests + run: cargo test --release -p sncast test-conversions: name: Test Conversions diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3235cfe0b3..29bbd02ba7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -195,7 +195,7 @@ jobs: - name: Smoke test shell: bash env: - RPC_URL: ${{ secrets.CHEATNET_RPC_URL }} + NODE_URL: ${{ secrets.NODE_URL }} run: | BINARY_PATH="${{ env.BINARY_PATH }}" BINARY_PATH="${BINARY_PATH%.tar.gz}" @@ -213,7 +213,7 @@ jobs: REPO_URL=${{ github.repositoryUrl }} REVISION=${{ github.sha }} - ./scripts/smoke_test.sh "$RPC_URL" "$SNFORGE_PATH" "$SNCAST_PATH" "$REPO_URL" "$REVISION" + ./scripts/smoke_test.sh "${NODE_URL}:7070/rpc/v0_7" "$SNFORGE_PATH" "$SNCAST_PATH" "$REPO_URL" "$REVISION" create-release: name: Create release diff --git a/Cargo.lock b/Cargo.lock index 7682457575..3a170f7226 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1187,6 +1187,7 @@ dependencies = [ "scarb-metadata", "serde", "serde_json", + "shared", "starknet", "starknet_api", "tempfile", @@ -1994,6 +1995,7 @@ dependencies = [ "trace-data", "universal-sierra-compiler-api", "url", + "walkdir", ] [[package]] diff --git a/crates/cheatnet/Cargo.toml b/crates/cheatnet/Cargo.toml index 1eb1ffe3dc..3c34d3d1c7 100644 --- a/crates/cheatnet/Cargo.toml +++ b/crates/cheatnet/Cargo.toml @@ -47,5 +47,6 @@ ctor.workspace = true indoc.workspace = true rayon.workspace = true glob.workspace = true +shared.workspace = true test-case.workspace = true tempfile.workspace = true diff --git a/crates/cheatnet/tests/common/state.rs b/crates/cheatnet/tests/common/state.rs index db52398909..8509f9f4bd 100644 --- a/crates/cheatnet/tests/common/state.rs +++ b/crates/cheatnet/tests/common/state.rs @@ -4,6 +4,7 @@ use blockifier::state::cached_state::{ use cheatnet::constants::build_testing_state; use cheatnet::forking::state::ForkStateReader; use cheatnet::state::ExtendedStateReader; +use shared::test_utils::node_url::node_rpc_url; use starknet_api::block::BlockNumber; pub fn create_cached_state() -> CachedState { @@ -24,7 +25,7 @@ pub fn create_fork_cached_state_at( block_number: u64, cache_dir: &str, ) -> CachedState { - let node_url = "http://188.34.188.184:7070/rpc/v0_7".parse().unwrap(); + let node_url = node_rpc_url().unwrap(); CachedState::new( ExtendedStateReader { dict_state_reader: build_testing_state(), diff --git a/crates/cheatnet/tests/starknet/forking.rs b/crates/cheatnet/tests/starknet/forking.rs index 5fef0fd764..6536ec5906 100644 --- a/crates/cheatnet/tests/starknet/forking.rs +++ b/crates/cheatnet/tests/starknet/forking.rs @@ -645,7 +645,7 @@ fn test_cached_block_info_merging() { #[test] fn test_calling_nonexistent_url() { let temp_dir = TempDir::new().unwrap(); - let nonexistent_url = "http://188.34.188.184:9546".parse().unwrap(); + let nonexistent_url = "http://nonexistent-node-address.com".parse().unwrap(); let mut cached_fork_state = CachedState::new( ExtendedStateReader { dict_state_reader: build_testing_state(), diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 1ed0c9fd9a..7285f93873 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -74,3 +74,4 @@ axum.workspace = true lazy_static.workspace = true indoc.workspace = true tempfile.workspace = true +walkdir.workspace = true diff --git a/crates/forge/tests/data/diagnostics_and_plugins/tests/test_fork.cairo b/crates/forge/tests/data/diagnostics_and_plugins/tests/test_fork.cairo index dc48d7274d..8b762ea9a2 100644 --- a/crates/forge/tests/data/diagnostics_and_plugins/tests/test_fork.cairo +++ b/crates/forge/tests/data/diagnostics_and_plugins/tests/test_fork.cairo @@ -5,94 +5,91 @@ fn incorrect_fork_attributes() { } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(Latest))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Number(Latest))] fn incorrect_fork_attributes2() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(19446744073709551615))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Number(19446744073709551615))] fn incorrect_fork_attributes3() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Hash(Random))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Hash(Random))] fn incorrect_fork_attributes4() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Hash(Latest))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Hash(Latest))] fn incorrect_fork_attributes5() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(12345))] fn incorrect_fork_attributes6() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(0x12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(0x12345))] fn incorrect_fork_attributes7() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(Random))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(Random))] fn incorrect_fork_attributes8() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(Random))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Number(Random))] fn incorrect_fork_attributes9() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Number(12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: Number(12345))] fn incorrect_fork_attributes10() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Hash(0x12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: Hash(0x12345))] fn incorrect_fork_attributes11() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Tag(Latest))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: Tag(Latest))] fn incorrect_fork_attributes12() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockWhat::Number(12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockWhat::Number(12345))] fn incorrect_fork_attributes13() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Something::BlockId::Number(12345))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: Something::BlockId::Number(12345))] fn incorrect_fork_attributes14() { assert(1 == 1, 'ok') } #[test] -#[fork( - url: "http://188.34.188.184:7070/rpc/v0_7", - block_id: BlockId::Tag(xddd::d00pa::hehe::BlockTag::Latest) -)] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(xddd::d00pa::hehe::BlockTag::Latest))] fn incorrect_fork_attributes15() { assert(1 == 1, 'ok') } #[test] -#[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(sumting::Latest))] +#[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(sumting::Latest))] fn incorrect_fork_attributes16() { assert(1 == 1, 'ok') } diff --git a/crates/forge/tests/data/forking/src/lib.cairo b/crates/forge/tests/data/forking/src/lib.cairo index c82386142c..43a27ef896 100644 --- a/crates/forge/tests/data/forking/src/lib.cairo +++ b/crates/forge/tests/data/forking/src/lib.cairo @@ -11,7 +11,7 @@ mod tests { } #[test] - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(54060))] + #[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Number(54060))] fn test_fork_simple() { let dispatcher = IHelloStarknetDispatcher { contract_address: contract_address_const::< @@ -29,7 +29,7 @@ mod tests { } #[test] - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(0xd32c))] + #[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Number(0xd32c))] fn test_fork_simple_number_hex() { let dispatcher = IHelloStarknetDispatcher { contract_address: contract_address_const::< @@ -48,7 +48,7 @@ mod tests { #[test] #[fork( - url: "http://188.34.188.184:7070/rpc/v0_7", + url: "{{ NODE_RPC_URL }}", block_id: BlockId::Hash(0x06ae121e46f5375f93b00475fb130348ae38148e121f84b0865e17542e9485de) )] fn test_fork_simple_hash_hex() { @@ -69,7 +69,7 @@ mod tests { #[test] #[fork( - url: "http://188.34.188.184:7070/rpc/v0_7", + url: "{{ NODE_RPC_URL }}", block_id: BlockId::Hash( 3021433528476416000728121069095289682281028310523383289416465162415092565470 ) @@ -91,7 +91,7 @@ mod tests { } #[test] - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(Latest))] + #[fork(url: "{{ NODE_RPC_URL }}", block_id: BlockId::Tag(Latest))] fn print_block_number_when_latest() { assert(1 == 1, ''); } diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 0c7d3fce5c..68b4ce675d 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -3,12 +3,15 @@ use assert_fs::TempDir; use camino::Utf8PathBuf; use indoc::formatdoc; use shared::command::CommandExt; +use shared::test_utils::node_url::node_rpc_url; use snapbox::cmd::{cargo_bin, Command as SnapboxCommand}; +use std::path::Path; use std::process::Command; use std::str::FromStr; use std::{env, fs}; use test_utils::tempdir_with_tool_versions; use toml_edit::{value, DocumentMut}; +use walkdir::WalkDir; pub(crate) fn runner(temp_dir: &TempDir) -> SnapboxCommand { SnapboxCommand::new(cargo_bin!("snforge")) @@ -49,6 +52,9 @@ pub(crate) fn setup_package_with_file_patterns( manifest_path.write_str(&scarb_toml.to_string()).unwrap(); + // TODO (#2074): do that on .cairo.template files only + replace_node_rpc_url_placeholders(temp.path()); + temp } @@ -56,6 +62,24 @@ pub(crate) fn setup_package(package_name: &str) -> TempDir { setup_package_with_file_patterns(package_name, BASE_FILE_PATTERNS) } +fn replace_node_rpc_url_placeholders(dir_path: &Path) { + let url = node_rpc_url().unwrap(); + let temp_dir_files = WalkDir::new(dir_path); + for entry in temp_dir_files { + let entry = entry.unwrap(); + + let path = entry.path(); + + if path.is_file() { + let content = fs::read_to_string(path).unwrap(); + + let modified_content = content.replace("{{ NODE_RPC_URL }}", url.as_str()); + + fs::write(path, modified_content).unwrap(); + } + } +} + pub(crate) fn setup_hello_workspace() -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); temp.copy_from("tests/data/hello_workspaces", &["**/*.cairo", "**/*.toml"]) diff --git a/crates/forge/tests/e2e/diagnostics_and_plugins.rs b/crates/forge/tests/e2e/diagnostics_and_plugins.rs index 81bad29657..702cadebd4 100644 --- a/crates/forge/tests/e2e/diagnostics_and_plugins.rs +++ b/crates/forge/tests/e2e/diagnostics_and_plugins.rs @@ -1,127 +1,128 @@ -use super::common::runner::{setup_package, test_runner}; +use super::common::runner::{setup_package_with_file_patterns, test_runner, BASE_FILE_PATTERNS}; use indoc::formatdoc; +use shared::test_utils::node_url::node_rpc_url; use shared::test_utils::output_assert::assert_stderr_contains; #[test] fn print_error_if_attributes_incorrect() { - let mock_tests_dir = setup_package("diagnostics_and_plugins"); - let mock_tests_dir_path = mock_tests_dir.path().canonicalize().unwrap(); - let mock_tests_dir_path_str = mock_tests_dir_path.to_str().unwrap(); - + let node_rpc_url = node_rpc_url().unwrap(); + let mock_tests_dir = + setup_package_with_file_patterns("diagnostics_and_plugins", BASE_FILE_PATTERNS); let output = test_runner(&mock_tests_dir).assert().code(2); + assert_stderr_contains( output, formatdoc! {r#" error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/src/lib.cairo:4:11 + --> [..]/src/lib.cairo[..] #[fork(url: "https://lib.com")] ^**********************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/src/lib.cairo:4:11 + --> [..]/src/lib.cairo[..] #[fork(url: "https://lib.com")] ^**********************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:2:7 + --> [..]/tests/test_fork.cairo[..] #[fork(url: "https://test.com")] ^***********************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:8:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(Latest))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(Latest))] ^*****************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:14:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(19446744073709551615))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(19446744073709551615))] ^*******************************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:20:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Hash(Random))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Hash(Random))] ^***************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:26:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Hash(Latest))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Hash(Latest))] ^***************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:32:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(12345))] ^*************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:38:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(0x12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(0x12345))] ^***************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:44:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(Random))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(Random))] ^**************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:50:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Number(Random))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(Random))] ^*****************************************************************************^ error: Plugin diagnostic: Expected fuzzer config must be of the form `runs: , seed: ` - --> {mock_tests_dir_path_str}/tests/test_fuzzer.cairo:2:9 + --> [..]/tests/test_fuzzer.cairo[..] #[fuzzer(test: 10)] ^********^ error: Plugin diagnostic: Expected fuzzer config must be of the form `runs: , seed: ` - --> {mock_tests_dir_path_str}/tests/test_fuzzer.cairo:8:9 + --> [..]/tests/test_fuzzer.cairo[..] #[fuzzer()] ^^ error: Plugin diagnostic: Expected panic must be of the form `expected: ` or `expected: "some string"` or `expected: `. - --> {mock_tests_dir_path_str}/tests/test_should_panic.cairo:2:15 + --> [..]/tests/test_should_panic.cairo[..] #[should_panic(url: "https://test.com")] ^***********************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:56:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Number(12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: Number(12345))] ^*******************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:62:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Hash(0x12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: Hash(0x12345))] ^*******************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:68:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Tag(Latest))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: Tag(Latest))] ^*****************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:74:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockWhat::Number(12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockWhat::Number(12345))] ^******************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:80:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: Something::BlockId::Number(12345))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: Something::BlockId::Number(12345))] ^***************************************************************************************^ error: Plugin diagnostic: Expected panic must be of the form `expected: ` or `expected: "some string"` or `expected: `. - --> {mock_tests_dir_path_str}/tests/test_should_panic.cairo:2:15 + --> [..]/tests/test_should_panic.cairo[..] #[should_panic(url: "https://test.com")] ^***********************^ Error: Failed to compile test artifact, for detailed information go through the logs above error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:86:7 - #[fork( - ^ + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(xddd::d00pa::hehe::BlockTag::Latest))] + ^*******************************************************************************************************^ error: Plugin diagnostic: Expected fork config must be of the form `url: , block_id: `. - --> {mock_tests_dir_path_str}/tests/test_fork.cairo:95:7 - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(sumting::Latest))] + --> [..]/tests/test_fork.cairo[..] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(sumting::Latest))] ^***********************************************************************************^ "#}, ); diff --git a/crates/forge/tests/e2e/fork_warning.rs b/crates/forge/tests/e2e/fork_warning.rs index f9586f3874..400e72124f 100644 --- a/crates/forge/tests/e2e/fork_warning.rs +++ b/crates/forge/tests/e2e/fork_warning.rs @@ -1,9 +1,11 @@ use super::common::runner::{setup_package, test_runner}; use assert_fs::fixture::{FileWriteStr, PathChild}; use axum::{extract::Query, response::Redirect, routing::any, Router}; -use indoc::{formatdoc, indoc}; +use indoc::formatdoc; use lazy_static::lazy_static; -use shared::{consts::EXPECTED_RPC_VERSION, test_utils::output_assert::assert_stdout_contains}; +use shared::consts::EXPECTED_RPC_VERSION; +use shared::test_utils::node_url::node_url; +use shared::test_utils::output_assert::assert_stdout_contains; use std::{thread::sleep, time::Duration}; use tokio::{ net::TcpListener, @@ -39,17 +41,22 @@ fn setup_redirect_server() { #[test] fn should_print_warning() { let temp = setup_package("empty"); + let mut node_url = node_url().unwrap(); + node_url.set_path("rpc/v0_5"); temp.child("tests/test.cairo") - .write_str(indoc!( - r#" - #[fork(url: "http://188.34.188.184:7070/rpc/v0_5", block_id: BlockId::Tag(BlockTag::Latest))] + .write_str( + formatdoc!( + r#" + #[fork(url: "{node_url}", block_id: BlockId::Tag(BlockTag::Latest))] #[test] - fn t1() { + fn t1() {{ assert!(false); - } + }} "# - )) + ) + .as_str(), + ) .unwrap(); let output = test_runner(&temp).assert(); @@ -60,7 +67,7 @@ fn should_print_warning() { r" [..]Compiling[..] [..]Finished[..] - [WARNING] RPC node with the url http://188.34.188.184:7070/rpc/v0_5 uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} + [WARNING] RPC node with the url {node_url} uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} Collected 1 test(s) from empty package @@ -71,7 +78,7 @@ fn should_print_warning() { Failure[..] Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out - Latest block number = [..] for url = http://188.34.188.184:7070/rpc/v0_5 + Latest block number = [..] for url = {node_url} Failures: tests::test::t1 @@ -83,22 +90,27 @@ fn should_print_warning() { #[test] fn should_dedup_urls() { let temp = setup_package("empty"); + let mut node_url = node_url().unwrap(); + node_url.set_path("rpc/v0_5"); temp.child("tests/test.cairo") - .write_str(indoc!( - r#" - #[fork(url: "http://188.34.188.184:7070/rpc/v0_5", block_id: BlockId::Tag(BlockTag::Latest))] + .write_str( + formatdoc!( + r#" + #[fork(url: "{node_url}", block_id: BlockId::Tag(BlockTag::Latest))] #[test] - fn t1() { + fn t1() {{ assert!(false); - } - #[fork(url: "http://188.34.188.184:7070/rpc/v0_5", block_id: BlockId::Tag(BlockTag::Latest))] + }} + #[fork(url: "{node_url}", block_id: BlockId::Tag(BlockTag::Latest))] #[test] - fn t2() { + fn t2() {{ assert!(false); - } + }} "# - )) + ) + .as_str(), + ) .unwrap(); let output = test_runner(&temp).assert(); @@ -109,7 +121,7 @@ fn should_dedup_urls() { r" [..]Compiling[..] [..]Finished[..] - [WARNING] RPC node with the url http://188.34.188.184:7070/rpc/v0_5 uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} + [WARNING] RPC node with the url {node_url} uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} Collected 2 test(s) from empty package @@ -123,7 +135,7 @@ fn should_dedup_urls() { Failure[..] Tests: 0 passed, 2 failed, 0 skipped, 0 ignored, 0 filtered out - Latest block number = [..] for url = http://188.34.188.184:7070/rpc/v0_5 + Latest block number = [..] for url = {node_url} Failures: tests::test::t1 @@ -138,22 +150,24 @@ fn should_print_foreach() { setup_redirect_server(); let temp = setup_package("empty"); + let mut node_url = node_url().unwrap(); + node_url.set_path("rpc/v0_5"); temp.child("tests/test.cairo") - .write_str(indoc!( + .write_str(formatdoc!( r#" - #[fork(url: "http://127.0.0.1:3030?url=http://188.34.188.184:7070/rpc/v0_5", block_id: BlockId::Tag(BlockTag::Latest))] + #[fork(url: "http://127.0.0.1:3030?url={node_url}", block_id: BlockId::Tag(BlockTag::Latest))] #[test] - fn t1() { + fn t1() {{ assert!(false); - } - #[fork(url: "http://188.34.188.184:7070/rpc/v0_5", block_id: BlockId::Tag(BlockTag::Latest))] + }} + #[fork(url: "{node_url}", block_id: BlockId::Tag(BlockTag::Latest))] #[test] - fn t2() { + fn t2() {{ assert!(false); - } + }} "# - )) + ).as_str()) .unwrap(); let output = test_runner(&temp).assert(); @@ -164,8 +178,8 @@ fn should_print_foreach() { r" [..]Compiling[..] [..]Finished[..] - [WARNING] RPC node with the url http://127.0.0.1:3030?url=http://188.34.188.184:7070/rpc/v0_5 uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} - [WARNING] RPC node with the url http://188.34.188.184:7070/rpc/v0_5 uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} + [WARNING] RPC node with the url http://127.0.0.1:3030?url={node_url} uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} + [WARNING] RPC node with the url {node_url} uses incompatible version 0.5.1. Expected version: {EXPECTED_RPC_VERSION} Collected 2 test(s) from empty package @@ -179,8 +193,8 @@ fn should_print_foreach() { Failure[..] Tests: 0 passed, 2 failed, 0 skipped, 0 ignored, 0 filtered out - Latest block number = [..] for url = http://127.0.0.1:3030?url=http://188.34.188.184:7070/rpc/v0_5 - Latest block number = [..] for url = http://188.34.188.184:7070/rpc/v0_5 + Latest block number = [..] for url = http://127.0.0.1:3030?url={node_url} + Latest block number = [..] for url = {node_url} Failures: tests::test::t1 diff --git a/crates/forge/tests/e2e/forking.rs b/crates/forge/tests/e2e/forking.rs index c7a87789bf..bc04371ea4 100644 --- a/crates/forge/tests/e2e/forking.rs +++ b/crates/forge/tests/e2e/forking.rs @@ -1,13 +1,14 @@ use super::common::runner::{ - runner, setup_package, setup_package_with_file_patterns, test_runner, BASE_FILE_PATTERNS, + runner, setup_package_with_file_patterns, test_runner, BASE_FILE_PATTERNS, }; use forge::shared_cache::CACHE_DIR; -use indoc::indoc; +use indoc::{formatdoc, indoc}; +use shared::test_utils::node_url::node_rpc_url; use shared::test_utils::output_assert::assert_stdout_contains; #[test] fn without_cache() { - let temp = setup_package("forking"); + let temp = setup_package_with_file_patterns("forking", BASE_FILE_PATTERNS); let output = test_runner(&temp) .arg("forking::tests::test_fork_simple") @@ -106,6 +107,7 @@ fn printing_latest_block_number() { "forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); + let node_rpc_url = node_rpc_url().unwrap(); let output = test_runner(&temp) .args(["--exact", "forking::tests::print_block_number_when_latest"]) @@ -114,7 +116,7 @@ fn printing_latest_block_number() { assert_stdout_contains( output, - indoc! {r" + formatdoc! {r" [..]Compiling[..] [..]Finished[..] @@ -124,7 +126,7 @@ fn printing_latest_block_number() { [PASS] forking::tests::print_block_number_when_latest [..] Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 4 filtered out - Latest block number = [..] for url = http://188.34.188.184:7070/rpc/v0_7 + Latest block number = [..] for url = {node_rpc_url} "}, ); } diff --git a/crates/forge/tests/integration/cheat_fork.rs b/crates/forge/tests/integration/cheat_fork.rs index f58a7be0f5..9f2edded5a 100644 --- a/crates/forge/tests/integration/cheat_fork.rs +++ b/crates/forge/tests/integration/cheat_fork.rs @@ -1,10 +1,9 @@ use indoc::formatdoc; +use shared::test_utils::node_url::node_rpc_url; use test_utils::runner::assert_passed; use test_utils::running_tests::run_test_case; use test_utils::test_case; -static CHEATNET_RPC_URL: &str = "http://188.34.188.184:7070/rpc/v0_7"; - #[test] fn prank_cairo0_contract() { let test = test_case!(formatdoc!( @@ -44,7 +43,7 @@ fn prank_cairo0_contract() { assert(unpranked_caller == caller, 'stop_prank does not work'); }} "#, - CHEATNET_RPC_URL, + node_rpc_url().unwrap(), ) .as_str()); @@ -92,7 +91,7 @@ fn roll_cairo0_contract() { assert(unrolled_block_number == block_number, 'stop_roll does not work'); }} "#, - CHEATNET_RPC_URL, + node_rpc_url().unwrap(), ) .as_str()); @@ -142,7 +141,7 @@ fn warp_cairo0_contract() { assert(unwarped_block_timestamp == block_timestamp, 'stop_warp does not work'); }} "#, - CHEATNET_RPC_URL, + node_rpc_url().unwrap(), ) .as_str()); @@ -183,7 +182,7 @@ fn mock_call_cairo0_contract() { assert(eth_dispatcher.name() == 'Ether', 'invalid name after mock'); }} "#, - CHEATNET_RPC_URL, + node_rpc_url().unwrap(), ) .as_str()); @@ -228,7 +227,7 @@ fn store_load_cairo0_contract() { assert(name == array!['NotEther'], 'invalid load2 name'); }} "#, - CHEATNET_RPC_URL, + node_rpc_url().unwrap(), ) .as_str()); diff --git a/crates/forge/tests/integration/setup_fork.rs b/crates/forge/tests/integration/setup_fork.rs index a2bbc08dd5..b998cd5217 100644 --- a/crates/forge/tests/integration/setup_fork.rs +++ b/crates/forge/tests/integration/setup_fork.rs @@ -1,5 +1,4 @@ -use indoc::formatdoc; - +use indoc::{formatdoc, indoc}; use std::num::NonZeroU32; use std::path::Path; use std::process::Command; @@ -22,12 +21,11 @@ use forge_runner::forge_config::{ }; use forge_runner::CACHE_DIR; use shared::command::CommandExt; +use shared::test_utils::node_url::node_rpc_url; use test_utils::runner::{assert_case_output_contains, assert_failed, assert_passed, Contract}; use test_utils::running_tests::run_test_case; use test_utils::test_case; -const TESTNET_RPC_URL: &str = "http://188.34.188.184:7070/rpc/v0_7"; - #[test] fn fork_simple_decorator() { let test = test_case!(formatdoc!( @@ -63,7 +61,7 @@ fn fork_simple_decorator() { assert(balance == 100, 'Balance should be 100'); }} "#, - TESTNET_RPC_URL + node_rpc_url().unwrap() ).as_str()); let result = run_test_case(&test); @@ -73,7 +71,7 @@ fn fork_simple_decorator() { #[test] fn fork_aliased_decorator() { - let test = test_case!(formatdoc!( + let test = test_case!(indoc!( r#" use result::ResultTrait; use array::ArrayTrait; @@ -84,17 +82,17 @@ fn fork_aliased_decorator() { use starknet::contract_address_const; #[starknet::interface] - trait IHelloStarknet {{ + trait IHelloStarknet { fn increase_balance(ref self: TContractState, amount: felt252); fn get_balance(self: @TContractState) -> felt252; - }} + } #[test] #[fork("FORK_NAME_FROM_SCARB_TOML")] - fn fork_aliased_decorator() {{ - let dispatcher = IHelloStarknetDispatcher {{ + fn fork_aliased_decorator() { + let dispatcher = IHelloStarknetDispatcher { contract_address: contract_address_const::<0x202de98471a4fae6bcbabb96cab00437d381abc58b02509043778074d6781e9>() - }}; + }; let balance = dispatcher.get_balance(); assert(balance == 0, 'Balance should be 0'); @@ -103,9 +101,9 @@ fn fork_aliased_decorator() { let balance = dispatcher.get_balance(); assert(balance == 100, 'Balance should be 100'); - }} + } "# - ).as_str()); + )); let rt = Runtime::new().expect("Could not instantiate Runtime"); @@ -150,7 +148,7 @@ fn fork_aliased_decorator() { &[ForkTarget::new( "FORK_NAME_FROM_SCARB_TOML".to_string(), RawForkParams { - url: TESTNET_RPC_URL.to_string(), + url: node_rpc_url().unwrap().to_string(), block_id_type: "Tag".to_string(), block_id_value: "Latest".to_string(), }, @@ -184,7 +182,7 @@ fn fork_cairo0_contract() { assert(total_supply == 88730316280408105750094, 'Wrong total supply'); }} "#, - TESTNET_RPC_URL + node_rpc_url().unwrap() ).as_str()); let result = run_test_case(&test); @@ -209,7 +207,7 @@ fn get_block_info_in_forked_block() { }} #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Number(54060))] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(54060))] fn test_fork_get_block_info_contract_on_testnet() {{ let dispatcher = IBlockInfoCheckerDispatcher {{ contract_address: contract_address_const::<0x3d80c579ad7d83ff46634abe8f91f9d2080c5c076d4f0f59dd810f9b3f01164>() @@ -226,7 +224,7 @@ fn get_block_info_in_forked_block() { }} #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Number(54060))] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(54060))] fn test_fork_get_block_info_test_state() {{ let block_info = starknet::get_block_info().unbox(); assert(block_info.block_timestamp == 1711645884, block_info.block_timestamp.into()); @@ -236,7 +234,7 @@ fn get_block_info_in_forked_block() { }} #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Number(54060))] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Number(54060))] fn test_fork_get_block_info_contract_deployed() {{ let contract = declare("BlockInfoChecker").unwrap(); let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); @@ -253,13 +251,14 @@ fn get_block_info_in_forked_block() { }} #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Tag(BlockTag::Latest))] + #[fork(url: "{node_rpc_url}", block_id: BlockId::Tag(BlockTag::Latest))] fn test_fork_get_block_info_latest_block() {{ let block_info = starknet::get_block_info().unbox(); assert(block_info.block_timestamp > 1711645884, block_info.block_timestamp.into()); assert(block_info.block_number > 54060, block_info.block_number.into()); }} - "# + "#, + node_rpc_url = node_rpc_url().unwrap() ).as_str(), Contract::from_code_path( "BlockInfoChecker".to_string(), @@ -276,11 +275,12 @@ fn fork_get_block_info_fails() { let test = test_case!(formatdoc!( r#" #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Number(999999999999))] + #[fork(url: "{}", block_id: BlockId::Number(999999999999))] fn fork_get_block_info_fails() {{ starknet::get_block_info(); }} - "# + "#, + node_rpc_url().unwrap() ) .as_str()); @@ -311,7 +311,7 @@ fn incompatible_abi() { }} #[test] - #[fork(url: "{TESTNET_RPC_URL}", block_id: BlockId::Tag(BlockTag::Latest))] + #[fork(url: "{}", block_id: BlockId::Tag(BlockTag::Latest))] fn test_forking_functionality() {{ let gov_contract_addr: starknet::ContractAddress = 0x66e4b798c66160bd5fd04056938e5c9f65d67f183dfab9d7d0d2ed9413276fe.try_into().unwrap(); let dispatcher = IResponseWith2FeltsDispatcher {{ contract_address: gov_contract_addr }}; @@ -319,6 +319,7 @@ fn incompatible_abi() { assert(propdetails.payload == 8, 'payload not match'); }} "#, + node_rpc_url().unwrap() ) .as_str()); diff --git a/crates/forge/tests/integration/spy_events.rs b/crates/forge/tests/integration/spy_events.rs index 148f61df22..81aa0fb742 100644 --- a/crates/forge/tests/integration/spy_events.rs +++ b/crates/forge/tests/integration/spy_events.rs @@ -1,4 +1,5 @@ -use indoc::indoc; +use indoc::{formatdoc, indoc}; +use shared::test_utils::node_url::node_rpc_url; use std::path::Path; use test_utils::runner::{assert_case_output_contains, assert_failed, assert_passed, Contract}; use test_utils::running_tests::run_test_case; @@ -437,7 +438,7 @@ fn emit_unnamed_event() { use starknet::contract_address_const; use starknet::ContractAddress; - use snforge_std::{ + use snforge_std::{ declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions, Event, SpyOn }; @@ -624,52 +625,52 @@ fn assert_not_emitted_fails() { #[test] fn capture_cairo0_event() { let test = test_case!( - indoc!( + formatdoc!( r#" use array::ArrayTrait; use result::ResultTrait; - use starknet::{ContractAddress, contract_address_const}; - use snforge_std::{ declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, - EventAssertions, SpyOn }; + use starknet::{{ContractAddress, contract_address_const}}; + use snforge_std::{{ declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, + EventAssertions, SpyOn }}; #[starknet::interface] - trait ISpyEventsChecker { + trait ISpyEventsChecker {{ fn emit_one_event(ref self: TContractState, some_data: felt252); fn test_cairo0_event_collection(ref self: TContractState, cairo0_address: felt252); - } + }} #[starknet::contract] - mod SpyEventsChecker { + mod SpyEventsChecker {{ use starknet::ContractAddress; #[storage] - struct Storage {} + struct Storage {{}} #[event] #[derive(Drop, starknet::Event)] - enum Event { + enum Event {{ FirstEvent: FirstEvent, my_event: Cairo0Event, - } + }} #[derive(Drop, starknet::Event)] - struct FirstEvent { + struct FirstEvent {{ some_data: felt252 - } + }} #[derive(Drop, starknet::Event)] - struct Cairo0Event { + struct Cairo0Event {{ some_data: felt252 - } - } + }} + }} #[test] - #[fork(url: "http://188.34.188.184:7070/rpc/v0_7", block_id: BlockId::Tag(BlockTag::Latest))] - fn capture_cairo0_event() { + #[fork(url: "{}", block_id: BlockId::Tag(BlockTag::Latest))] + fn capture_cairo0_event() {{ let cairo0_contract_address = contract_address_const::<0x2c77ca97586968c6651a533bd5f58042c368b14cf5f526d2f42f670012e10ac>(); let contract = declare("SpyEventsChecker").unwrap(); let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; + let dispatcher = ISpyEventsCheckerDispatcher {{ contract_address }}; let mut spy = spy_events(SpyOn::All); @@ -681,31 +682,32 @@ fn capture_cairo0_event() { ( cairo0_contract_address, SpyEventsChecker::Event::my_event( - SpyEventsChecker::Cairo0Event { + SpyEventsChecker::Cairo0Event {{ some_data: 123456789 - } + }} ) ), ( contract_address, SpyEventsChecker::Event::FirstEvent( - SpyEventsChecker::FirstEvent { + SpyEventsChecker::FirstEvent {{ some_data: 420 - } + }} ) ), ( cairo0_contract_address, SpyEventsChecker::Event::my_event( - SpyEventsChecker::Cairo0Event { + SpyEventsChecker::Cairo0Event {{ some_data: 123456789 - } + }} ) ) ]); - } - "# - ), + }} + "#, + node_rpc_url().unwrap() + ).as_str(), Contract::from_code_path( "SpyEventsChecker".to_string(), Path::new("tests/data/contracts/spy_events_checker.cairo"), diff --git a/crates/forge/tests/integration/store_load.rs b/crates/forge/tests/integration/store_load.rs index 86408b3e9b..28735ba4e0 100644 --- a/crates/forge/tests/integration/store_load.rs +++ b/crates/forge/tests/integration/store_load.rs @@ -1,4 +1,5 @@ use indoc::{formatdoc, indoc}; +use shared::test_utils::node_url::node_rpc_url; use std::path::Path; use test_utils::runner::{assert_case_output_contains, assert_failed, assert_passed, Contract}; use test_utils::running_tests::run_test_case; @@ -554,7 +555,6 @@ fn store_load_felt_to_felt() { assert_passed(&result); } -static INTEGRATION_RPC_URL: &str = "http://188.34.188.184:7070/rpc/v0_7"; #[test] fn fork_store_load() { @@ -587,7 +587,7 @@ fn fork_store_load() { assert(balance == 100, 'Balance should be 100'); }} "#, - INTEGRATION_RPC_URL + node_rpc_url().unwrap() ).as_str()); let result = run_test_case(&test); diff --git a/scripts/smoke_test.sh b/scripts/smoke_test.sh index dd20f8abe1..e786b17551 100755 --- a/scripts/smoke_test.sh +++ b/scripts/smoke_test.sh @@ -17,7 +17,7 @@ popd || exit # Check cast -if ! $SNCAST_PATH --url "$RPC_URL":7070/rpc/v0_7 call \ +if ! $SNCAST_PATH --url "$RPC_URL" call \ --contract-address 0x06b248bde9ce00d69099304a527640bc9515a08f0b49e5168e2096656f207e1d \ --function "get" --calldata 0x1 | grep -q $'command: call\nresponse: [0x0]'; then exit 1