From 368dfdecb7555abba53654a65aafd62c92f3ae4c Mon Sep 17 00:00:00 2001 From: Piotr Magiera <56825108+piotmag769@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:40:49 +0200 Subject: [PATCH] Fix docs and minor stuff + bump version before release (#559) Closes # ## Introduced changes - - ## Breaking changes ## Checklist - [ ] Linked relevant issue - [ ] Updated relevant documentation - [ ] Added relevant tests - [ ] Performed self-review of the code - [ ] Added changes to `CHANGELOG.md` --- CHANGELOG.md | 1 + CONTRIBUTING.md | 36 ++++++++++++++--------- Cargo.lock | 4 +-- Cargo.toml | 2 +- crates/cheatnet/tests/main.rs | 3 +- crates/forge/tests/e2e/common/runner.rs | 2 +- crates/forge/tests/e2e/running.rs | 4 +-- docs/src/appendix/cheatcodes.md | 2 +- docs/src/appendix/forge-library.md | 2 +- docs/src/development/environment-setup.md | 11 +++---- docs/src/testing/contracts.md | 4 +-- docs/src/testing/debugging.md | 2 +- docs/src/testing/using-cheatcodes.md | 6 ++-- scripts/prepare_for_tests.sh | 1 + scripts/test_cast.sh | 8 ----- scripts/test_forge.sh | 9 ------ 16 files changed, 46 insertions(+), 51 deletions(-) delete mode 100755 scripts/test_cast.sh delete mode 100755 scripts/test_forge.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 196729dc35..35a38cf41e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - support for `roll`ing/`warp`ing/`prank`ing the constructor logic (precalculate address, prank, assert pranked state in constructor) - `spy_events` cheatcode - support for printing in contracts +- `spoof` cheatcode ### Cast diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 883e18a419..157617925c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,35 +20,43 @@ To run tests scripts, you have to install: - [asdf](https://asdf-vm.com/guide/getting-started.html) - [starknet-devnet](https://0xspaceshard.github.io/starknet-devnet/docs/intro) -> ⚠️ Make sure you run `./scripts/prepare_for_tests.sh` after setting up the development environment, otherwise the -> tests will fail. +> ⚠️ Make sure you run `./scripts/prepare_for_tests.sh` +> and then set [Scarb](https://docs.swmansion.com/scarb/) version +> [compatible](https://github.com/foundry-rs/starknet-foundry/releases) with both `snforge` and `sncast` +> after setting up the development environment, otherwise the tests will fail. Before creating a contribution, make sure your code passes the following checks ```shell -./scripts/test_forge.sh -./scripts/test_cast.sh -cargo fmt --check -cargo lint +$ cargo test +$ cargo fmt --check +$ cargo lint ``` Otherwise, it won't be possible to merge your contribution. -You can also run specific set of tests, by directly running `cargo test`. +You can also run a specific set of tests, by directly running `cargo test`. For forge tests, make sure you are in `crates/forge` directory: ```shell -forge $ cargo test --lib # runs all unit tests -forge $ cargo test integration # runs all integration tests -forge $ cargo test e2e # runs all e2e tests +$ cargo test --lib # runs all unit tests +$ cargo test integration # runs all integration tests +$ cargo test e2e # runs all e2e tests ``` Similarly, to run cast tests make sure you are in `crates/cast` directory: ```shell -cast $ cargo test --lib # runs lib unit tests -cast $ cargo test helpers # runs helpers unit tests -cast $ cargo test integration # runs all integration tests -cast $ cargo test e2e # runs all e2e tests +$ cargo test --lib # runs lib unit tests +$ cargo test helpers # runs helpers unit tests +$ cargo test integration # runs all integration tests +$ cargo test e2e # runs all e2e tests +``` + +Or to run cheatnet tests make sure you are in `crates/cheatnet` directory: +```shell +$ cargo test --lib # runs lib unit tests +$ cargo test cheatcodes # runs all cheatcodes tests +$ cargo test starknet # runs all starknet tests ``` ## Contributing diff --git a/Cargo.lock b/Cargo.lock index 7850010e1d..9b693a52e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,7 +1073,7 @@ dependencies = [ [[package]] name = "cast" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "camino", @@ -1724,7 +1724,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "forge" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "ark-ff", diff --git a/Cargo.toml b/Cargo.toml index e097181b5f..cb16c138e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ [workspace.package] name = "starknet-foundry" -version = "0.4.1" +version = "0.5.0" edition = "2021" repository = "https://github.com/foundry-rs/starknet-foundry" license = "MIT" diff --git a/crates/cheatnet/tests/main.rs b/crates/cheatnet/tests/main.rs index 5b761f08a5..e2dc42b3fd 100644 --- a/crates/cheatnet/tests/main.rs +++ b/crates/cheatnet/tests/main.rs @@ -9,9 +9,10 @@ fn init() { use camino::Utf8PathBuf; let contracts_path = Utf8PathBuf::from("tests").join("contracts"); - std::process::Command::new("scarb") + let output = std::process::Command::new("scarb") .current_dir(contracts_path) .arg("build") .output() .unwrap(); + assert!(output.status.success()); } diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 1337bde9dd..4c3c9b3ddd 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -53,7 +53,7 @@ pub(crate) fn setup_package(package_name: &str) -> TempDir { /// In the context of GITHUB actions, get the source branch that triggered the workflow run. /// Locally returns current branch. -pub(crate) fn gen_current_branch() -> String { +pub(crate) fn get_current_branch() -> String { let name: &str = "BRANCH_NAME"; match env::var(name) { Ok(v) => v, diff --git a/crates/forge/tests/e2e/running.rs b/crates/forge/tests/e2e/running.rs index 9232f7d5f1..7c5426eb22 100644 --- a/crates/forge/tests/e2e/running.rs +++ b/crates/forge/tests/e2e/running.rs @@ -2,7 +2,7 @@ use assert_fs::fixture::{FileWriteStr, PathChild, PathCopy}; use camino::Utf8PathBuf; use indoc::{formatdoc, indoc}; -use crate::e2e::common::runner::{gen_current_branch, runner, setup_package}; +use crate::e2e::common::runner::{get_current_branch, runner, setup_package}; use assert_fs::TempDir; use std::str::FromStr; @@ -52,7 +52,7 @@ fn simple_package_with_git_dependency() { let temp = TempDir::new().unwrap(); temp.copy_from("tests/data/simple_package", &["**/*.cairo", "**/*.toml"]) .unwrap(); - let branch = gen_current_branch(); + let branch = get_current_branch(); let manifest_path = temp.child("Scarb.toml"); manifest_path .write_str(&formatdoc!( diff --git a/docs/src/appendix/cheatcodes.md b/docs/src/appendix/cheatcodes.md index 55620da102..e686568a60 100644 --- a/docs/src/appendix/cheatcodes.md +++ b/docs/src/appendix/cheatcodes.md @@ -18,5 +18,5 @@ > using appropriate release tag. >```toml > [dependencies] -> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.4.0" } +> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } > ``` diff --git a/docs/src/appendix/forge-library.md b/docs/src/appendix/forge-library.md index abcfbc34f7..96292288e9 100644 --- a/docs/src/appendix/forge-library.md +++ b/docs/src/appendix/forge-library.md @@ -13,5 +13,5 @@ > using appropriate release tag. >```toml > [dependencies] -> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.4.0" } +> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } > ``` diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index bb634ee09e..bead1350c9 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -24,14 +24,15 @@ It is not possible to run tests without these installed. ## Running Tests -> ⚠️ Make sure you run `./scripts/prepare_for_tests.sh` after setting up the development environment, otherwise the -> tests will fail. +> ⚠️ Make sure you run `./scripts/prepare_for_tests.sh` +> and then set [Scarb](https://docs.swmansion.com/scarb/) version +> [compatible](https://github.com/foundry-rs/starknet-foundry/releases) with both `snforge` and `sncast` +> after setting up the development environment, otherwise the tests will fail. Tests can be run with: ```shell -$ ./scripts/test_cast.sh -$ ./scripts/test_forge.sh +$ cargo test ``` ## Formatting and Lints @@ -39,7 +40,7 @@ $ ./scripts/test_forge.sh Starknet Foundry uses [rustfmt](https://github.com/rust-lang/rustfmt) for formatting. You can run the formatter with ```shell -cargo fmt +$ cargo fmt ``` For linting, it uses [clippy](https://github.com/rust-lang/rust-clippy). You can run it with this command: diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index ada2560b40..510064ea28 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -7,7 +7,7 @@ > using appropriate release tag. >```toml > [dependencies] -> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.4.0" } +> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } > ``` Using unit testing as much as possible is a good practice, as it makes your test suites run faster. However, when @@ -53,7 +53,7 @@ Note that the name after `mod` will be used as the contract name for testing pur Let's write a test that will deploy the `HelloStarknet` contract and call some functions. ```rust -use snforge_std::{ declare, PreparedContrac, deploy }; +use snforge_std::{ declare, ContractClassTrait }; #[test] fn call_and_invoke() { diff --git a/docs/src/testing/debugging.md b/docs/src/testing/debugging.md index 772ff0087e..9c2a967d86 100644 --- a/docs/src/testing/debugging.md +++ b/docs/src/testing/debugging.md @@ -6,7 +6,7 @@ > using appropriate release tag. >```toml > [dependencies] -> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.4.0" } +> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } > ``` Starknet Foundry standard library adds a utility method for printing inside tests and contracts to facilitate simple debugging. diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index f6c87ca05d..6fdefd58a4 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -6,7 +6,7 @@ > using appropriate release tag. >```toml > [dependencies] -> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.4.0" } +> snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } > ``` When testing smart contracts, often there are parts of code that are dependent on a specific blockchain state. @@ -100,7 +100,7 @@ so it passes our validation. ### Pranking the Address ```rust -use snforge_std::{ declare, PreparedContract, deploy, start_prank }; +use snforge_std::{ declare, ContractClassTrait, start_prank }; #[test] fn call_and_invoke() { @@ -180,7 +180,7 @@ and then use it in `start_prank` as an argument: ```rust -use snforge_std::{ declare, PreparedContract, ContractClassTrait, deploy, start_prank }; +use snforge_std::{ declare, ContractClassTrait, start_prank }; #[test] fn prank_the_constructor() { diff --git a/scripts/prepare_for_tests.sh b/scripts/prepare_for_tests.sh index 7c0bcd1a28..45060c4ee9 100755 --- a/scripts/prepare_for_tests.sh +++ b/scripts/prepare_for_tests.sh @@ -70,6 +70,7 @@ for scarb_version in "${SCARB_VERSIONS[@]}"; do done asdf global scarb 0.4.1 +rm .tool-versions echo "All done!" exit 0 diff --git a/scripts/test_cast.sh b/scripts/test_cast.sh deleted file mode 100755 index d93d54b608..0000000000 --- a/scripts/test_cast.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -set -e - -cd -P -- "$(dirname -- "$0")" - -./prepare_for_tests.sh -cargo test -p cast diff --git a/scripts/test_forge.sh b/scripts/test_forge.sh deleted file mode 100755 index 9c2377862f..0000000000 --- a/scripts/test_forge.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -set -e - -cd -P -- "$(dirname -- "$0")" - -asdf install scarb 0.7.0 -asdf global scarb 0.7.0 -cargo test --release -p forge