Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
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
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.9.4
starknet-foundry 0.37.0
scarb 2.10.1
starknet-foundry 0.38.0
12 changes: 8 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "cairo_cheatsheet"
version = "0.1.0"

[[package]]
name = "calling_other_contracts"
version = "0.1.0"
Expand Down Expand Up @@ -242,15 +246,15 @@ dependencies = [

[[package]]
name = "snforge_scarb_plugin"
version = "0.37.0"
version = "0.38.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:9dbb114f853decc27b2d6d53e2ddd207217ce63c2d24a47c5c48d5f475b0b9a5"
checksum = "sha256:c4d128eedb5fca4362be38a84e5f5a85bd94ec1557bab7c045d48de0163e406c"

[[package]]
name = "snforge_std"
version = "0.37.0"
version = "0.38.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:f5702c4a6d54e3563b4aa78c834de6ddcf18ef8ca8fd35dc1bceb7ece58e9571"
checksum = "sha256:8b3eaff778105c313b78708974c253cd927ecf5c896f4557a0ea4f10f427b554"
dependencies = [
"snforge_scarb_plugin",
]
Expand Down
8 changes: 4 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ test = "$(git rev-parse --show-toplevel)/scripts/test_resolver.sh"
[workspace.tool.snforge]

[workspace.dependencies]
starknet = "2.9.4"
cairo_test = "2.9.4"
assert_macros = "2.9.4"
snforge_std = "0.37.0"
starknet = "2.10.1"
cairo_test = "2.10.1"
assert_macros = "2.10.1"
snforge_std = "0.38.0"
openzeppelin_account = "1.0.0"
openzeppelin_introspection = "1.0.0"
openzeppelin_presets = "1.0.0"
Expand Down
1 change: 0 additions & 1 deletion listings/cairo_cheatsheet/listing/.gitignore

This file was deleted.

3 changes: 3 additions & 0 deletions listings/getting-started/testing_how_to/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ mod contract;
pub use contract::{
InventoryContract, IInventoryContractDispatcher, IInventoryContractDispatcherTrait,
};

#[cfg(test)]
mod test_contract;
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ trait ArrayTrait<T> {
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/array_example.cairo]
// [!include ~/listings/cairo_cheatsheet/src/array_example.cairo]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/dict.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ A dictionary is a data structure used to store key-value pairs, enabling efficie
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/dict_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/dict_example.cairo:sheet]
```
4 changes: 2 additions & 2 deletions pages/cairo_cheatsheet/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Just like other programming languages, enums (enumerations) are used in cairo to
In cairo, `enum variants` can hold different data types (the unit type, structs, other enums, tuples, default core library types, arrays, dictionaries, ...), as shown in the code snippet below. Furthermore, as a quick reminder, enums are expressions, meaning they can return values.

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/enum_example.cairo:enums]
// [!include ~/listings/cairo_cheatsheet/src/enum_example.cairo:enums]
```

Enums can be declared both inside and outside a contract. If declared outside, they need to be imported inside using the `use` keyword, just like other imports.
Expand All @@ -24,5 +24,5 @@ Enums can be declared both inside and outside a contract. If declared outside, t
Here is an example of a contract illustrating the above statements :

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/enum_example.cairo:enum_contract]
// [!include ~/listings/cairo_cheatsheet/src/enum_example.cairo:enum_contract]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/felt.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/felt_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/felt_example.cairo:sheet]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/if_let.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A `if let` statement is a combination of an `if` statement and a `let` statement. It allows you to execute the block only if the pattern matches. It's a cleaner way to handle a `match` statement with only one pattern that you want to handle.

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/if_let_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/if_let_example.cairo:sheet]
```

### See also
Expand Down
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A `loop` specifies a block of code that will run repetitively until a halting co
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/loop_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/loop_example.cairo:sheet]
```

### See also
Expand Down
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
The `Map` type can be used to represent a collection of key-value.

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/mapping_example.cairo]
// [!include ~/listings/cairo_cheatsheet/src/mapping_example.cairo]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ The `match` expression in Cairo allows us to control the flow of our code by com
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/match_example.cairo]
// [!include ~/listings/cairo_cheatsheet/src/match_example.cairo]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ A struct is a data type similar to a tuple. Like tuples, they can be used to hol
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/struct_example.cairo]
// [!include ~/listings/cairo_cheatsheet/src/struct_example.cairo]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Tuples is a data type to group a fixed number of items of potentially different
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/tuple_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/tuple_example.cairo:sheet]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/type_casting.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ The `into` method is used for conversion from a smaller data type to a larger da
For example:

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/type_casting_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/type_casting_example.cairo:sheet]
```
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/while.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A `while` loop allows you to specify a condition that must be true for the loop to continue.

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/while_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/while_example.cairo:sheet]
```

### See also
Expand Down
2 changes: 1 addition & 1 deletion pages/cairo_cheatsheet/while_let.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A `while let` loop is a combination of a `while` loop and a `let` statement. It allows you to execute the loop body only if the pattern matches.

```cairo
// [!include ~/listings/cairo_cheatsheet/listing/src/while_let_example.cairo:sheet]
// [!include ~/listings/cairo_cheatsheet/src/while_let_example.cairo:sheet]
```

### See also
Expand Down
2 changes: 1 addition & 1 deletion pages/getting-started/syscalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ The system call does not add any padding and the input needs to be a multiple of
## Additional Resources

- [Official Syscalls Documentation](https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/system-calls-cairo1/)
- [Source Code](https://github.com/starkware-libs/cairo/blob/v2.9.4/corelib/src/starknet/syscalls.cairo)
- [Source Code](https://github.com/starkware-libs/cairo/blob/v2.10.1/corelib/src/starknet/syscalls.cairo)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ There's two main *test runners* for Cairo:
<div class="flex justify-center">
| Test Runner | Scope | Best For |
|----------------------------------------------------|---------------------|-------------------------------|
| **[Snforge](./testing/testing-snforge.md)** | Starknet contracts | Full smart contract testing with blockchain state |
| **[Cairo Test](./testing/testing-cairo-test.md)** | Pure Cairo packages | Non-blockchain-state logic validation / testing |
| **[Snforge](/getting-started/testing/testing-snforge)** | Starknet contracts | Full smart contract testing with blockchain state |
| **[Cairo Test](/getting-started/testing/testing-cairo-test)** | Pure Cairo packages | Non-blockchain-state logic validation / testing |
</div>

:::warning[Recommendation]
Expand Down
2 changes: 1 addition & 1 deletion pages/getting-started/testing/testing-cairo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Cairo-test is the included testing framework from Cairo, and can be run with `sc
You need to add it as a dev dependency with the following line in your `Scarb.toml`:
```toml
[dev-dependencies]
cairo_test = "2.9.4" // Version should be same as your Starknet/Scarb version
cairo_test = "2.10.1" // Version should be same as your Starknet/Scarb version
```

Testing is done similarly as shown in the [Testing with Snforge](/getting-started/testing/testing-snforge) section, but all the snforge specific features are not available.
Expand Down
8 changes: 4 additions & 4 deletions pages/getting-started/testing/testing-snforge.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Each test function requires the `#[test]` attribute. For tests that should verif
Here's a comprehensive test example:

```cairo
// [!include ~/listings/getting-started/testing_how_to/tests/test_contract.cairo:tests]
// [!include ~/listings/getting-started/testing_how_to/src/test_contract.cairo:tests]
```

## Testing Techniques
Expand All @@ -49,23 +49,23 @@ Here's a comprehensive test example:
For testing specific storage scenarios, snforge provides `load` and `store` functions:

```cairo
// [!include ~/listings/getting-started/testing_how_to/tests/test_contract.cairo:tests_with_direct_storage_access]
// [!include ~/listings/getting-started/testing_how_to/src/test_contract.cairo:tests_with_direct_storage_access]
```

### Contract State Testing

Use `Contract::contract_state_for_testing` to access internal contract state:

```cairo
// [!include ~/listings/getting-started/testing_how_to/tests/test_contract.cairo:tests_with_contract_state]
// [!include ~/listings/getting-started/testing_how_to/src/test_contract.cairo:tests_with_contract_state]
```

### Event Testing

To verify event emissions:

```cairo
// [!include ~/listings/getting-started/testing_how_to/tests/test_contract.cairo:tests_with_events]
// [!include ~/listings/getting-started/testing_how_to/src/test_contract.cairo:tests_with_events]
```

:::info
Expand Down
4 changes: 2 additions & 2 deletions pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ To deepen your knowledge:
The current version of this book uses:

```md
cairo 2.9.4
cairo 2.10.1
edition 2024_07
sierra 1.6.0
sierra 1.7.0
// .tool-versions:
// [!include ~/.tool-versions]
```
Expand Down
2 changes: 1 addition & 1 deletion routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const config: Sidebar = [
},
{
text: "Testing contracts",
link: "/getting-started/testing/testing",
link: "/getting-started/testing/",
items: [
{
text: "With Snforge",
Expand Down