Skip to content

Commit

Permalink
Fix docs and minor stuff + bump version before release (#559)
Browse files Browse the repository at this point in the history
<!-- Reference any GitHub issues resolved by this PR -->

Closes #

## Introduced changes

<!-- A brief description of the changes -->

-
-

## Breaking changes

<!-- List of all breaking changes, if applicable -->

## Checklist

<!-- Make sure all of these are complete -->

- [ ] Linked relevant issue
- [ ] Updated relevant documentation
- [ ] Added relevant tests
- [ ] Performed self-review of the code
- [ ] Added changes to `CHANGELOG.md`
  • Loading branch information
piotmag769 authored Aug 30, 2023
1 parent 402ec0b commit 368dfde
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 22 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion crates/cheatnet/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion crates/forge/tests/e2e/common/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/e2e/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion docs/src/appendix/cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
> ```
2 changes: 1 addition & 1 deletion docs/src/appendix/forge-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
> ```
11 changes: 6 additions & 5 deletions docs/src/development/environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ 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

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:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/testing/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/testing/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs/src/testing/using-cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions scripts/prepare_for_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions scripts/test_cast.sh

This file was deleted.

9 changes: 0 additions & 9 deletions scripts/test_forge.sh

This file was deleted.

0 comments on commit 368dfde

Please sign in to comment.