Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update Running Tests docs section #2006

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SEPOLIA_RPC_URL=https://example.com/rpc/v0_7
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -57,7 +61,8 @@ jobs:
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
- uses: software-mansion/[email protected]
- 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
Expand Down Expand Up @@ -93,11 +98,8 @@ jobs:
run: ./scripts/install_devnet.sh
- uses: software-mansion/[email protected]
- 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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Scarb.lock
.spr.yml
.snfoundry_cache/
.snfoundry_trace/
.env
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cheatnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion crates/cheatnet/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtendedStateReader> {
Expand All @@ -24,7 +25,7 @@ pub fn create_fork_cached_state_at(
block_number: u64,
cache_dir: &str,
) -> CachedState<ExtendedStateReader> {
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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatnet/tests/starknet/forking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ axum.workspace = true
lazy_static.workspace = true
indoc.workspace = true
tempfile.workspace = true
walkdir.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
10 changes: 5 additions & 5 deletions crates/forge/tests/data/forking/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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::<
Expand All @@ -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::<
Expand All @@ -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() {
Expand All @@ -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
)
Expand All @@ -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, '');
}
Expand Down
24 changes: 24 additions & 0 deletions crates/forge/tests/e2e/common/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -49,13 +52,34 @@ 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
}

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"])
Expand Down
Loading
Loading