Skip to content

Commit

Permalink
Update CI and tests with NODE_URL getter function
Browse files Browse the repository at this point in the history
commit-id:99e99636

Apply review suggestions to tests (to rebase)
  • Loading branch information
tomek0123456789 committed Apr 17, 2024
1 parent 2c59a45 commit cd8f718
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 169 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
name: Test Forge / Unit and Integration Tests
runs-on: ubuntu-latest
steps:
- name: Set NODE_URL for foundry-rs/starknet-foundry
if: ${{ github.event.pull_request.head.repo.full_name == 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }}:7070)" >> $GITHUB_ENV

- name: Set NODE_URL for forks
if: ${{ github.event.pull_request.head.repo.full_name != 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }})" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
Expand Down Expand Up @@ -42,6 +50,14 @@ jobs:
if: github.event_name == 'pull_request'
run: echo "REPO_NAME=$(echo ${{ github.event.pull_request.head.repo.full_name }}.git)" >> $GITHUB_ENV

- name: Set NODE_URL for foundry-rs/starknet-foundry
if: ${{ github.event.pull_request.head.repo.full_name == 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }}:7070)" >> $GITHUB_ENV

- name: Set NODE_URL for forks
if: ${{ github.event.pull_request.head.repo.full_name != 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }})" >> $GITHUB_ENV

- name: Print repo name
run: echo 'The repo name is' $REPO_NAME

Expand Down Expand Up @@ -72,6 +88,14 @@ jobs:
name: Test Cheatnet
runs-on: ubuntu-latest
steps:
- name: Set NODE_URL for foundry-rs/starknet-foundry
if: ${{ github.event.pull_request.head.repo.full_name == 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }}:7070)" >> $GITHUB_ENV

- name: Set NODE_URL for forks
if: ${{ github.event.pull_request.head.repo.full_name != 'foundry-rs/starknet-foundry' }}
run: echo "NODE_URL=$(echo ${{ secrets.NODE_URL }})" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
Expand Down
2 changes: 1 addition & 1 deletion .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 }}
RPC_URL: ${{ secrets.RPC_URL }}
run: |
BINARY_PATH="${{ env.BINARY_PATH }}"
BINARY_PATH="${BINARY_PATH%.tar.gz}"
Expand Down
2 changes: 2 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_url_with_version;
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_url_with_version().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 @@ -644,7 +644,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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ RPC_URL }}", block_id: BlockId::Tag(Latest))]
fn print_block_number_when_latest() {
assert(1 == 1, '');
}
Expand Down
30 changes: 30 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_url_with_version;
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 @@ -56,6 +59,33 @@ pub(crate) fn setup_package(package_name: &str) -> TempDir {
setup_package_with_file_patterns(package_name, BASE_FILE_PATTERNS)
}

pub(crate) fn setup_package_with_rpc_url_placeholders(
package_name: &str,
file_patterns: &[&str],
) -> TempDir {
let temp_dir = setup_package_with_file_patterns(package_name, file_patterns);
replace_rpc_url_placeholders(temp_dir.path());
temp_dir
}

fn replace_rpc_url_placeholders(dir_path: &Path) {
let url = node_url_with_version().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("{{ 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

0 comments on commit cd8f718

Please sign in to comment.