Skip to content

Commit

Permalink
Explain assert_macros in the guide (#2531)
Browse files Browse the repository at this point in the history
<!-- Reference any GitHub issues resolved by this PR -->

Closes #2481

## Introduced changes

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

- Added info about `assert_macros` in docs

## Checklist

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

- [x] Linked relevant issue
- [x] Updated relevant documentation
- [x] Added relevant tests
- [x] Performed self-review of the code
- [x] Added changes to `CHANGELOG.md`

---------

Co-authored-by: Artur Michałek <[email protected]>
  • Loading branch information
kkawula and cptartur authored Oct 1, 2024
1 parent f0cbefb commit 9d9f2ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit 9d9f2ab

Please sign in to comment.