-
Notifications
You must be signed in to change notification settings - Fork 145
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
Moved Cairo code snippets to Scarb projects in docs/listings
#2470
base: master
Are you sure you want to change the base?
Conversation
listings
Scarb projectlistings
Scarb project
7a70cdf
to
af1a24e
Compare
listings
Scarb projectdocs/listings
docs/listings
listings
Scarb project
af1a24e
to
0536710
Compare
listings
Scarb projectdocs/listings
0080314
to
4515227
Compare
```rust | ||
#[test] | ||
fn call_and_invoke() { | ||
// ... | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 0, 'balance == 0'); | ||
|
||
dispatcher.increase_balance(100); | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 100, 'balance == 100'); | ||
} | ||
{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo}} | ||
``` | ||
|
||
However, when running this test, we will get a failure with a message | ||
This test passes, which means that `increase_balance` method panics with expected message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed to should panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot have panicking tests since we want to verify Cairo listings using scarb test
. That's why some tests are marked #[should_panic]
and some use safe dispatchers.
Also a few tests in the first chapter introducing to testing are presented as failing but in fact they have a hidden #[should_panic]
not appearing in the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at the whole document again and I think this is confusing to have it pass. If that's necessary you can add hidden should_panic
but we should be showing to the users that this fails so it's obvious what's the point of using a cheat there.
34093f4
to
0eba6f9
Compare
commit-id:e2a3655e
0eba6f9
to
5df9a0b
Compare
let contract_address: ContractAddress = 0x1e52f6ebc3e594d2a6dc2a0d7d193cb50144cfdfb7fdd9519135c29b67e427 | ||
.try_into() | ||
.expect('Invalid contract address value'); | ||
Structure use by the command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structure use by the command: | |
Structure used by the command: |
@@ -1,5 +1,9 @@ | |||
# Conditional Compilation | |||
|
|||
> 📝 **Note** | |||
> For an elaborative guide on Scarb conditional compilation, please refer to [Scarb documentation](https://docs.swmansion.com/scarb/docs/reference/conditional-compilation.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> For an elaborative guide on Scarb conditional compilation, please refer to [Scarb documentation](https://docs.swmansion.com/scarb/docs/reference/conditional-compilation.html) | |
> For more detailed guide on Scarb conditional compilation, please refer to [Scarb documentation](https://docs.swmansion.com/scarb/docs/reference/conditional-compilation.html) |
> Cheats related to contract execution context won't work for forked contracts written in **Cairo 0**. | ||
> Those cheatcodes are not going to have any effects: | ||
> | ||
> - start_spoof / stop_spoof | ||
> - spy_events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> Cheats related to contract execution context won't work for forked contracts written in **Cairo 0**. | |
> Those cheatcodes are not going to have any effects: | |
> | |
> - start_spoof / stop_spoof | |
> - spy_events | |
> Cheats related to contract execution context won't work for forked contracts written in **Cairo 0**. | |
> Those cheatcodes are not going to have any effects: | |
> | |
> - `start_spoof` / `stop_spoof` | |
> - `spy_events` |
```rust | ||
#[test] | ||
fn call_and_invoke() { | ||
// ... | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 0, 'balance == 0'); | ||
|
||
dispatcher.increase_balance(100); | ||
|
||
let balance = dispatcher.get_balance(); | ||
assert(balance == 100, 'balance == 100'); | ||
} | ||
{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo}} | ||
``` | ||
|
||
However, when running this test, we will get a failure with a message | ||
This test passes, which means that `increase_balance` method panics with expected message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at the whole document again and I think this is confusing to have it pass. If that's necessary you can add hidden should_panic
but we should be showing to the users that this fails so it's obvious what's the point of using a cheat there.
using [`stop_cheat_caller_address`](../appendix/cheatcodes/caller_address.md#stop_cheat_caller_address). | ||
We will demonstrate its behavior using `SafeDispatcher` to show when exactly the fail occurs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this should just fail (or at least appear as failed to the user).
I think you can also link this issue #1671 |
Stack:
docs/listings
to CI #2471docs/listings
#2470 ⬅