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

Moved Cairo code snippets to Scarb projects in docs/listings #2470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

integraledelebesgue
Copy link
Member

@integraledelebesgue integraledelebesgue commented Sep 13, 2024

Stack:

⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@integraledelebesgue integraledelebesgue changed the title Moved Cairo code snippets to modules in listings Scarb project Introduced Docs Tests Sep 13, 2024
@integraledelebesgue integraledelebesgue changed the title Introduced Docs Tests Moved Cairo code snippets to modules in listings Scarb project Sep 13, 2024
@integraledelebesgue integraledelebesgue force-pushed the spr/master/e2a3655e branch 3 times, most recently from 7a70cdf to af1a24e Compare September 17, 2024 10:29
@integraledelebesgue integraledelebesgue changed the title Moved Cairo code snippets to modules in listings Scarb project Moved Cairo code snippets to Scarb projects in docs/listings Sep 17, 2024
@integraledelebesgue integraledelebesgue changed the title Moved Cairo code snippets to Scarb projects in docs/listings Moved Cairo code snippets to modules in listings Scarb project Sep 17, 2024
@integraledelebesgue integraledelebesgue changed the title Moved Cairo code snippets to modules in listings Scarb project Moved Cairo code snippets to Scarb projects in docs/listings Sep 17, 2024
@integraledelebesgue integraledelebesgue force-pushed the spr/master/e2a3655e branch 7 times, most recently from 0080314 to 4515227 Compare September 17, 2024 12:59
Comment on lines 29 to +33
```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.
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@integraledelebesgue integraledelebesgue force-pushed the spr/master/e2a3655e branch 4 times, most recently from 34093f4 to 0eba6f9 Compare September 19, 2024 11:18
let contract_address: ContractAddress = 0x1e52f6ebc3e594d2a6dc2a0d7d193cb50144cfdfb7fdd9519135c29b67e427
.try_into()
.expect('Invalid contract address value');
Structure use by the command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> 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)

Comment on lines +86 to 90
> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> 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`

Comment on lines 29 to +33
```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.
Copy link
Member

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.

Comment on lines +74 to +75
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:
Copy link
Member

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).

@cptartur
Copy link
Member

I think you can also link this issue #1671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants