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

Explain assert_macros in the guide #2531

Merged
merged 9 commits into from
Oct 1, 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
23 changes: 23 additions & 0 deletions docs/src/testing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,26 @@ Tests: 0 passed, 0 failed, 0 skipped, 1 ignored, 0 filtered out

To run only tests marked with the `#[ignore]` attribute use `snforge test --ignored`.
To run all tests regardless of the `#[ignore]` attribute use `snforge test --include-ignored`.

## Writing Assertions and `assert_macros` Package
> ⚠️ **Recommended only for development** ️⚠️
>
>***Assert macros package provides a set of macros that can be used to write assertions such as `assert_eq!`.
In order to use it, your project must have the `assert_macros` dependency added to the `Scarb.toml` file.
These macros are very expensive to run on Starknet, as they result a huge amount of steps and are not recommended for production use.
They are only meant to be used in tests.
For snforge `v0.31.0` and later, this dependency is added automatically when creating a project using `snforge init`. But for earlier versions, you need to add it manually.***

```toml
[dev-dependencies]
snforge_std = ...
assert_macros = "<scarb-version>"
```

Available assert macros are
- `assert_eq!`
- `assert_ne!`
- `assert_lt!`
- `assert_le!`
- `assert_gt!`
- `assert_ge!`
4 changes: 4 additions & 0 deletions docs/src/testing/using-cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ When testing smart contracts, often there are parts of code that are dependent o
Instead of trying to replicate these conditions in tests, you can emulate them
using [cheatcodes](../appendix/cheatcodes.md).

> ⚠️ **Warning**
>
> These examples make use of `assert_macros`, so it's recommended to get familiar with them first. [Learn more about `assert_macros`](testing.md#writing-assertions-and-assert_macros-package)

## The Test Contract

In this tutorial, we will be using the following Starknet contract:
Expand Down
Loading