From 3c4a07678e5f682afffbce1839b77a4b18bbadfe Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 8 Nov 2024 17:38:38 +0100 Subject: [PATCH 001/183] Add expandable shell snippet outputs --- docs/src/development/environment-setup.md | 19 +++-- docs/src/getting-started/first-steps.md | 13 ++-- docs/src/projects/configuration.md | 4 +- .../snforge-advanced-features/fuzz-testing.md | 4 +- .../snforge-advanced-features/profiling.md | 6 +- docs/src/starknet/account-import.md | 10 +-- docs/src/starknet/account.md | 18 ++--- docs/src/starknet/call.md | 21 ++++-- docs/src/starknet/calldata-transformation.md | 4 +- docs/src/starknet/declare.md | 9 ++- docs/src/starknet/deploy.md | 41 +++++++++-- docs/src/starknet/fees-and-versions.md | 10 ++- docs/src/starknet/index.md | 22 +++++- docs/src/starknet/invoke.md | 17 ++++- docs/src/starknet/multicall.md | 26 ++++++- docs/src/starknet/script.md | 73 ++++++++++++++++--- docs/src/starknet/show_config.md | 11 ++- docs/src/starknet/tx-status.md | 9 ++- docs/src/starknet/verify.md | 9 ++- docs/src/testing/contracts.md | 30 +++++++- docs/src/testing/coverage.md | 8 +- docs/src/testing/running-tests.md | 50 +++++++++++-- docs/src/testing/test-collection.md | 10 ++- docs/src/testing/testing-workspaces.md | 35 +++++++-- docs/src/testing/testing.md | 39 +++++++++- docs/src/testing/using-cheatcodes.md | 30 +++++++- 26 files changed, 423 insertions(+), 105 deletions(-) diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index dbc8108506..0d9aa26320 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -11,7 +11,7 @@ Install the latest stable [Rust](https://www.rust-lang.org/tools/install) versio If you already have Rust installed make sure to upgrade it by running ```shell -$ rustup update +rustup update ``` ### Scarb @@ -55,7 +55,7 @@ Install the latest [universal-sierra-compiler](https://github.com/software-mansi Tests can be run with: ```shell -$ cargo test +cargo test ``` @@ -64,19 +64,19 @@ $ cargo test Starknet Foundry uses [rustfmt](https://github.com/rust-lang/rustfmt) for formatting. You can run the formatter with ```shell -$ cargo fmt +cargo fmt ``` For linting, it uses [clippy](https://github.com/rust-lang/rust-clippy). You can run it with this command: ```shell -$ cargo clippy --all-targets --all-features -- --no-deps -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::default_trait_access +cargo clippy --all-targets --all-features -- --no-deps -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::default_trait_access ``` Or using our defined alias ```shell -$ cargo lint +cargo lint ``` ## Spelling @@ -86,14 +86,19 @@ Starknet Foundry uses [typos](https://github.com/marketplace/actions/typos-actio You can run the checker with ```shell -$ typos +typos ``` -Some typos can be automatically fixed by running +Some typos can be automatically fixed by running``` +
+Click to expand output + +```shell ```shell $ typos -w ``` +
## Contributing diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 36036d2a66..ac90aa9090 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -6,14 +6,14 @@ We demonstrate how to create a new project, compile, and test it. To start a new project with Starknet Foundry, run `snforge init` ```shell -$ snforge init project_name +snforge init project_name ``` Let's check out the project structure ```shell -$ cd project_name -$ tree . -L 1 +cd project_name +tree . -L 1 . ├── Scarb.lock ├── Scarb.toml @@ -31,7 +31,7 @@ $ tree . -L 1 And run tests with `snforge test` ```shell -$ snforge test +snforge test Compiling project_name v0.1.0 (project_name/Scarb.toml) Finished release target(s) in 1 second @@ -60,7 +60,7 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag Make sure that the version in `tag` matches `snforge`. You can check the currently installed version with ```shell -$ snforge --version +snforge --version snforge 0.27.0 ``` @@ -69,7 +69,7 @@ using [`scarb add`](https://docs.swmansion.com/scarb/docs/guides/dependencies.ht command. ```shell -$ scarb add snforge_std \ +scarb add snforge_std \ --dev \ --git https://github.com/foundry-rs/starknet-foundry.git \ --tag v0.27.0 @@ -80,3 +80,4 @@ Additionally, ensure that starknet-contract target is enabled in the `Scarb.toml ```toml # ... [[target.starknet-contract]] +``` \ No newline at end of file diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index e4cf1e2931..73846c06a5 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -50,7 +50,7 @@ defined in the profile. > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. ```shell -$ sncast --profile myprofile \ +sncast --profile myprofile \ call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ @@ -81,7 +81,7 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. ```shell -$ sncast call \ +sncast call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ --calldata 0x0 \ diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index a00880aa1a..a2e1070b78 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -23,7 +23,7 @@ The test will be run many times against different randomly generated values. Then run `snforge test` like usual. ```shell -$ snforge test +snforge test Collected 1 test(s) from fuzz_testing package Running 1 test(s) from src/ Running 0 test(s) from tests/ @@ -57,7 +57,7 @@ It is possible to configure the number of runs of the random fuzzer as well as i It can also be configured globally, via command line arguments: ```shell -$ snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 +snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 ``` Or in `Scarb.toml` file: diff --git a/docs/src/snforge-advanced-features/profiling.md b/docs/src/snforge-advanced-features/profiling.md index e7fbc16fd8..c9d641e6e3 100644 --- a/docs/src/snforge-advanced-features/profiling.md +++ b/docs/src/snforge-advanced-features/profiling.md @@ -9,7 +9,7 @@ You can inspect the call tree, see how many resources are used for different par All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -$ snforge test --save-trace-data +snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -18,7 +18,7 @@ for the [cairo-profiler](https://github.com/software-mansion/cairo-profiler). If you want `snforge` to call `cairo-profiler` on generated files automatically, use [`--build-profile`](../appendix/snforge/test.md#--build-profile) flag: ```shell -$ snforge test --build-profile +snforge test --build-profile ``` ## Passing arguments to `cairo-profiler` @@ -27,7 +27,7 @@ You can pass additional arguments to `cairo-profiler` by using the `--` separato to `cairo-profiler`: ```shell -$ snforge test --build-profile -- --show-inlined-functions +snforge test --build-profile -- --show-inlined-functions ``` > 📝 **Note** diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 016b18edac..191b736d05 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -72,7 +72,7 @@ This section shows how to export your private key from specific wallets. To import an account into the file holding the accounts info (`~/.starknet_accounts/starknet_open_zeppelin_accounts.json` by default), use the `account import` command. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -88,7 +88,7 @@ $ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -103,7 +103,7 @@ Type in your private key and press enter: To import Argent account, set the `--type` flag to `argent`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_argent \ @@ -117,7 +117,7 @@ $ sncast \ To import Braavos account, set the `--type` flag to `braavos`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_braavos \ @@ -131,7 +131,7 @@ $ sncast \ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_oz \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index fbd12c5ab3..a018e2e292 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -23,7 +23,7 @@ Do the following to start interacting with the Starknet: #### Create account with the `sncast account create` command ```shell -$ sncast \ +sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name @@ -53,7 +53,7 @@ You can do it both by sending tokens from another starknet account or by bridgin #### Deploy account with the `sncast account deploy` command ```shell -$ sncast \ +sncast \ account deploy \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -80,7 +80,7 @@ If you created an account with `sncast account create` it by default it will be To import an account to the `default accounts file`, use the `account import` command. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name my_imported_account \ @@ -93,7 +93,7 @@ $ sncast \ List all accounts saved in `accounts file`, grouped based on the networks they are defined on. ```shell -$ sncast account list +sncast account list ``` ``` @@ -118,7 +118,7 @@ There is also possibility to show private keys with the `--display-private-keys` Delete an account from `accounts-file` and its associated Scarb profile. If you pass this command, you will be asked to confirm the deletion. ```shell -$ sncast account delete \ +sncast account delete \ --name some-name \ --network alpha-sepolia ``` @@ -132,7 +132,7 @@ It is possible to create an account using custom openzeppelin, argent or braavos with `--class-hash` flag: ```shell -$ sncast \ +sncast \ account create \ --name some-name \ --url http://127.0.0.1:5050 \ @@ -144,7 +144,7 @@ $ sncast \ Instead of random generation, salt can be specified with `--salt`. ```shell -$ sncast \ +sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -173,7 +173,7 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. ```shell -$ sncast \ +sncast \ --keystore keystore.json \ --account account.json \ declare \ @@ -187,7 +187,7 @@ $ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. ```shell -$ sncast \ +sncast \ --keystore my_key.json \ --account my_account.json \ account create \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 1656ee0d3b..e2bde8e27d 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -17,16 +17,21 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ### General Example ```shell -$ sncast \ - call \ - --url http://127.0.0.1:5050 \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 +``` + +
+Click to expand output +```shell command: call response: [0x1, 0x23, 0x4] ``` +
+
> 📝 **Note** > Call does not require passing account-connected parameters (`account` and `accounts-file`) because it doesn't create a transaction. @@ -36,12 +41,18 @@ response: [0x1, 0x23, 0x4] You can call a contract at the specific block by passing `--block-id` argument. ```shell -$ sncast call \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 \ - --block-id 1234 + --block-id 1234``` +``` + +
+Click to expand output +```shell command: call response: [0x1, 0x23] ``` +
diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index a3095d1c9d..8407b0dcf6 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -53,7 +53,7 @@ pub mod DataTransformerContract { A default form of calldata passed to commands requiring it is a series of hex-encoded felts: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -79,7 +79,7 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 56244a76d6..377c4ff5c7 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -18,12 +18,17 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: ```shell -$ sncast --account myuser \ +sncast --account myuser \ declare \ --url http://127.0.0.1:5050/rpc \ --fee-token strk \ --contract-name SimpleBalance +``` + +
+Click to expand output +```shell command: declare class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f @@ -32,6 +37,8 @@ To see declaration details, visit: class: https://starkscan.co/search/0x8448a68b5e... transaction: https://starkscan.co/search/0x7ad0d6e449... ``` +
+
> 📝 **Note** > Contract name is a part after the `mod` keyword in your contract file. It may differ from package name defined in `Scarb.toml` file. diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index ff2871767f..05da22a032 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -15,13 +15,18 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: ```shell -$ sncast \ +sncast \ --account myuser \ deploy \ --url http://127.0.0.1:5050/rpc \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +``` + +
+Click to expand output +```shell command: Deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e @@ -30,6 +35,8 @@ To see deployment details, visit: contract: https://starkscan.co/search/0x301316d47a... transaction: https://starkscan.co/search/0x64a62a0002... ``` +
+
> 💡 **Info** > Max fee will be automatically computed if `--max-fee ` is not passed. @@ -51,11 +58,16 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --constructor-calldata 0x1 0x1 0x0 - +``` + +
+Click to expand output + +```shell command: deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e @@ -64,6 +76,8 @@ To see deployment details, visit: contract: https://starkscan.co/search/0x301316d47a... transaction: https://starkscan.co/search/0x64a62a0002... ``` +
+
> 📝 **Note** > Although the constructor has only two params you have to pass more because u256 is serialized to two felts. @@ -75,11 +89,16 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --salt 0x123 - +``` + +
+Click to expand output + +```shell command: deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303bc transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e @@ -88,6 +107,8 @@ To see deployment details, visit: contract: https://starkscan.co/search/0x301316d47a... transaction: https://starkscan.co/search/0x64a62a0002... ``` +
+
### Passing `unique` Argument @@ -95,16 +116,22 @@ Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --unique +``` + +
+Click to expand output +```shell command: deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303aa -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e``` Details: contract: https://starkscan.co/search/0x301316d47a... transaction: https://starkscan.co/search/0x64a62a0002... ``` +
diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 918ec8374c..14ec1e4595 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -26,7 +26,7 @@ When deploying an account, you can specify the version of the transaction and th When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 @@ -34,7 +34,7 @@ $ sncast account deploy \ or set `--version` to `v3`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --version v3 \ --max-fee 9999999999999 @@ -43,7 +43,7 @@ $ sncast account deploy \ In case of paying in ETH, same rules apply. You need to set either `--fee-token` to `eth`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --fee-token eth \ --max-fee 9999999999999 @@ -52,11 +52,13 @@ $ sncast account deploy \ or set `--version` to `v1`: ```shell -$ sncast account deploy \ +```shell +sncast account deploy \ --name some-name \ --version v1 \ --max-fee 9999999999999 ``` + > 📝 **Note** > The unit used in `--max-fee` flag is the smallest unit of the given fee token. For ETH it is Wei, for STRK it is Fri. diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index 725b7a31e1..7ef9d33640 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -12,7 +12,7 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): ```shell -$ sncast +sncast ``` If `snfoundry.toml` is present and configured with `[sncast.default]`, `url`, `accounts-file` and `account` name will be taken from it. @@ -28,17 +28,24 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: ```shell -$ sncast --account myuser \ +sncast --account myuser \ call \ --url http://127.0.0.1:5050 \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ --calldata 0x0 \ --block-id latest +``` + +
+Click to expand output +```shell command: call response: [0x0] ``` +
+
> 📝 **Note** > In the above example we supply `sncast` with `--account` and `--url` flags. If `snfoundry.toml` is present, and have these properties set, values provided using these flags will override values from `snfoundry.toml`. Learn more about `snfoundry.toml` configuration [here](../projects/configuration.md#sncast). @@ -64,12 +71,17 @@ It is also possible to pass calldata in more friendly, human readable form thank Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. ```shell -$ sncast --account myuser \ +sncast --account myuser \ --wait \ deploy \ --url http://127.0.0.1:5050 \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +``` + +
+Click to expand output +```shell Transaction hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 Waiting for transaction to be received. Retries left: 11 Waiting for transaction to be received. Retries left: 10 @@ -84,12 +96,14 @@ Received transaction. Status: Pending Received transaction. Status: Pending command: deploy contract_address: 0x1d91599ec661e97fdcbb10c642a1c4f920986f1a7a9659d157d0db09baaa29e -transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 +transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983``` To see deployment details, visit: contract: https://starkscan.co/search/0x1d91599ec6... transaction: https://starkscan.co/search/0x3062310a1e... ``` +
+
As you can see command waited for the transaction until it was `ACCEPTED_ON_L2`. diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index bab2c4af56..088b5cb367 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -17,7 +17,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example ```shell -$ sncast \ +sncast \ --account example_user \ invoke \ --url http://127.0.0.1:5050 \ @@ -25,13 +25,20 @@ $ sncast \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 0x1e +``` + +
+Click to expand output +```shell command: invoke transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f To see invocation details, visit: transaction: https://starkscan.co/tx/0x7ad0d6e449... ``` +
+
> 💡 **Info** > Max fee will be automatically computed if `--max-fee ` is not passed. @@ -44,14 +51,20 @@ transaction: https://starkscan.co/tx/0x7ad0d6e449... Not every function accepts parameters. Here is how to call it. ```shell -$ sncast invoke \ +sncast invoke \ --fee-token strk \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "function_without_params" +``` + +
+Click to expand output +```shell command: invoke transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f To see invocation details, visit: transaction: https://starkscan.co/tx/0x7ad0d6e449... ``` +
diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 53c112fe33..d124208278 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -47,14 +47,21 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. ```shell -$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +``` + +
+Click to expand output +```shell command: multicall transaction_hash: 0x38fb8a0432f71bf2dae746a1b4f159a75a862e253002b48599c9611fa271dcb To see invocation details, visit: transaction: https://starkscan.co/tx/0x38fb8a0432... ``` +
+
> 💡 **Info** > Max fee will be automatically computed if `--max-fee ` is not passed. @@ -67,10 +74,17 @@ transaction: https://starkscan.co/tx/0x38fb8a0432... You can also generate multicall template with `multicall new` command, specifying output path. ```shell -$ sncast multicall new ./template.toml +sncast multicall new ./template.toml +``` + +
+Click to expand output +```shell Multicall template successfully saved in ./template.toml ``` +
+
Resulting in output: ```toml @@ -96,7 +110,13 @@ inputs = [] If there is a file with the same name as provided, it can be overwritten. ```shell -$ sncast multicall new ./template.toml --overwrite +sncast multicall new ./template.toml --overwrite +``` +
+Click to expand output + +```shell Multicall template successfully saved in ./new_multicall_template.toml ``` +
diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 90657121aa..1f6af75b50 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -67,7 +67,10 @@ Most common directory structures include: ### 1. `scripts` directory with all the scripts in the same workspace with cairo contracts (default for `sncast script init`) ```shell -$ tree +tree +``` + +```shell . ├── scripts │ └── my_script @@ -91,7 +94,10 @@ You can also have multiple scripts as separate packages, or multiple modules ins #### 1a. multiple scripts in one package ```shell -$ tree +tree +``` + +```shell . ├── scripts │ └── my_script @@ -109,7 +115,10 @@ $ tree #### 1b. multiple scripts as separate packages ```shell -$ tree +tree +``` + +```shell . ├── scripts │ ├── Scarb.toml @@ -132,7 +141,10 @@ $ tree #### 1c. single script with flat directory structure ```shell -$ tree +tree +``` + +```shell . ├── Scarb.toml ├── scripts @@ -147,7 +159,10 @@ $ tree ### 2. scripts disjointed from the workspace with cairo contracts ```shell -$ tree +tree +``` + +```shell . ├── Scarb.toml └── src @@ -167,7 +182,7 @@ This setup can be seen in action in [Full Example below](#full-example-with-cont To get started, a deployment script with all required elements can be initialized using the following command: ```shell -$ sncast script init my_script +sncast script init my_script ``` For more details, see [init command](../appendix/sncast/script/init.md). @@ -187,7 +202,10 @@ This example shows how to call an already deployed contract. Please find full ex The script should be included in a Scarb package. The directory structure and config for this example looks like this: ```shell -$ tree +tree +``` + +```shell . ├── src │ ├── my_script.cairo @@ -208,14 +226,20 @@ sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = To run the script, do: ```shell -$ sncast \ +sncast \ script run my_script --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 +``` + +
+Click to expand output +```shell CallResult { data: [0, 96231036770510887841935600920878740513, 16] } command: script run status: success ``` +
### Full Example (With Contract Deployment) @@ -234,7 +258,10 @@ We prepare a script: The script should be included in a Scarb package. The directory structure and config for this example looks like this: ```shell -$ tree +tree +``` + +```shell . ├── contracts │ ├── Scarb.toml @@ -272,11 +299,16 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 +``` + +
+Click to expand output +```shell Class hash of the declared contract: 685896493695476540388232336434993540241192267040651919145140488413686992233 ... Deployed the contract to address: 2993684914933159551622723238457226804366654523161908704282792530334498925876 @@ -287,16 +319,23 @@ Call result: [2] command: script run status: success ``` +
+
As [an idempotency](#state-file) feature is turned on by default, executing the same script once again ends with a success and only `call` functions are being executed (as they do not change the network state): ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 +``` +
+Click to expand output + +```shell Class hash of the declared contract: 1922774777685257258886771026518018305931014651657879651971507142160195873652 Deployed the contract to address: 3478557462226312644848472512920965457566154264259286784215363579593349825684 Invoke tx hash is: 1373185562410761200747829131886166680837022579434823960660735040169785115611 @@ -304,22 +343,32 @@ Call result: [2] command: script run status: success ``` +
+
+ whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already declared): ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 \ --no-state-file +``` +
+Click to expand output + +```shell command: script run message: 0x636f6e747261637420616c7265616479206465636c61726564 ('contract already declared') status: script panicked ``` +
+
## Error handling diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index 4e5b6852a6..ea7a8f8629 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -14,14 +14,21 @@ replace any subcommand (and its parameters) with `show-config` and it will show ### General Example ```shell -$ sncast \ +sncast \ --account user1 \ show-config \ --url http://127.0.0.1:5050 +``` +
+Click to expand output + +```shell command: show-config account: user1 chain_id: alpha-sepolia keystore: ../keystore rpc_url: http://127.0.0.1:5050/rpc -``` \ No newline at end of file +``` +
+
\ No newline at end of file diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 86a967190d..56781ff389 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -13,13 +13,18 @@ For a detailed CLI description, refer to the [tx-status command reference](../ap You can track the details about the execution and finality status of a transaction in the given network by using the transaction hash as shown below: ```shell -$ sncast \ +sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ --url http://127.0.0.1:5050 +``` + +
+Click to expand output +```shell command: tx-status execution_status: Succeeded finality_status: AcceptedOnL2 ``` - +
diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index a0dc9850ff..0a751d8f7c 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -24,18 +24,25 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: ```shell -$ sncast \ +sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ --contract-name SimpleBalance \ --verifier walnut \ --network sepolia +``` + +
+Click to expand output +```shell You are about to submit the entire workspace's code to the third-party chosen verifier at walnut, and the code will be publicly available through walnut's APIs. Are you sure? (Y/n) Y command: verify message: Contract verification has started. You can check the verification status at the following link: https://api.walnut.dev/v1/verification/77f1d905-fdb4-4280-b7d6-57cd029d1259/status. ``` +
+
> 📝 **Note** > Contract name is a part after the `mod` keyword in your contract file. It may differ from package name defined in `Scarb.toml` file. diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index e244ff6bf0..bfd20a6dc6 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -39,13 +39,21 @@ Let's write a test that will deploy the `HelloStarknet` contract and call some f > `HelloStarknet` contract has no constructor, so the calldata remains empty in the example above. ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from testing_smart_contracts package Running 0 test(s) from src/ Running 1 test(s) from tests/ [PASS] tests::call_and_invoke Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
## Handling Errors @@ -67,7 +75,13 @@ If we called this function in a test, it would result in a failure. ``` ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from testing_smart_contracts package Running 0 test(s) from src/ Running 1 test(s) from tests/ @@ -81,6 +95,8 @@ Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: tests::failing ``` +
+
### `SafeDispatcher` @@ -97,13 +113,21 @@ They allow using the contract without automatically unwrapping the result, which Now the test passes as expected. ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from package_name package Running 0 test(s) from src/ Running 1 test(s) from tests/ [PASS] tests::handling_errors Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
Similarly, you can handle the panics which use `ByteArray` as an argument (like an `assert!` or `panic!` macro) diff --git a/docs/src/testing/coverage.md b/docs/src/testing/coverage.md index 2804e29dde..0887517f35 100644 --- a/docs/src/testing/coverage.md +++ b/docs/src/testing/coverage.md @@ -31,7 +31,7 @@ Usage details and limitations are also described there - make sure to check it o All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -$ snforge test --save-trace-data +snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -40,7 +40,7 @@ for the [cairo-coverage](https://github.com/software-mansion/cairo-coverage). If you want `snforge` to call `cairo-coverage` on generated files automatically, use [`--coverage`](../appendix/snforge/test.md#--coverage) flag: ```shell -$ snforge test --coverage +snforge test --coverage ``` This will generate a coverage report in the `coverage` directory named `coverage.lcov`. @@ -51,7 +51,7 @@ You can pass additional arguments to `cairo-coverage` by using the `--` separato to `cairo-coverage`: ```shell -$ snforge test --coverage -- --include macros +snforge test --coverage -- --include macros ``` > 📝 **Note** @@ -66,7 +66,7 @@ In this example we will use the `genhtml` tool from the [lcov package](https://g Run the following command in the directory containing your `coverage.lcov` file: ```shell -$ genhtml -o coverage_report coverage.lcov +genhtml -o coverage_report coverage.lcov ``` You can now open the `index.html` file in the `coverage_report` directory to see the generated coverage report. \ No newline at end of file diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index e5cb0eaaa2..11c3554f72 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -3,7 +3,13 @@ To run tests with `snforge`, simply run the `snforge test` command from the package directory. ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 3 test(s) from package_name package Running 3 test(s) from src/ [PASS] package_name::tests::executing @@ -11,6 +17,8 @@ Running 3 test(s) from src/ [PASS] package_name::tests::calling_another Tests: 3 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
## Filtering Tests @@ -19,13 +27,21 @@ By default, any test with an [absolute module tree path](https://book.cairo-lang matching the filter will be run. ```shell -$ snforge test calling +snforge test calling +``` + +
+Click to expand output + +```shell Collected 2 test(s) from package_name package Running 2 test(s) from src/ [PASS] package_name::tests::calling [PASS] package_name::tests::calling_another Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 1 filtered out ``` +
+
## Running a Specific Test @@ -38,19 +54,33 @@ Note, you have to use a fully qualified test name, including a module name. > ```shell -$ snforge test package_name::tests::calling --exact +snforge test package_name::tests::calling --exact +``` + +
+Click to expand output + +```shell Collected 1 test(s) from package_name package Running 1 test(s) from src/ [PASS] package_name::tests::calling Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out ``` +
+
## Stopping Test Execution After First Failed Test To stop the test execution after first failed test, you can pass an `--exit-first` flag along with `snforge test` command. ```shell -$ snforge test --exit-first +snforge test --exit-first +``` + +
+Click to expand output + +```shell Collected 6 test(s) from package_name package Running 6 test(s) from src/ [PASS] package_name::tests::executing @@ -66,13 +96,21 @@ Tests: 3 passed, 1 failed, 2 skipped, 0 ignored, 0 filtered out Failures: package_name::tests::failing ``` +
+
## Displaying Resources Used During Tests To track resources like `builtins` / `syscalls` that are used when running tests, use `snforge test --detailed-resources`. ```shell -$ snforge test --detailed-resources +snforge test --detailed-resources +``` + +
+Click to expand output + +```shell Collected 1 test(s) from package_name package Running 1 test(s) from src/ [PASS] package_name::tests::resources (gas: ~2213) @@ -83,5 +121,7 @@ Running 1 test(s) from src/ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
For more information about how starknet-foundry calculates those, see [gas and resource estimation](gas-and-resource-estimation.md) section. \ No newline at end of file diff --git a/docs/src/testing/test-collection.md b/docs/src/testing/test-collection.md index 920e75ac84..3e2feea487 100644 --- a/docs/src/testing/test-collection.md +++ b/docs/src/testing/test-collection.md @@ -24,7 +24,10 @@ then it is treated as an entrypoint to the `tests` package from which tests are For example, for a package structured this way: ```shell -$ tree . +tree . +``` + +```shell . ├── Scarb.toml ├── tests/ @@ -64,7 +67,10 @@ Then this virtual `lib.cairo` is treated as an entrypoint to the `tests` package For example, for a package structured this way: ```shell -$ tree . +tree . +``` + +```shell . ├── Scarb.toml ├── tests/ diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index b04c31b5c3..abf10c2013 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -11,7 +11,10 @@ When running `snforge test` in a Scarb workspace with a root package, it will on For a project structure like this ```shell -$ tree . -L 3 +tree . -L 3 +``` + +```shell . ├── Scarb.toml ├── crates @@ -30,21 +33,33 @@ $ tree . -L 3 only the tests in `./src` and `./tests` folders will be executed. - ```shell +snforge test +``` + +
+Click to expand output -$ snforge test +```shell Collected 1 test(s) from hello_workspaces package Running 1 test(s) from src/ [PASS] hello_workspaces::tests::test_simple Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
To select the specific package to test, pass a `--package package_name` (or `-p package_name` for short) flag. You can also run `snforge test` from the package directory to achieve the same effect. ```shell -$ snforge test --package addition +snforge test --package addition +``` + +
+Click to expand output + +```shell Collected 2 test(s) from addition package Running 1 test(s) from src/ [PASS] addition::tests::it_works @@ -52,11 +67,19 @@ Running 1 test(s) from tests/ [PASS] tests::test_simple::simple_case Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
You can also pass `--workspace` flag to run tests for all packages in the workspace. ```shell -$ snforge test --workspace +snforge test --workspace +``` + +
+Click to expand output + +```shell Collected 2 test(s) from addition package Running 1 test(s) from src/ [PASS] addition::tests::it_works @@ -76,6 +99,8 @@ Running 1 test(s) from src/ [PASS] hello_workspaces::tests::test_simple Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
`--package` and `--workspace` flags are mutually exclusive, adding both of them to a `snforge test` command will result in an error. diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index 17654dc639..1f2fe23a5d 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -19,12 +19,20 @@ You can find a detailed explanation of how `snforge` collects tests [here](test- Now run `snforge` using a command: ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from writing_tests package Running 1 test(s) from src/ [PASS] writing::first_test::tests::test_sum Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
## Failing Tests @@ -36,7 +44,13 @@ If your code panics, the test is considered failed. Here's an example of a faili ``` ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from writing_tests package Running 1 test(s) from src/ [FAIL] writing_tests::panicking_tests::tests::failing @@ -49,6 +63,8 @@ Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: writing_tests::panicking_tests::tests::failing ``` +
+
## Expected Failures @@ -75,15 +91,22 @@ With this format, the expected error message needs to be a substring of the actu {{#include ../../listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo:tuple}} ``` +```shell +snforge test +``` + +
+Click to expand output ```shell -$ snforge test Collected 1 test(s) from writing_tests package Running 0 test(s) from src/ Running 1 test(s) from tests/ [PASS] snforge_overview_integrationtest::should_panic_check_data Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
## Ignoring Tests @@ -95,13 +118,21 @@ You can achieve it using `#[ignore]` - tests marked with this attribute will be ``` ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from writing_tests package Running 0 test(s) from src/ Running 1 test(s) from tests/ [IGNORE] writing_tests_integrationtest::ignoring::ignored_test 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`. diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index 563a646568..242a4b75cb 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -38,7 +38,13 @@ We can try to create a test that will increase and verify the balance. This test fails, which means that `increase_balance` method panics as we expected. ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from using_cheatcodes package Running 1 test(s) from tests/ [FAIL] using_cheatcodes_tests::caller_address::failing::call_and_invoke @@ -48,6 +54,8 @@ Failure data: Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
Our user validation is not letting us call the contract, because the default caller address is not `123`. @@ -66,13 +74,21 @@ address, so it passes our validation. The test will now pass without an error ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from using_cheatcodes package Running 0 test(s) from src/ Running 1 test(s) from tests/ [PASS] using_cheatcodes_integrationtest::caller_address::proper_use::call_and_invoke (gas: ~239) Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ``` +
+
### Canceling the Cheat @@ -88,7 +104,13 @@ We will demonstrate its behavior using `SafeDispatcher` to show when exactly the ``` ```shell -$ snforge test +snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from using_cheatcodes package Running 0 test(s) from src/ Running 1 test(s) from tests/ @@ -99,6 +121,8 @@ Failure data: Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 4 filtered out ``` +
+
We see that the second `increase_balance` fails since we cancelled the cheatcode. From f8b005875db8985212210b5d162e492af4d852cd Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sat, 9 Nov 2024 23:34:59 +0100 Subject: [PATCH 002/183] Change shell snippets to expandable blocks --- docs/src/getting-started/first-steps.md | 19 ++++++++ docs/src/projects/configuration.md | 14 ++++++ .../snforge-advanced-features/fuzz-testing.md | 8 ++++ docs/src/starknet/account-import.md | 7 +++ docs/src/starknet/account.md | 7 +++ docs/src/starknet/calldata-transformation.md | 46 +++++++++---------- docs/src/starknet/fees-and-versions.md | 1 - .../testing/gas-and-resource-estimation.md | 12 ++++- 8 files changed, 89 insertions(+), 25 deletions(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index ac90aa9090..3c9931ef9d 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -14,6 +14,9 @@ Let's check out the project structure ```shell cd project_name tree . -L 1 +``` + +```shell . ├── Scarb.lock ├── Scarb.toml @@ -32,6 +35,12 @@ And run tests with `snforge test` ```shell snforge test +``` + +
+Click to expand output + +```shell Compiling project_name v0.1.0 (project_name/Scarb.toml) Finished release target(s) in 1 second @@ -42,6 +51,8 @@ Running 2 test(s) from tests/ [PASS] tests::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~104) Tests: 2 passed, 0 failed, 0 skipped, 0 ignored ``` +
+
## Using `snforge` With Existing Scarb Projects @@ -61,8 +72,16 @@ Make sure that the version in `tag` matches `snforge`. You can check the current ```shell snforge --version +``` + +
+Click to expand + +```shell snforge 0.27.0 ``` +
+
It is also possible to add this dependency using [`scarb add`](https://docs.swmansion.com/scarb/docs/guides/dependencies.html#adding-a-dependency-via-scarb-add) diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 73846c06a5..19c2eaf906 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -56,10 +56,17 @@ sncast --profile myprofile \ --function get \ --calldata 0x0 \ --block-id latest +``` + +
+Click to expand output +```shell command: call response: [0x0] ``` +
+
### Multiple Profiles @@ -86,10 +93,17 @@ sncast call \ --function get \ --calldata 0x0 \ --block-id latest +``` + +
+Click to expand output +```shell command: call response: [0x1, 0x23, 0x4] ``` +
+
## Environmental variables diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index a2e1070b78..fc86bab808 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -24,6 +24,12 @@ Then run `snforge test` like usual. ```shell snforge test +``` + +
+Click to expand output + +```shell Collected 1 test(s) from fuzz_testing package Running 1 test(s) from src/ Running 0 test(s) from tests/ @@ -31,6 +37,8 @@ Running 0 test(s) from tests/ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out Fuzzer seed: [..] ``` +
+
## Types Supported by the Fuzzer diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 191b736d05..acb89b2ebe 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -94,9 +94,16 @@ sncast \ --name account_123 \ --address 0x1 \ --type oz +``` + +
+Click to expand output +```shell Type in your private key and press enter: ``` +
+
#### Argent diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index a018e2e292..598c57a866 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -27,7 +27,12 @@ sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name +``` + +
+Click to expand output +```shell command: account create add_profile: --add-profile flag was not set. No profile added to snfoundry.toml address: 0x34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b @@ -37,6 +42,8 @@ message: Account successfully created. Prefund generated address with at least < To see account creation details, visit: account: https://starkscan.co/search/contract/34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b ``` +
+
For a detailed CLI description, see [account create command reference](../appendix/sncast/account/create.md). diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 8407b0dcf6..a9ad0791ce 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -123,12 +123,12 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: - ```shell - $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ - --function complex_fn \ - --arguments \ +```shell +sncast call \ + --url http://127.0.0.1:5050 \ + --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --function complex_fn \ + --arguments \ 'array![array![1, 2], array![3, 4, 5], array![6]],'\ '12,'\ '-128_i8,'\ @@ -136,8 +136,8 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie "('a shortstring', 32_u32),"\ 'true,'\ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' \ - --block-id latest - ``` + --block-id latest +``` > 📝 **Note** > In bash and similar shells indentation and whitespace matters when providing multiline strings with `\` @@ -146,20 +146,20 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie Alternatively, you can continue the single quote for multiple lines. - ```shell - $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ - --function complex_fn \ - --arguments 'array![array![1, 2], array![3, 4, 5], array![6]], +```shell +sncast call \ + --url http://127.0.0.1:5050 \ + --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --function complex_fn \ + --arguments 'array![array![1, 2], array![3, 4, 5], array![6]], 12, -128_i8, "Some string (a ByteArray)", ('\''a shortstring'\'', 32_u32), true, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' \ - --block-id latest - ``` + --block-id latest +``` > 📝 **Note** > In bash and similar shells any `'` must be escaped correctly. @@ -168,15 +168,15 @@ true, 2. `nested_struct_fn` - struct nesting: - ```shell - $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ - --function nested_struct_fn \ - --arguments \ +```shell +sncast call \ + --url http://127.0.0.1:5050 \ + --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --function nested_struct_fn \ + --arguments \ 'data_transformer_contract::NestedStructWithField {'\ ' a: data_transformer_contract::SimpleStruct { a: 10 },'\ ' b: 12'\ '}'\ --block-id latest - ``` +``` diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 14ec1e4595..eeb9854c2a 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -51,7 +51,6 @@ sncast account deploy \ or set `--version` to `v1`: -```shell ```shell sncast account deploy \ --name some-name \ diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 6670873345..33d6460bbf 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -35,8 +35,15 @@ It is possible to enable more detailed breakdown of resources, on which the gas ### Usage In order to run tests with this feature, run the `test` command with the appropriate flag: + +```shell +snforge test --detailed-resources +``` + +
+Click to expand output + ```shell -$ snforge test --detailed-resources ... [PASS] package_name::tests::resources (gas: ~2213) steps: 881 @@ -45,6 +52,9 @@ $ snforge test --detailed-resources syscalls: (StorageWrite: 1, StorageRead: 1, CallContract: 1) ... ``` +
+
+ This displays the resources used by the VM during the test execution. ## Analyzing the results From 4e457117edb7a01fb2ffd1e3bb28f9b5ebcb0ce3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 13:32:15 +0100 Subject: [PATCH 003/183] Make expandable snippet open by default --- crates/sncast/README.md | 85 ++++++++++++++++--- .../parametrizing_tests_with_fixed_values.md | 2 +- docs/src/development/environment-setup.md | 7 +- docs/src/getting-started/first-steps.md | 4 +- docs/src/projects/configuration.md | 8 +- .../snforge-advanced-features/fuzz-testing.md | 4 +- docs/src/starknet/account-import.md | 4 +- docs/src/starknet/account.md | 4 +- docs/src/starknet/call.md | 8 +- docs/src/starknet/declare.md | 4 +- docs/src/starknet/deploy.md | 16 ++-- docs/src/starknet/index.md | 8 +- docs/src/starknet/invoke.md | 8 +- docs/src/starknet/multicall.md | 12 +-- docs/src/starknet/script.md | 16 ++-- docs/src/starknet/show_config.md | 4 +- docs/src/starknet/tx-status.md | 4 +- docs/src/starknet/verify.md | 4 +- docs/src/testing/contracts.md | 12 +-- .../testing/gas-and-resource-estimation.md | 4 +- docs/src/testing/running-tests.md | 20 ++--- docs/src/testing/testing-workspaces.md | 12 +-- docs/src/testing/testing.md | 16 ++-- docs/src/testing/using-cheatcodes.md | 12 +-- 24 files changed, 170 insertions(+), 108 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 0b92258188..ec586d5dc2 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,104 +32,159 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract ```shell -$ sncast --account myuser \ +sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ declare \ --contract-name SimpleBalance +``` + +
+Output: +```shell command: Declare class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f ``` - +
+
With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast declare \ +sncast declare \ --contract-name SimpleBalance +``` + +
+Output: +```shell command: Declare class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f ``` +
+
+ ### Deploy a contract ```shell -$ sncast --account myuser \ +sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +``` + +
+Output: +```shell command: Deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e ``` - +
+
With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +``` + +
+Output: +```shell command: Deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e ``` +
+
### Invoke a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +sncast --url http://127.0.0.1:5050 \ --account example_user \ invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 +``` +
+Output: + +```shell command: Invoke transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f ``` +
+
With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast invoke \ +sncast invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 +``` + +
+Output: +```shell command: Invoke transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f ``` +
+
### Call a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +sncast --url http://127.0.0.1:5050 \ call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 +``` +
+Output: + +```shell command: call response: [0x0] ``` +
+
With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast call \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function some_function \ --calldata 1 2 3 +``` + +
+Output: +```shell command: call response: [0x0] ``` +
+
## Development @@ -140,8 +195,16 @@ Please make sure you're using scarb installed via asdf - otherwise some tests ma To verify, run: ```shell -$ which scarb +which scarb +``` + +
+Output: + +```shell $HOME/.asdf/shims/scarb ``` +
+
If you previously installed scarb using official installer, you may need to remove this installation or modify your PATH to make sure asdf installed one is always used. diff --git a/design_documents/parametrizing_tests_with_fixed_values.md b/design_documents/parametrizing_tests_with_fixed_values.md index 8e5d26a407..fa3a0c7467 100644 --- a/design_documents/parametrizing_tests_with_fixed_values.md +++ b/design_documents/parametrizing_tests_with_fixed_values.md @@ -119,7 +119,7 @@ If a test case has a custom name, it should be displayed to the user. An example output could look similarly to this: ```shell -$ snforge test +snforge test [PASS] tests::parametrized(a = 1, b = 2) # unnamed test case [PASS] tests::parametrized[a_test](a = 3, b = 5) # named test case [FAIL] tests::parametrized[my_case](a = 4, b = 5) # named test case diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index 0d9aa26320..1767fbebdf 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -91,12 +91,11 @@ typos Some typos can be automatically fixed by running``` -
-Click to expand output +
+Output: ```shell -```shell -$ typos -w +typos -w ```
diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 3c9931ef9d..6c79e2b2e9 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -37,8 +37,8 @@ And run tests with `snforge test` snforge test ``` -
-Click to expand output +
+Output: ```shell Compiling project_name v0.1.0 (project_name/Scarb.toml) diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 19c2eaf906..41aa0a089c 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -58,8 +58,8 @@ sncast --profile myprofile \ --block-id latest ``` -
-Click to expand output +
+Output: ```shell command: call @@ -95,8 +95,8 @@ sncast call \ --block-id latest ``` -
-Click to expand output +
+Output: ```shell command: call diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index fc86bab808..d6faf359c3 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -26,8 +26,8 @@ Then run `snforge test` like usual. snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from fuzz_testing package diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index acb89b2ebe..1d712cdb7b 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -96,8 +96,8 @@ sncast \ --type oz ``` -
-Click to expand output +
+Output: ```shell Type in your private key and press enter: diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 598c57a866..4d84f9dbbb 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -29,8 +29,8 @@ sncast \ --name some-name ``` -
-Click to expand output +
+Output: ```shell command: account create diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index e2bde8e27d..21aa6672fa 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -23,8 +23,8 @@ sncast call \ --calldata 1 2 3 ``` -
-Click to expand output +
+Output: ```shell command: call @@ -48,8 +48,8 @@ sncast call \ --block-id 1234``` ``` -
-Click to expand output +
+Output: ```shell command: call diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 377c4ff5c7..440b88338b 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -25,8 +25,8 @@ sncast --account myuser \ --contract-name SimpleBalance ``` -
-Click to expand output +
+Output: ```shell command: declare diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 05da22a032..73402fa3b7 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -23,8 +23,8 @@ sncast \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ``` -
-Click to expand output +
+Output: ```shell command: Deploy @@ -64,8 +64,8 @@ sncast deploy \ --constructor-calldata 0x1 0x1 0x0 ``` -
-Click to expand output +
+Output: ```shell command: deploy @@ -95,8 +95,8 @@ sncast deploy \ --salt 0x123 ``` -
-Click to expand output +
+Output: ```shell command: deploy @@ -122,8 +122,8 @@ sncast deploy \ --unique ``` -
-Click to expand output +
+Output: ```shell command: deploy diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index 7ef9d33640..d4c5dc8804 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -37,8 +37,8 @@ sncast --account myuser \ --block-id latest ``` -
-Click to expand output +
+Output: ```shell command: call @@ -78,8 +78,8 @@ sncast --account myuser \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ``` -
-Click to expand output +
+Output: ```shell Transaction hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 088b5cb367..7c0c3307d8 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -27,8 +27,8 @@ sncast \ --calldata 1 2 0x1e ``` -
-Click to expand output +
+Output: ```shell command: invoke @@ -57,8 +57,8 @@ sncast invoke \ --function "function_without_params" ``` -
-Click to expand output +
+Output: ```shell command: invoke diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index d124208278..fc8536091b 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -50,8 +50,8 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk ``` -
-Click to expand output +
+Output: ```shell command: multicall @@ -77,8 +77,8 @@ You can also generate multicall template with `multicall new` command, specifyin sncast multicall new ./template.toml ``` -
-Click to expand output +
+Output: ```shell Multicall template successfully saved in ./template.toml @@ -113,8 +113,8 @@ If there is a file with the same name as provided, it can be overwritten. sncast multicall new ./template.toml --overwrite ``` -
-Click to expand output +
+Output: ```shell Multicall template successfully saved in ./new_multicall_template.toml diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 1f6af75b50..6aaa90e8f7 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -231,8 +231,8 @@ sncast \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` -
-Click to expand output +
+Output: ```shell CallResult { data: [0, 96231036770510887841935600920878740513, 16] } @@ -305,8 +305,8 @@ sncast \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` -
-Click to expand output +
+Output: ```shell Class hash of the declared contract: 685896493695476540388232336434993540241192267040651919145140488413686992233 @@ -332,8 +332,8 @@ sncast \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` -
-Click to expand output +
+Output: ```shell Class hash of the declared contract: 1922774777685257258886771026518018305931014651657879651971507142160195873652 @@ -357,8 +357,8 @@ sncast \ --no-state-file ``` -
-Click to expand output +
+Output: ```shell command: script run diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index ea7a8f8629..378dfc50af 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -20,8 +20,8 @@ sncast \ --url http://127.0.0.1:5050 ``` -
-Click to expand output +
+Output: ```shell command: show-config diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 56781ff389..2382e09a98 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -19,8 +19,8 @@ sncast \ --url http://127.0.0.1:5050 ``` -
-Click to expand output +
+Output: ```shell command: tx-status diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 0a751d8f7c..011d41db59 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -32,8 +32,8 @@ sncast \ --network sepolia ``` -
-Click to expand output +
+Output: ```shell You are about to submit the entire workspace's code to the third-party chosen verifier at walnut, and the code will be publicly available through walnut's APIs. Are you sure? (Y/n) Y diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index bfd20a6dc6..e730240365 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -42,8 +42,8 @@ Let's write a test that will deploy the `HelloStarknet` contract and call some f snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from testing_smart_contracts package @@ -78,8 +78,8 @@ If we called this function in a test, it would result in a failure. snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from testing_smart_contracts package @@ -116,8 +116,8 @@ Now the test passes as expected. snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from package_name package diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 33d6460bbf..26294c9b81 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -40,8 +40,8 @@ In order to run tests with this feature, run the `test` command with the appropr snforge test --detailed-resources ``` -
-Click to expand output +
+Output: ```shell ... diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index 11c3554f72..a0772c45a6 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -6,8 +6,8 @@ To run tests with `snforge`, simply run the `snforge test` command from the pack snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 3 test(s) from package_name package @@ -30,8 +30,8 @@ By default, any test with an [absolute module tree path](https://book.cairo-lang snforge test calling ``` -
-Click to expand output +
+Output: ```shell Collected 2 test(s) from package_name package @@ -57,8 +57,8 @@ Note, you have to use a fully qualified test name, including a module name. snforge test package_name::tests::calling --exact ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from package_name package @@ -77,8 +77,8 @@ To stop the test execution after first failed test, you can pass an `--exit-firs snforge test --exit-first ``` -
-Click to expand output +
+Output: ```shell Collected 6 test(s) from package_name package @@ -107,8 +107,8 @@ To track resources like `builtins` / `syscalls` that are used when running tests snforge test --detailed-resources ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from package_name package diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index abf10c2013..437f23c877 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -37,8 +37,8 @@ only the tests in `./src` and `./tests` folders will be executed. snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from hello_workspaces package @@ -56,8 +56,8 @@ You can also run `snforge test` from the package directory to achieve the same e snforge test --package addition ``` -
-Click to expand output +
+Output: ```shell Collected 2 test(s) from addition package @@ -76,8 +76,8 @@ You can also pass `--workspace` flag to run tests for all packages in the worksp snforge test --workspace ``` -
-Click to expand output +
+Output: ```shell Collected 2 test(s) from addition package diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index 1f2fe23a5d..313badb971 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -22,8 +22,8 @@ Now run `snforge` using a command: snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from writing_tests package @@ -47,8 +47,8 @@ If your code panics, the test is considered failed. Here's an example of a faili snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from writing_tests package @@ -95,8 +95,8 @@ With this format, the expected error message needs to be a substring of the actu snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from writing_tests package @@ -121,8 +121,8 @@ You can achieve it using `#[ignore]` - tests marked with this attribute will be snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from writing_tests package diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index 242a4b75cb..ebd23f967a 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -41,8 +41,8 @@ This test fails, which means that `increase_balance` method panics as we expecte snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from using_cheatcodes package @@ -77,8 +77,8 @@ The test will now pass without an error snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from using_cheatcodes package @@ -107,8 +107,8 @@ We will demonstrate its behavior using `SafeDispatcher` to show when exactly the snforge test ``` -
-Click to expand output +
+Output: ```shell Collected 1 test(s) from using_cheatcodes package From 23493ab1ffe15b3adbb642b0cf5eb6b37821b17d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 13:35:09 +0100 Subject: [PATCH 004/183] Make `tree` commands expandable --- docs/src/starknet/script.md | 35 ++++++++++++++++++++++++++ docs/src/testing/test-collection.md | 10 ++++++++ docs/src/testing/testing-workspaces.md | 5 ++++ 3 files changed, 50 insertions(+) diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 6aaa90e8f7..24377a878a 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -70,6 +70,9 @@ Most common directory structures include: tree ``` +
+Output: + ```shell . ├── scripts @@ -83,6 +86,8 @@ tree │ └── lib.cairo └── Scarb.toml ``` +
+
> 📝 **Note** > You should add `scripts` to `members` field in your top-level Scarb.toml to be able to run the script from @@ -97,6 +102,9 @@ You can also have multiple scripts as separate packages, or multiple modules ins tree ``` +
+Output: + ```shell . ├── scripts @@ -111,6 +119,8 @@ tree │ └── lib.cairo └── Scarb.toml ``` +
+
#### 1b. multiple scripts as separate packages @@ -118,6 +128,9 @@ tree tree ``` +
+Output: + ```shell . ├── scripts @@ -137,6 +150,8 @@ tree │ └── lib.cairo └── Scarb.toml ``` +
+
#### 1c. single script with flat directory structure @@ -144,6 +159,9 @@ tree tree ``` +
+Output: + ```shell . ├── Scarb.toml @@ -155,6 +173,8 @@ tree └── src └── lib.cairo ``` +
+
### 2. scripts disjointed from the workspace with cairo contracts @@ -162,6 +182,9 @@ tree tree ``` +
+Output: + ```shell . ├── Scarb.toml @@ -169,6 +192,8 @@ tree ├── lib.cairo └── my_script.cairo ``` +
+
In order to use this directory structure you must set any contracts you're using as dependencies in script's Scarb.toml, and override `build-external-contracts` property to build those contracts. To learn more consult [Scarb documentation](https://docs.swmansion.com/scarb/docs/extensions/starknet/contract-target.html#compiling-external-contracts). @@ -205,6 +230,9 @@ The script should be included in a Scarb package. The directory structure and co tree ``` +
+Output: + ```shell . ├── src @@ -212,6 +240,8 @@ tree │ └── lib.cairo └── Scarb.toml ``` +
+
```toml [package] @@ -261,6 +291,9 @@ The script should be included in a Scarb package. The directory structure and co tree ``` +
+Output: + ```shell . ├── contracts @@ -273,6 +306,8 @@ tree ├── lib.cairo └── map_script.cairo ``` +
+
```toml [package] diff --git a/docs/src/testing/test-collection.md b/docs/src/testing/test-collection.md index 3e2feea487..178496755e 100644 --- a/docs/src/testing/test-collection.md +++ b/docs/src/testing/test-collection.md @@ -27,6 +27,9 @@ For example, for a package structured this way: tree . ``` +
+Output: + ```shell . ├── Scarb.toml @@ -40,6 +43,8 @@ tree . └── src/ └── lib.cairo ``` +
+
with `tests/lib.cairo` content: @@ -70,6 +75,9 @@ For example, for a package structured this way: tree . ``` +
+Output: + ```shell . ├── Scarb.toml @@ -83,6 +91,8 @@ tree . └── src/ └── lib.cairo ``` +
+
and `tests/common.cairo` content: diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index 437f23c877..f4ad22f440 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -14,6 +14,9 @@ For a project structure like this tree . -L 3 ``` +
+Output: + ```shell . ├── Scarb.toml @@ -30,6 +33,8 @@ tree . -L 3 └── src └── lib.cairo ``` +
+
only the tests in `./src` and `./tests` folders will be executed. From 62bb35a35342235cf7a7ce2235e612be84464f3f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 14:46:12 +0100 Subject: [PATCH 005/183] Restore prompt in shell snippets --- crates/sncast/README.md | 18 +++++++++--------- .../parametrizing_tests_with_fixed_values.md | 2 +- docs/src/getting-started/first-steps.md | 8 ++++---- docs/src/getting-started/installation.md | 2 +- docs/src/projects/configuration.md | 4 ++-- .../snforge-advanced-features/fuzz-testing.md | 4 ++-- .../src/snforge-advanced-features/profiling.md | 6 +++--- docs/src/starknet/account-import.md | 10 +++++----- docs/src/starknet/account.md | 18 +++++++++--------- docs/src/starknet/call.md | 4 ++-- docs/src/starknet/calldata-transformation.md | 10 +++++----- docs/src/starknet/declare.md | 2 +- docs/src/starknet/deploy.md | 8 ++++---- docs/src/starknet/fees-and-versions.md | 8 ++++---- docs/src/starknet/index.md | 6 +++--- docs/src/starknet/invoke.md | 4 ++-- docs/src/starknet/multicall.md | 6 +++--- docs/src/starknet/script.md | 10 +++++----- docs/src/starknet/show_config.md | 2 +- docs/src/starknet/tx-status.md | 2 +- docs/src/starknet/verify.md | 2 +- docs/src/testing/contracts.md | 6 +++--- docs/src/testing/coverage.md | 6 +++--- .../src/testing/gas-and-resource-estimation.md | 2 +- docs/src/testing/running-tests.md | 10 +++++----- docs/src/testing/testing-workspaces.md | 6 +++--- docs/src/testing/testing.md | 8 ++++---- docs/src/testing/using-cheatcodes.md | 6 +++--- 28 files changed, 90 insertions(+), 90 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index ec586d5dc2..3165eeadf5 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,7 +32,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract ```shell -sncast --account myuser \ +$ sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ declare \ --contract-name SimpleBalance @@ -52,7 +52,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast declare \ +$ sncast declare \ --contract-name SimpleBalance ``` @@ -71,7 +71,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Deploy a contract ```shell -sncast --account myuser \ +$ sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ``` @@ -90,7 +90,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ```
@@ -108,7 +108,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract ```shell -sncast --url http://127.0.0.1:5050 \ +$ sncast --url http://127.0.0.1:5050 \ --account example_user \ invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ @@ -130,7 +130,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast invoke \ +$ sncast invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -149,7 +149,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Call a contract ```shell -sncast --url http://127.0.0.1:5050 \ +$ sncast --url http://127.0.0.1:5050 \ call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ @@ -170,7 +170,7 @@ response: [0x0] With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function some_function \ --calldata 1 2 3 @@ -195,7 +195,7 @@ Please make sure you're using scarb installed via asdf - otherwise some tests ma To verify, run: ```shell -which scarb +$ which scarb ```
diff --git a/design_documents/parametrizing_tests_with_fixed_values.md b/design_documents/parametrizing_tests_with_fixed_values.md index fa3a0c7467..8e5d26a407 100644 --- a/design_documents/parametrizing_tests_with_fixed_values.md +++ b/design_documents/parametrizing_tests_with_fixed_values.md @@ -119,7 +119,7 @@ If a test case has a custom name, it should be displayed to the user. An example output could look similarly to this: ```shell -snforge test +$ snforge test [PASS] tests::parametrized(a = 1, b = 2) # unnamed test case [PASS] tests::parametrized[a_test](a = 3, b = 5) # named test case [FAIL] tests::parametrized[my_case](a = 4, b = 5) # named test case diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 6c79e2b2e9..f0e74b8c35 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -6,7 +6,7 @@ We demonstrate how to create a new project, compile, and test it. To start a new project with Starknet Foundry, run `snforge init` ```shell -snforge init project_name +$ snforge init project_name ``` Let's check out the project structure @@ -34,7 +34,7 @@ tree . -L 1 And run tests with `snforge test` ```shell -snforge test +$ snforge test ```
@@ -71,14 +71,14 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag Make sure that the version in `tag` matches `snforge`. You can check the currently installed version with ```shell -snforge --version +$ snforge --version ```
Click to expand ```shell -snforge 0.27.0 +$ snforge 0.27.0 ```

diff --git a/docs/src/getting-started/installation.md b/docs/src/getting-started/installation.md index b0d96f061f..6ff62d1841 100644 --- a/docs/src/getting-started/installation.md +++ b/docs/src/getting-started/installation.md @@ -81,7 +81,7 @@ As for now, Starknet Foundry on Windows needs manual installation, but necessary 4. Verify installation by running the following command in new terminal session: ```shell -snforge --version +$ snforge --version sncast --version ``` diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 41aa0a089c..18d74fbf7b 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -50,7 +50,7 @@ defined in the profile. > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. ```shell -sncast --profile myprofile \ +$ sncast --profile myprofile \ call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ @@ -88,7 +88,7 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. ```shell -sncast call \ +$ sncast call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ --calldata 0x0 \ diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index d6faf359c3..73326e1719 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -23,7 +23,7 @@ The test will be run many times against different randomly generated values. Then run `snforge test` like usual. ```shell -snforge test +$ snforge test ```
@@ -65,7 +65,7 @@ It is possible to configure the number of runs of the random fuzzer as well as i It can also be configured globally, via command line arguments: ```shell -snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 +$ snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 ``` Or in `Scarb.toml` file: diff --git a/docs/src/snforge-advanced-features/profiling.md b/docs/src/snforge-advanced-features/profiling.md index c9d641e6e3..e7fbc16fd8 100644 --- a/docs/src/snforge-advanced-features/profiling.md +++ b/docs/src/snforge-advanced-features/profiling.md @@ -9,7 +9,7 @@ You can inspect the call tree, see how many resources are used for different par All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -snforge test --save-trace-data +$ snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -18,7 +18,7 @@ for the [cairo-profiler](https://github.com/software-mansion/cairo-profiler). If you want `snforge` to call `cairo-profiler` on generated files automatically, use [`--build-profile`](../appendix/snforge/test.md#--build-profile) flag: ```shell -snforge test --build-profile +$ snforge test --build-profile ``` ## Passing arguments to `cairo-profiler` @@ -27,7 +27,7 @@ You can pass additional arguments to `cairo-profiler` by using the `--` separato to `cairo-profiler`: ```shell -snforge test --build-profile -- --show-inlined-functions +$ snforge test --build-profile -- --show-inlined-functions ``` > 📝 **Note** diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 1d712cdb7b..c316dc4be8 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -72,7 +72,7 @@ This section shows how to export your private key from specific wallets. To import an account into the file holding the accounts info (`~/.starknet_accounts/starknet_open_zeppelin_accounts.json` by default), use the `account import` command. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -88,7 +88,7 @@ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -110,7 +110,7 @@ Type in your private key and press enter: To import Argent account, set the `--type` flag to `argent`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_argent \ @@ -124,7 +124,7 @@ sncast \ To import Braavos account, set the `--type` flag to `braavos`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_braavos \ @@ -138,7 +138,7 @@ sncast \ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_oz \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 4d84f9dbbb..03b3cbf83a 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -23,7 +23,7 @@ Do the following to start interacting with the Starknet: #### Create account with the `sncast account create` command ```shell -sncast \ +$ sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name @@ -60,7 +60,7 @@ You can do it both by sending tokens from another starknet account or by bridgin #### Deploy account with the `sncast account deploy` command ```shell -sncast \ +$ sncast \ account deploy \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -87,7 +87,7 @@ If you created an account with `sncast account create` it by default it will be To import an account to the `default accounts file`, use the `account import` command. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name my_imported_account \ @@ -100,7 +100,7 @@ sncast \ List all accounts saved in `accounts file`, grouped based on the networks they are defined on. ```shell -sncast account list +$ sncast account list ``` ``` @@ -125,7 +125,7 @@ There is also possibility to show private keys with the `--display-private-keys` Delete an account from `accounts-file` and its associated Scarb profile. If you pass this command, you will be asked to confirm the deletion. ```shell -sncast account delete \ +$ sncast account delete \ --name some-name \ --network alpha-sepolia ``` @@ -139,7 +139,7 @@ It is possible to create an account using custom openzeppelin, argent or braavos with `--class-hash` flag: ```shell -sncast \ +$ sncast \ account create \ --name some-name \ --url http://127.0.0.1:5050 \ @@ -151,7 +151,7 @@ sncast \ Instead of random generation, salt can be specified with `--salt`. ```shell -sncast \ +$ sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -180,7 +180,7 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. ```shell -sncast \ +$ sncast \ --keystore keystore.json \ --account account.json \ declare \ @@ -194,7 +194,7 @@ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. ```shell -sncast \ +$ sncast \ --keystore my_key.json \ --account my_account.json \ account create \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 21aa6672fa..33bcee9184 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -17,7 +17,7 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ### General Example ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -41,7 +41,7 @@ response: [0x1, 0x23, 0x4] You can call a contract at the specific block by passing `--block-id` argument. ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index a9ad0791ce..52c8aea376 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -53,7 +53,7 @@ pub mod DataTransformerContract { A default form of calldata passed to commands requiring it is a series of hex-encoded felts: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -79,7 +79,7 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -124,7 +124,7 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -147,7 +147,7 @@ sncast call \ Alternatively, you can continue the single quote for multiple lines. ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -169,7 +169,7 @@ true, 2. `nested_struct_fn` - struct nesting: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function nested_struct_fn \ diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 440b88338b..e3cc81b6c9 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -18,7 +18,7 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: ```shell -sncast --account myuser \ +$ sncast --account myuser \ declare \ --url http://127.0.0.1:5050/rpc \ --fee-token strk \ diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 73402fa3b7..1caec3fd1f 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -15,7 +15,7 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: ```shell -sncast \ +$ sncast \ --account myuser \ deploy \ --url http://127.0.0.1:5050/rpc \ @@ -58,7 +58,7 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --constructor-calldata 0x1 0x1 0x0 @@ -89,7 +89,7 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --salt 0x123 @@ -116,7 +116,7 @@ Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --unique diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index eeb9854c2a..6c2fe7cb5a 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -26,7 +26,7 @@ When deploying an account, you can specify the version of the transaction and th When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 @@ -34,7 +34,7 @@ sncast account deploy \ or set `--version` to `v3`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --version v3 \ --max-fee 9999999999999 @@ -43,7 +43,7 @@ sncast account deploy \ In case of paying in ETH, same rules apply. You need to set either `--fee-token` to `eth`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --fee-token eth \ --max-fee 9999999999999 @@ -52,7 +52,7 @@ sncast account deploy \ or set `--version` to `v1`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --version v1 \ --max-fee 9999999999999 diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index d4c5dc8804..a746c9510d 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -12,7 +12,7 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): ```shell -sncast +$ sncast ``` If `snfoundry.toml` is present and configured with `[sncast.default]`, `url`, `accounts-file` and `account` name will be taken from it. @@ -28,7 +28,7 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: ```shell -sncast --account myuser \ +$ sncast --account myuser \ call \ --url http://127.0.0.1:5050 \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ @@ -71,7 +71,7 @@ It is also possible to pass calldata in more friendly, human readable form thank Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. ```shell -sncast --account myuser \ +$ sncast --account myuser \ --wait \ deploy \ --url http://127.0.0.1:5050 \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 7c0c3307d8..fad68d907f 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -17,7 +17,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example ```shell -sncast \ +$ sncast \ --account example_user \ invoke \ --url http://127.0.0.1:5050 \ @@ -51,7 +51,7 @@ transaction: https://starkscan.co/tx/0x7ad0d6e449... Not every function accepts parameters. Here is how to call it. ```shell -sncast invoke \ +$ sncast invoke \ --fee-token strk \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "function_without_params" diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index fc8536091b..04290a0599 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -47,7 +47,7 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. ```shell -sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk ```
@@ -74,7 +74,7 @@ transaction: https://starkscan.co/tx/0x38fb8a0432... You can also generate multicall template with `multicall new` command, specifying output path. ```shell -sncast multicall new ./template.toml +$ sncast multicall new ./template.toml ```
@@ -110,7 +110,7 @@ inputs = [] If there is a file with the same name as provided, it can be overwritten. ```shell -sncast multicall new ./template.toml --overwrite +$ sncast multicall new ./template.toml --overwrite ```
diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 24377a878a..dc2e9f6d1c 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -207,7 +207,7 @@ This setup can be seen in action in [Full Example below](#full-example-with-cont To get started, a deployment script with all required elements can be initialized using the following command: ```shell -sncast script init my_script +$ sncast script init my_script ``` For more details, see [init command](../appendix/sncast/script/init.md). @@ -256,7 +256,7 @@ sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = To run the script, do: ```shell -sncast \ +$ sncast \ script run my_script --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` @@ -334,7 +334,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -361,7 +361,7 @@ As [an idempotency](#state-file) feature is turned on by default, executing the and only `call` functions are being executed (as they do not change the network state): ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -385,7 +385,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already declared): ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index 378dfc50af..de1b514f37 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -14,7 +14,7 @@ replace any subcommand (and its parameters) with `show-config` and it will show ### General Example ```shell -sncast \ +$ sncast \ --account user1 \ show-config \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 2382e09a98..1ecf3821b2 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -13,7 +13,7 @@ For a detailed CLI description, refer to the [tx-status command reference](../ap You can track the details about the execution and finality status of a transaction in the given network by using the transaction hash as shown below: ```shell -sncast \ +$ sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 011d41db59..eb75048188 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -24,7 +24,7 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: ```shell -sncast \ +$ sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ --contract-name SimpleBalance \ diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index e730240365..a434ff612b 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -39,7 +39,7 @@ Let's write a test that will deploy the `HelloStarknet` contract and call some f > `HelloStarknet` contract has no constructor, so the calldata remains empty in the example above. ```shell -snforge test +$ snforge test ```
@@ -75,7 +75,7 @@ If we called this function in a test, it would result in a failure. ``` ```shell -snforge test +$ snforge test ```
@@ -113,7 +113,7 @@ They allow using the contract without automatically unwrapping the result, which Now the test passes as expected. ```shell -snforge test +$ snforge test ```
diff --git a/docs/src/testing/coverage.md b/docs/src/testing/coverage.md index 0887517f35..db77f9214d 100644 --- a/docs/src/testing/coverage.md +++ b/docs/src/testing/coverage.md @@ -31,7 +31,7 @@ Usage details and limitations are also described there - make sure to check it o All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -snforge test --save-trace-data +$ snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -40,7 +40,7 @@ for the [cairo-coverage](https://github.com/software-mansion/cairo-coverage). If you want `snforge` to call `cairo-coverage` on generated files automatically, use [`--coverage`](../appendix/snforge/test.md#--coverage) flag: ```shell -snforge test --coverage +$ snforge test --coverage ``` This will generate a coverage report in the `coverage` directory named `coverage.lcov`. @@ -51,7 +51,7 @@ You can pass additional arguments to `cairo-coverage` by using the `--` separato to `cairo-coverage`: ```shell -snforge test --coverage -- --include macros +$ snforge test --coverage -- --include macros ``` > 📝 **Note** diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 26294c9b81..604f5a7aa3 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -37,7 +37,7 @@ It is possible to enable more detailed breakdown of resources, on which the gas In order to run tests with this feature, run the `test` command with the appropriate flag: ```shell -snforge test --detailed-resources +$ snforge test --detailed-resources ```
diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index a0772c45a6..6644822774 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -3,7 +3,7 @@ To run tests with `snforge`, simply run the `snforge test` command from the package directory. ```shell -snforge test +$ snforge test ```
@@ -27,7 +27,7 @@ By default, any test with an [absolute module tree path](https://book.cairo-lang matching the filter will be run. ```shell -snforge test calling +$ snforge test calling ```
@@ -54,7 +54,7 @@ Note, you have to use a fully qualified test name, including a module name. > ```shell -snforge test package_name::tests::calling --exact +$ snforge test package_name::tests::calling --exact ```
@@ -74,7 +74,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out To stop the test execution after first failed test, you can pass an `--exit-first` flag along with `snforge test` command. ```shell -snforge test --exit-first +$ snforge test --exit-first ```
@@ -104,7 +104,7 @@ Failures: To track resources like `builtins` / `syscalls` that are used when running tests, use `snforge test --detailed-resources`. ```shell -snforge test --detailed-resources +$ snforge test --detailed-resources ```
diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index f4ad22f440..350749fd0f 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -39,7 +39,7 @@ tree . -L 3 only the tests in `./src` and `./tests` folders will be executed. ```shell -snforge test +$ snforge test ```
@@ -58,7 +58,7 @@ To select the specific package to test, pass a `--package package_name` (or `-p You can also run `snforge test` from the package directory to achieve the same effect. ```shell -snforge test --package addition +$ snforge test --package addition ```
@@ -78,7 +78,7 @@ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out You can also pass `--workspace` flag to run tests for all packages in the workspace. ```shell -snforge test --workspace +$ snforge test --workspace ```
diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index 313badb971..b3d7272667 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -19,7 +19,7 @@ You can find a detailed explanation of how `snforge` collects tests [here](test- Now run `snforge` using a command: ```shell -snforge test +$ snforge test ```
@@ -44,7 +44,7 @@ If your code panics, the test is considered failed. Here's an example of a faili ``` ```shell -snforge test +$ snforge test ```
@@ -92,7 +92,7 @@ With this format, the expected error message needs to be a substring of the actu ``` ```shell -snforge test +$ snforge test ```
@@ -118,7 +118,7 @@ You can achieve it using `#[ignore]` - tests marked with this attribute will be ``` ```shell -snforge test +$ snforge test ```
diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index ebd23f967a..c714109698 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -38,7 +38,7 @@ We can try to create a test that will increase and verify the balance. This test fails, which means that `increase_balance` method panics as we expected. ```shell -snforge test +$ snforge test ```
@@ -74,7 +74,7 @@ address, so it passes our validation. The test will now pass without an error ```shell -snforge test +$ snforge test ```
@@ -104,7 +104,7 @@ We will demonstrate its behavior using `SafeDispatcher` to show when exactly the ``` ```shell -snforge test +$ snforge test ```
From 3ef847fc198b756250e4d063c23c646d62254281 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 14:50:54 +0100 Subject: [PATCH 006/183] Revert "Restore prompt in shell snippets" This reverts commit 62bb35a35342235cf7a7ce2235e612be84464f3f. --- crates/sncast/README.md | 18 +++++++++--------- .../parametrizing_tests_with_fixed_values.md | 2 +- docs/src/getting-started/first-steps.md | 8 ++++---- docs/src/getting-started/installation.md | 2 +- docs/src/projects/configuration.md | 4 ++-- .../snforge-advanced-features/fuzz-testing.md | 4 ++-- .../src/snforge-advanced-features/profiling.md | 6 +++--- docs/src/starknet/account-import.md | 10 +++++----- docs/src/starknet/account.md | 18 +++++++++--------- docs/src/starknet/call.md | 4 ++-- docs/src/starknet/calldata-transformation.md | 10 +++++----- docs/src/starknet/declare.md | 2 +- docs/src/starknet/deploy.md | 8 ++++---- docs/src/starknet/fees-and-versions.md | 8 ++++---- docs/src/starknet/index.md | 6 +++--- docs/src/starknet/invoke.md | 4 ++-- docs/src/starknet/multicall.md | 6 +++--- docs/src/starknet/script.md | 10 +++++----- docs/src/starknet/show_config.md | 2 +- docs/src/starknet/tx-status.md | 2 +- docs/src/starknet/verify.md | 2 +- docs/src/testing/contracts.md | 6 +++--- docs/src/testing/coverage.md | 6 +++--- .../src/testing/gas-and-resource-estimation.md | 2 +- docs/src/testing/running-tests.md | 10 +++++----- docs/src/testing/testing-workspaces.md | 6 +++--- docs/src/testing/testing.md | 8 ++++---- docs/src/testing/using-cheatcodes.md | 6 +++--- 28 files changed, 90 insertions(+), 90 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 3165eeadf5..ec586d5dc2 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,7 +32,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract ```shell -$ sncast --account myuser \ +sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ declare \ --contract-name SimpleBalance @@ -52,7 +52,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast declare \ +sncast declare \ --contract-name SimpleBalance ``` @@ -71,7 +71,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Deploy a contract ```shell -$ sncast --account myuser \ +sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ``` @@ -90,7 +90,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ```
@@ -108,7 +108,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +sncast --url http://127.0.0.1:5050 \ --account example_user \ invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ @@ -130,7 +130,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast invoke \ +sncast invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -149,7 +149,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Call a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +sncast --url http://127.0.0.1:5050 \ call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ @@ -170,7 +170,7 @@ response: [0x0] With arguments taken from `snfoundry.toml` file (default profile name): ```shell -$ sncast call \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function some_function \ --calldata 1 2 3 @@ -195,7 +195,7 @@ Please make sure you're using scarb installed via asdf - otherwise some tests ma To verify, run: ```shell -$ which scarb +which scarb ```
diff --git a/design_documents/parametrizing_tests_with_fixed_values.md b/design_documents/parametrizing_tests_with_fixed_values.md index 8e5d26a407..fa3a0c7467 100644 --- a/design_documents/parametrizing_tests_with_fixed_values.md +++ b/design_documents/parametrizing_tests_with_fixed_values.md @@ -119,7 +119,7 @@ If a test case has a custom name, it should be displayed to the user. An example output could look similarly to this: ```shell -$ snforge test +snforge test [PASS] tests::parametrized(a = 1, b = 2) # unnamed test case [PASS] tests::parametrized[a_test](a = 3, b = 5) # named test case [FAIL] tests::parametrized[my_case](a = 4, b = 5) # named test case diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index f0e74b8c35..6c79e2b2e9 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -6,7 +6,7 @@ We demonstrate how to create a new project, compile, and test it. To start a new project with Starknet Foundry, run `snforge init` ```shell -$ snforge init project_name +snforge init project_name ``` Let's check out the project structure @@ -34,7 +34,7 @@ tree . -L 1 And run tests with `snforge test` ```shell -$ snforge test +snforge test ```
@@ -71,14 +71,14 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag Make sure that the version in `tag` matches `snforge`. You can check the currently installed version with ```shell -$ snforge --version +snforge --version ```
Click to expand ```shell -$ snforge 0.27.0 +snforge 0.27.0 ```

diff --git a/docs/src/getting-started/installation.md b/docs/src/getting-started/installation.md index 6ff62d1841..b0d96f061f 100644 --- a/docs/src/getting-started/installation.md +++ b/docs/src/getting-started/installation.md @@ -81,7 +81,7 @@ As for now, Starknet Foundry on Windows needs manual installation, but necessary 4. Verify installation by running the following command in new terminal session: ```shell -$ snforge --version +snforge --version sncast --version ``` diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 18d74fbf7b..41aa0a089c 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -50,7 +50,7 @@ defined in the profile. > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. ```shell -$ sncast --profile myprofile \ +sncast --profile myprofile \ call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ @@ -88,7 +88,7 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. ```shell -$ sncast call \ +sncast call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ --calldata 0x0 \ diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index 73326e1719..d6faf359c3 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -23,7 +23,7 @@ The test will be run many times against different randomly generated values. Then run `snforge test` like usual. ```shell -$ snforge test +snforge test ```
@@ -65,7 +65,7 @@ It is possible to configure the number of runs of the random fuzzer as well as i It can also be configured globally, via command line arguments: ```shell -$ snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 +snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 ``` Or in `Scarb.toml` file: diff --git a/docs/src/snforge-advanced-features/profiling.md b/docs/src/snforge-advanced-features/profiling.md index e7fbc16fd8..c9d641e6e3 100644 --- a/docs/src/snforge-advanced-features/profiling.md +++ b/docs/src/snforge-advanced-features/profiling.md @@ -9,7 +9,7 @@ You can inspect the call tree, see how many resources are used for different par All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -$ snforge test --save-trace-data +snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -18,7 +18,7 @@ for the [cairo-profiler](https://github.com/software-mansion/cairo-profiler). If you want `snforge` to call `cairo-profiler` on generated files automatically, use [`--build-profile`](../appendix/snforge/test.md#--build-profile) flag: ```shell -$ snforge test --build-profile +snforge test --build-profile ``` ## Passing arguments to `cairo-profiler` @@ -27,7 +27,7 @@ You can pass additional arguments to `cairo-profiler` by using the `--` separato to `cairo-profiler`: ```shell -$ snforge test --build-profile -- --show-inlined-functions +snforge test --build-profile -- --show-inlined-functions ``` > 📝 **Note** diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index c316dc4be8..1d712cdb7b 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -72,7 +72,7 @@ This section shows how to export your private key from specific wallets. To import an account into the file holding the accounts info (`~/.starknet_accounts/starknet_open_zeppelin_accounts.json` by default), use the `account import` command. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -88,7 +88,7 @@ $ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -110,7 +110,7 @@ Type in your private key and press enter: To import Argent account, set the `--type` flag to `argent`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_argent \ @@ -124,7 +124,7 @@ $ sncast \ To import Braavos account, set the `--type` flag to `braavos`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_braavos \ @@ -138,7 +138,7 @@ $ sncast \ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin`. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_oz \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 03b3cbf83a..4d84f9dbbb 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -23,7 +23,7 @@ Do the following to start interacting with the Starknet: #### Create account with the `sncast account create` command ```shell -$ sncast \ +sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name @@ -60,7 +60,7 @@ You can do it both by sending tokens from another starknet account or by bridgin #### Deploy account with the `sncast account deploy` command ```shell -$ sncast \ +sncast \ account deploy \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -87,7 +87,7 @@ If you created an account with `sncast account create` it by default it will be To import an account to the `default accounts file`, use the `account import` command. ```shell -$ sncast \ +sncast \ account import \ --url http://127.0.0.1:5050 \ --name my_imported_account \ @@ -100,7 +100,7 @@ $ sncast \ List all accounts saved in `accounts file`, grouped based on the networks they are defined on. ```shell -$ sncast account list +sncast account list ``` ``` @@ -125,7 +125,7 @@ There is also possibility to show private keys with the `--display-private-keys` Delete an account from `accounts-file` and its associated Scarb profile. If you pass this command, you will be asked to confirm the deletion. ```shell -$ sncast account delete \ +sncast account delete \ --name some-name \ --network alpha-sepolia ``` @@ -139,7 +139,7 @@ It is possible to create an account using custom openzeppelin, argent or braavos with `--class-hash` flag: ```shell -$ sncast \ +sncast \ account create \ --name some-name \ --url http://127.0.0.1:5050 \ @@ -151,7 +151,7 @@ $ sncast \ Instead of random generation, salt can be specified with `--salt`. ```shell -$ sncast \ +sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -180,7 +180,7 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. ```shell -$ sncast \ +sncast \ --keystore keystore.json \ --account account.json \ declare \ @@ -194,7 +194,7 @@ $ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. ```shell -$ sncast \ +sncast \ --keystore my_key.json \ --account my_account.json \ account create \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 33bcee9184..21aa6672fa 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -17,7 +17,7 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ### General Example ```shell -$ sncast call \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -41,7 +41,7 @@ response: [0x1, 0x23, 0x4] You can call a contract at the specific block by passing `--block-id` argument. ```shell -$ sncast call \ +sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 52c8aea376..a9ad0791ce 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -53,7 +53,7 @@ pub mod DataTransformerContract { A default form of calldata passed to commands requiring it is a series of hex-encoded felts: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -79,7 +79,7 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -124,7 +124,7 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -147,7 +147,7 @@ $ sncast call \ Alternatively, you can continue the single quote for multiple lines. ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -169,7 +169,7 @@ true, 2. `nested_struct_fn` - struct nesting: ```shell -$ sncast call \ +sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function nested_struct_fn \ diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index e3cc81b6c9..440b88338b 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -18,7 +18,7 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: ```shell -$ sncast --account myuser \ +sncast --account myuser \ declare \ --url http://127.0.0.1:5050/rpc \ --fee-token strk \ diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 1caec3fd1f..73402fa3b7 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -15,7 +15,7 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: ```shell -$ sncast \ +sncast \ --account myuser \ deploy \ --url http://127.0.0.1:5050/rpc \ @@ -58,7 +58,7 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --constructor-calldata 0x1 0x1 0x0 @@ -89,7 +89,7 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --salt 0x123 @@ -116,7 +116,7 @@ Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. ```shell -$ sncast deploy \ +sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --unique diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 6c2fe7cb5a..eeb9854c2a 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -26,7 +26,7 @@ When deploying an account, you can specify the version of the transaction and th When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 @@ -34,7 +34,7 @@ $ sncast account deploy \ or set `--version` to `v3`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --version v3 \ --max-fee 9999999999999 @@ -43,7 +43,7 @@ $ sncast account deploy \ In case of paying in ETH, same rules apply. You need to set either `--fee-token` to `eth`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --fee-token eth \ --max-fee 9999999999999 @@ -52,7 +52,7 @@ $ sncast account deploy \ or set `--version` to `v1`: ```shell -$ sncast account deploy \ +sncast account deploy \ --name some-name \ --version v1 \ --max-fee 9999999999999 diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index a746c9510d..d4c5dc8804 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -12,7 +12,7 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): ```shell -$ sncast +sncast ``` If `snfoundry.toml` is present and configured with `[sncast.default]`, `url`, `accounts-file` and `account` name will be taken from it. @@ -28,7 +28,7 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: ```shell -$ sncast --account myuser \ +sncast --account myuser \ call \ --url http://127.0.0.1:5050 \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ @@ -71,7 +71,7 @@ It is also possible to pass calldata in more friendly, human readable form thank Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. ```shell -$ sncast --account myuser \ +sncast --account myuser \ --wait \ deploy \ --url http://127.0.0.1:5050 \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index fad68d907f..7c0c3307d8 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -17,7 +17,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example ```shell -$ sncast \ +sncast \ --account example_user \ invoke \ --url http://127.0.0.1:5050 \ @@ -51,7 +51,7 @@ transaction: https://starkscan.co/tx/0x7ad0d6e449... Not every function accepts parameters. Here is how to call it. ```shell -$ sncast invoke \ +sncast invoke \ --fee-token strk \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "function_without_params" diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 04290a0599..fc8536091b 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -47,7 +47,7 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. ```shell -$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk ```
@@ -74,7 +74,7 @@ transaction: https://starkscan.co/tx/0x38fb8a0432... You can also generate multicall template with `multicall new` command, specifying output path. ```shell -$ sncast multicall new ./template.toml +sncast multicall new ./template.toml ```
@@ -110,7 +110,7 @@ inputs = [] If there is a file with the same name as provided, it can be overwritten. ```shell -$ sncast multicall new ./template.toml --overwrite +sncast multicall new ./template.toml --overwrite ```
diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index dc2e9f6d1c..24377a878a 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -207,7 +207,7 @@ This setup can be seen in action in [Full Example below](#full-example-with-cont To get started, a deployment script with all required elements can be initialized using the following command: ```shell -$ sncast script init my_script +sncast script init my_script ``` For more details, see [init command](../appendix/sncast/script/init.md). @@ -256,7 +256,7 @@ sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = To run the script, do: ```shell -$ sncast \ +sncast \ script run my_script --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` @@ -334,7 +334,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -361,7 +361,7 @@ As [an idempotency](#state-file) feature is turned on by default, executing the and only `call` functions are being executed (as they do not change the network state): ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -385,7 +385,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already declared): ```shell -$ sncast \ +sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index de1b514f37..378dfc50af 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -14,7 +14,7 @@ replace any subcommand (and its parameters) with `show-config` and it will show ### General Example ```shell -$ sncast \ +sncast \ --account user1 \ show-config \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 1ecf3821b2..2382e09a98 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -13,7 +13,7 @@ For a detailed CLI description, refer to the [tx-status command reference](../ap You can track the details about the execution and finality status of a transaction in the given network by using the transaction hash as shown below: ```shell -$ sncast \ +sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index eb75048188..011d41db59 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -24,7 +24,7 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: ```shell -$ sncast \ +sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ --contract-name SimpleBalance \ diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index a434ff612b..e730240365 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -39,7 +39,7 @@ Let's write a test that will deploy the `HelloStarknet` contract and call some f > `HelloStarknet` contract has no constructor, so the calldata remains empty in the example above. ```shell -$ snforge test +snforge test ```
@@ -75,7 +75,7 @@ If we called this function in a test, it would result in a failure. ``` ```shell -$ snforge test +snforge test ```
@@ -113,7 +113,7 @@ They allow using the contract without automatically unwrapping the result, which Now the test passes as expected. ```shell -$ snforge test +snforge test ```
diff --git a/docs/src/testing/coverage.md b/docs/src/testing/coverage.md index db77f9214d..0887517f35 100644 --- a/docs/src/testing/coverage.md +++ b/docs/src/testing/coverage.md @@ -31,7 +31,7 @@ Usage details and limitations are also described there - make sure to check it o All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -$ snforge test --save-trace-data +snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -40,7 +40,7 @@ for the [cairo-coverage](https://github.com/software-mansion/cairo-coverage). If you want `snforge` to call `cairo-coverage` on generated files automatically, use [`--coverage`](../appendix/snforge/test.md#--coverage) flag: ```shell -$ snforge test --coverage +snforge test --coverage ``` This will generate a coverage report in the `coverage` directory named `coverage.lcov`. @@ -51,7 +51,7 @@ You can pass additional arguments to `cairo-coverage` by using the `--` separato to `cairo-coverage`: ```shell -$ snforge test --coverage -- --include macros +snforge test --coverage -- --include macros ``` > 📝 **Note** diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 604f5a7aa3..26294c9b81 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -37,7 +37,7 @@ It is possible to enable more detailed breakdown of resources, on which the gas In order to run tests with this feature, run the `test` command with the appropriate flag: ```shell -$ snforge test --detailed-resources +snforge test --detailed-resources ```
diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index 6644822774..a0772c45a6 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -3,7 +3,7 @@ To run tests with `snforge`, simply run the `snforge test` command from the package directory. ```shell -$ snforge test +snforge test ```
@@ -27,7 +27,7 @@ By default, any test with an [absolute module tree path](https://book.cairo-lang matching the filter will be run. ```shell -$ snforge test calling +snforge test calling ```
@@ -54,7 +54,7 @@ Note, you have to use a fully qualified test name, including a module name. > ```shell -$ snforge test package_name::tests::calling --exact +snforge test package_name::tests::calling --exact ```
@@ -74,7 +74,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out To stop the test execution after first failed test, you can pass an `--exit-first` flag along with `snforge test` command. ```shell -$ snforge test --exit-first +snforge test --exit-first ```
@@ -104,7 +104,7 @@ Failures: To track resources like `builtins` / `syscalls` that are used when running tests, use `snforge test --detailed-resources`. ```shell -$ snforge test --detailed-resources +snforge test --detailed-resources ```
diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index 350749fd0f..f4ad22f440 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -39,7 +39,7 @@ tree . -L 3 only the tests in `./src` and `./tests` folders will be executed. ```shell -$ snforge test +snforge test ```
@@ -58,7 +58,7 @@ To select the specific package to test, pass a `--package package_name` (or `-p You can also run `snforge test` from the package directory to achieve the same effect. ```shell -$ snforge test --package addition +snforge test --package addition ```
@@ -78,7 +78,7 @@ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out You can also pass `--workspace` flag to run tests for all packages in the workspace. ```shell -$ snforge test --workspace +snforge test --workspace ```
diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index b3d7272667..313badb971 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -19,7 +19,7 @@ You can find a detailed explanation of how `snforge` collects tests [here](test- Now run `snforge` using a command: ```shell -$ snforge test +snforge test ```
@@ -44,7 +44,7 @@ If your code panics, the test is considered failed. Here's an example of a faili ``` ```shell -$ snforge test +snforge test ```
@@ -92,7 +92,7 @@ With this format, the expected error message needs to be a substring of the actu ``` ```shell -$ snforge test +snforge test ```
@@ -118,7 +118,7 @@ You can achieve it using `#[ignore]` - tests marked with this attribute will be ``` ```shell -$ snforge test +snforge test ```
diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index c714109698..ebd23f967a 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -38,7 +38,7 @@ We can try to create a test that will increase and verify the balance. This test fails, which means that `increase_balance` method panics as we expected. ```shell -$ snforge test +snforge test ```
@@ -74,7 +74,7 @@ address, so it passes our validation. The test will now pass without an error ```shell -$ snforge test +snforge test ```
@@ -104,7 +104,7 @@ We will demonstrate its behavior using `SafeDispatcher` to show when exactly the ``` ```shell -$ snforge test +snforge test ```
From 304e423cde24e637a13919b05d46f9cc5e0d2429 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 15:12:14 +0100 Subject: [PATCH 007/183] Restore prompt in shell snippets --- README.md | 6 ++--- crates/sncast/README.md | 18 +++++++------- .../parametrizing_tests_with_fixed_values.md | 2 +- docs/README.md | 2 +- docs/src/development/environment-setup.md | 8 +++---- docs/src/getting-started/first-steps.md | 8 +++---- docs/src/getting-started/installation.md | 14 +++++------ docs/src/projects/configuration.md | 4 ++-- .../snforge-advanced-features/fuzz-testing.md | 4 ++-- .../snforge-advanced-features/profiling.md | 6 ++--- docs/src/starknet/account-import.md | 10 ++++---- docs/src/starknet/account.md | 18 +++++++------- docs/src/starknet/call.md | 4 ++-- docs/src/starknet/calldata-transformation.md | 10 ++++---- docs/src/starknet/declare.md | 2 +- docs/src/starknet/deploy.md | 8 +++---- docs/src/starknet/fees-and-versions.md | 8 +++---- docs/src/starknet/index.md | 6 ++--- docs/src/starknet/invoke.md | 4 ++-- docs/src/starknet/multicall.md | 6 ++--- docs/src/starknet/script.md | 24 +++++++++---------- docs/src/starknet/show_config.md | 2 +- docs/src/starknet/tx-status.md | 2 +- docs/src/starknet/verify.md | 2 +- docs/src/testing/contracts.md | 6 ++--- docs/src/testing/coverage.md | 8 +++---- .../testing/gas-and-resource-estimation.md | 2 +- docs/src/testing/running-tests.md | 10 ++++---- docs/src/testing/test-collection.md | 4 ++-- docs/src/testing/testing-workspaces.md | 8 +++---- docs/src/testing/testing.md | 8 +++---- docs/src/testing/using-cheatcodes.md | 6 ++--- 32 files changed, 115 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index c29d68dfd0..091c5ca556 100644 --- a/README.md +++ b/README.md @@ -35,19 +35,19 @@ Starknet Foundry, like its [Ethereum counterpart](https://github.com/foundry-rs/ To install Starknet Foundry, first install `snfoundryup` by running: ```shell -curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh +$ curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh ``` Follow the instructions and then run ```shell -snfoundryup +$ snfoundryup ``` You can also specify a version you wish to install: ```shell -snfoundryup -v 0.9.0 +$ snfoundryup -v 0.9.0 ``` To verify that the Starknet Foundry is installed correctly, run `snforge --version` and `sncast --version`. diff --git a/crates/sncast/README.md b/crates/sncast/README.md index ec586d5dc2..3165eeadf5 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,7 +32,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract ```shell -sncast --account myuser \ +$ sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ declare \ --contract-name SimpleBalance @@ -52,7 +52,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast declare \ +$ sncast declare \ --contract-name SimpleBalance ``` @@ -71,7 +71,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Deploy a contract ```shell -sncast --account myuser \ +$ sncast --account myuser \ --url http://127.0.0.1:5050/rpc \ deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ``` @@ -90,7 +90,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ```
@@ -108,7 +108,7 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract ```shell -sncast --url http://127.0.0.1:5050 \ +$ sncast --url http://127.0.0.1:5050 \ --account example_user \ invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ @@ -130,7 +130,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast invoke \ +$ sncast invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -149,7 +149,7 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Call a contract ```shell -sncast --url http://127.0.0.1:5050 \ +$ sncast --url http://127.0.0.1:5050 \ call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ @@ -170,7 +170,7 @@ response: [0x0] With arguments taken from `snfoundry.toml` file (default profile name): ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function some_function \ --calldata 1 2 3 @@ -195,7 +195,7 @@ Please make sure you're using scarb installed via asdf - otherwise some tests ma To verify, run: ```shell -which scarb +$ which scarb ```
diff --git a/design_documents/parametrizing_tests_with_fixed_values.md b/design_documents/parametrizing_tests_with_fixed_values.md index fa3a0c7467..8e5d26a407 100644 --- a/design_documents/parametrizing_tests_with_fixed_values.md +++ b/design_documents/parametrizing_tests_with_fixed_values.md @@ -119,7 +119,7 @@ If a test case has a custom name, it should be displayed to the user. An example output could look similarly to this: ```shell -snforge test +$ snforge test [PASS] tests::parametrized(a = 1, b = 2) # unnamed test case [PASS] tests::parametrized[a_test](a = 3, b = 5) # named test case [FAIL] tests::parametrized[my_case](a = 4, b = 5) # named test case diff --git a/docs/README.md b/docs/README.md index 6d1038e299..39b0255d33 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,7 +5,7 @@ Install mdBook ```shell -cargo install mdbook +$ cargo install mdbook ``` ## Building diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index 1767fbebdf..3376c1c18e 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -55,7 +55,7 @@ Install the latest [universal-sierra-compiler](https://github.com/software-mansi Tests can be run with: ```shell -cargo test +$ cargo test ``` @@ -64,19 +64,19 @@ cargo test Starknet Foundry uses [rustfmt](https://github.com/rust-lang/rustfmt) for formatting. You can run the formatter with ```shell -cargo fmt +$ cargo fmt ``` For linting, it uses [clippy](https://github.com/rust-lang/rust-clippy). You can run it with this command: ```shell -cargo clippy --all-targets --all-features -- --no-deps -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::default_trait_access +$ cargo clippy --all-targets --all-features -- --no-deps -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::default_trait_access ``` Or using our defined alias ```shell -cargo lint +$ cargo lint ``` ## Spelling diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 6c79e2b2e9..f0e74b8c35 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -6,7 +6,7 @@ We demonstrate how to create a new project, compile, and test it. To start a new project with Starknet Foundry, run `snforge init` ```shell -snforge init project_name +$ snforge init project_name ``` Let's check out the project structure @@ -34,7 +34,7 @@ tree . -L 1 And run tests with `snforge test` ```shell -snforge test +$ snforge test ```
@@ -71,14 +71,14 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag Make sure that the version in `tag` matches `snforge`. You can check the currently installed version with ```shell -snforge --version +$ snforge --version ```
Click to expand ```shell -snforge 0.27.0 +$ snforge 0.27.0 ```

diff --git a/docs/src/getting-started/installation.md b/docs/src/getting-started/installation.md index b0d96f061f..9f59b52b12 100644 --- a/docs/src/getting-started/installation.md +++ b/docs/src/getting-started/installation.md @@ -25,13 +25,13 @@ Snfoundryup is the Starknet Foundry toolchain installer. You can install it by running: ```shell -curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh +$ curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh ``` Follow the instructions and then run: ```shell -snfoundryup +$ snfoundryup ``` See `snfoundryup --help` for more options. @@ -43,7 +43,7 @@ To verify that the Starknet Foundry is installed correctly, run `snforge --versi First, add the Starknet Foundry plugin to asdf: ```shell -asdf plugin add starknet-foundry +$ asdf plugin add starknet-foundry ``` #### Common Error @@ -58,7 +58,7 @@ Consider adding one of the following versions in your config file at starknet-fo This error indicates that `Starknet Foundry` version is unset. To resolve it, set the version globally using asdf: ```shell -asdf global starknet-foundry +$ asdf global starknet-foundry ``` For additional information on asdf version management, see the [asdf](https://asdf-vm.com/guide/getting-started.html#_6-set-a-version) @@ -81,8 +81,8 @@ As for now, Starknet Foundry on Windows needs manual installation, but necessary 4. Verify installation by running the following command in new terminal session: ```shell -snforge --version -sncast --version +$ snforge --version +$ sncast --version ``` ### Universal-Sierra-Compiler update @@ -90,7 +90,7 @@ sncast --version If you would like to bump the USC manually (e.g. when the new Sierra version is released) you can do it by running: ```shell -curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh +$ curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh ``` ## How to build Starknet Foundry from source code diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 41aa0a089c..18d74fbf7b 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -50,7 +50,7 @@ defined in the profile. > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. ```shell -sncast --profile myprofile \ +$ sncast --profile myprofile \ call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ @@ -88,7 +88,7 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. ```shell -sncast call \ +$ sncast call \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ --function get \ --calldata 0x0 \ diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index d6faf359c3..73326e1719 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -23,7 +23,7 @@ The test will be run many times against different randomly generated values. Then run `snforge test` like usual. ```shell -snforge test +$ snforge test ```
@@ -65,7 +65,7 @@ It is possible to configure the number of runs of the random fuzzer as well as i It can also be configured globally, via command line arguments: ```shell -snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 +$ snforge test --fuzzer-runs 1234 --fuzzer-seed 1111 ``` Or in `Scarb.toml` file: diff --git a/docs/src/snforge-advanced-features/profiling.md b/docs/src/snforge-advanced-features/profiling.md index c9d641e6e3..e7fbc16fd8 100644 --- a/docs/src/snforge-advanced-features/profiling.md +++ b/docs/src/snforge-advanced-features/profiling.md @@ -9,7 +9,7 @@ You can inspect the call tree, see how many resources are used for different par All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -snforge test --save-trace-data +$ snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -18,7 +18,7 @@ for the [cairo-profiler](https://github.com/software-mansion/cairo-profiler). If you want `snforge` to call `cairo-profiler` on generated files automatically, use [`--build-profile`](../appendix/snforge/test.md#--build-profile) flag: ```shell -snforge test --build-profile +$ snforge test --build-profile ``` ## Passing arguments to `cairo-profiler` @@ -27,7 +27,7 @@ You can pass additional arguments to `cairo-profiler` by using the `--` separato to `cairo-profiler`: ```shell -snforge test --build-profile -- --show-inlined-functions +$ snforge test --build-profile -- --show-inlined-functions ``` > 📝 **Note** diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 1d712cdb7b..c316dc4be8 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -72,7 +72,7 @@ This section shows how to export your private key from specific wallets. To import an account into the file holding the accounts info (`~/.starknet_accounts/starknet_open_zeppelin_accounts.json` by default), use the `account import` command. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -88,7 +88,7 @@ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_123 \ @@ -110,7 +110,7 @@ Type in your private key and press enter: To import Argent account, set the `--type` flag to `argent`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_argent \ @@ -124,7 +124,7 @@ sncast \ To import Braavos account, set the `--type` flag to `braavos`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_braavos \ @@ -138,7 +138,7 @@ sncast \ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin`. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name account_oz \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 4d84f9dbbb..03b3cbf83a 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -23,7 +23,7 @@ Do the following to start interacting with the Starknet: #### Create account with the `sncast account create` command ```shell -sncast \ +$ sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name @@ -60,7 +60,7 @@ You can do it both by sending tokens from another starknet account or by bridgin #### Deploy account with the `sncast account deploy` command ```shell -sncast \ +$ sncast \ account deploy \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -87,7 +87,7 @@ If you created an account with `sncast account create` it by default it will be To import an account to the `default accounts file`, use the `account import` command. ```shell -sncast \ +$ sncast \ account import \ --url http://127.0.0.1:5050 \ --name my_imported_account \ @@ -100,7 +100,7 @@ sncast \ List all accounts saved in `accounts file`, grouped based on the networks they are defined on. ```shell -sncast account list +$ sncast account list ``` ``` @@ -125,7 +125,7 @@ There is also possibility to show private keys with the `--display-private-keys` Delete an account from `accounts-file` and its associated Scarb profile. If you pass this command, you will be asked to confirm the deletion. ```shell -sncast account delete \ +$ sncast account delete \ --name some-name \ --network alpha-sepolia ``` @@ -139,7 +139,7 @@ It is possible to create an account using custom openzeppelin, argent or braavos with `--class-hash` flag: ```shell -sncast \ +$ sncast \ account create \ --name some-name \ --url http://127.0.0.1:5050 \ @@ -151,7 +151,7 @@ sncast \ Instead of random generation, salt can be specified with `--salt`. ```shell -sncast \ +$ sncast \ account create \ --url http://127.0.0.1:5050 \ --name some-name \ @@ -180,7 +180,7 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. ```shell -sncast \ +$ sncast \ --keystore keystore.json \ --account account.json \ declare \ @@ -194,7 +194,7 @@ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. ```shell -sncast \ +$ sncast \ --keystore my_key.json \ --account my_account.json \ account create \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 21aa6672fa..33bcee9184 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -17,7 +17,7 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ### General Example ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -41,7 +41,7 @@ response: [0x1, 0x23, 0x4] You can call a contract at the specific block by passing `--block-id` argument. ```shell -sncast call \ +$ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index a9ad0791ce..52c8aea376 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -53,7 +53,7 @@ pub mod DataTransformerContract { A default form of calldata passed to commands requiring it is a series of hex-encoded felts: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -79,7 +79,7 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function tuple_fn \ @@ -124,7 +124,7 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -147,7 +147,7 @@ sncast call \ Alternatively, you can continue the single quote for multiple lines. ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function complex_fn \ @@ -169,7 +169,7 @@ true, 2. `nested_struct_fn` - struct nesting: ```shell -sncast call \ +$ sncast call \ --url http://127.0.0.1:5050 \ --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ --function nested_struct_fn \ diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 440b88338b..e3cc81b6c9 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -18,7 +18,7 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: ```shell -sncast --account myuser \ +$ sncast --account myuser \ declare \ --url http://127.0.0.1:5050/rpc \ --fee-token strk \ diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 73402fa3b7..1caec3fd1f 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -15,7 +15,7 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: ```shell -sncast \ +$ sncast \ --account myuser \ deploy \ --url http://127.0.0.1:5050/rpc \ @@ -58,7 +58,7 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --constructor-calldata 0x1 0x1 0x0 @@ -89,7 +89,7 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --salt 0x123 @@ -116,7 +116,7 @@ Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. ```shell -sncast deploy \ +$ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --unique diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index eeb9854c2a..6c2fe7cb5a 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -26,7 +26,7 @@ When deploying an account, you can specify the version of the transaction and th When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 @@ -34,7 +34,7 @@ sncast account deploy \ or set `--version` to `v3`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --version v3 \ --max-fee 9999999999999 @@ -43,7 +43,7 @@ sncast account deploy \ In case of paying in ETH, same rules apply. You need to set either `--fee-token` to `eth`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --fee-token eth \ --max-fee 9999999999999 @@ -52,7 +52,7 @@ sncast account deploy \ or set `--version` to `v1`: ```shell -sncast account deploy \ +$ sncast account deploy \ --name some-name \ --version v1 \ --max-fee 9999999999999 diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index d4c5dc8804..a746c9510d 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -12,7 +12,7 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): ```shell -sncast +$ sncast ``` If `snfoundry.toml` is present and configured with `[sncast.default]`, `url`, `accounts-file` and `account` name will be taken from it. @@ -28,7 +28,7 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: ```shell -sncast --account myuser \ +$ sncast --account myuser \ call \ --url http://127.0.0.1:5050 \ --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ @@ -71,7 +71,7 @@ It is also possible to pass calldata in more friendly, human readable form thank Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. ```shell -sncast --account myuser \ +$ sncast --account myuser \ --wait \ deploy \ --url http://127.0.0.1:5050 \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 7c0c3307d8..fad68d907f 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -17,7 +17,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example ```shell -sncast \ +$ sncast \ --account example_user \ invoke \ --url http://127.0.0.1:5050 \ @@ -51,7 +51,7 @@ transaction: https://starkscan.co/tx/0x7ad0d6e449... Not every function accepts parameters. Here is how to call it. ```shell -sncast invoke \ +$ sncast invoke \ --fee-token strk \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "function_without_params" diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index fc8536091b..04290a0599 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -47,7 +47,7 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. ```shell -sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk ```
@@ -74,7 +74,7 @@ transaction: https://starkscan.co/tx/0x38fb8a0432... You can also generate multicall template with `multicall new` command, specifying output path. ```shell -sncast multicall new ./template.toml +$ sncast multicall new ./template.toml ```
@@ -110,7 +110,7 @@ inputs = [] If there is a file with the same name as provided, it can be overwritten. ```shell -sncast multicall new ./template.toml --overwrite +$ sncast multicall new ./template.toml --overwrite ```
diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 24377a878a..bd8d548e79 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -67,7 +67,7 @@ Most common directory structures include: ### 1. `scripts` directory with all the scripts in the same workspace with cairo contracts (default for `sncast script init`) ```shell -tree +$ tree ```
@@ -99,7 +99,7 @@ You can also have multiple scripts as separate packages, or multiple modules ins #### 1a. multiple scripts in one package ```shell -tree +$ tree ```
@@ -125,7 +125,7 @@ tree #### 1b. multiple scripts as separate packages ```shell -tree +$ tree ```
@@ -156,7 +156,7 @@ tree #### 1c. single script with flat directory structure ```shell -tree +$ tree ```
@@ -179,7 +179,7 @@ tree ### 2. scripts disjointed from the workspace with cairo contracts ```shell -tree +$ tree ```
@@ -207,7 +207,7 @@ This setup can be seen in action in [Full Example below](#full-example-with-cont To get started, a deployment script with all required elements can be initialized using the following command: ```shell -sncast script init my_script +$ sncast script init my_script ``` For more details, see [init command](../appendix/sncast/script/init.md). @@ -227,7 +227,7 @@ This example shows how to call an already deployed contract. Please find full ex The script should be included in a Scarb package. The directory structure and config for this example looks like this: ```shell -tree +$ tree ```
@@ -256,7 +256,7 @@ sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = To run the script, do: ```shell -sncast \ +$ sncast \ script run my_script --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 ``` @@ -288,7 +288,7 @@ We prepare a script: The script should be included in a Scarb package. The directory structure and config for this example looks like this: ```shell -tree +$ tree ```
@@ -334,7 +334,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -361,7 +361,7 @@ As [an idempotency](#state-file) feature is turned on by default, executing the and only `call` functions are being executed (as they do not change the network state): ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 @@ -385,7 +385,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already declared): ```shell -sncast \ +$ sncast \ --account example_user \ script run map_script \ --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index 378dfc50af..de1b514f37 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -14,7 +14,7 @@ replace any subcommand (and its parameters) with `show-config` and it will show ### General Example ```shell -sncast \ +$ sncast \ --account user1 \ show-config \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 2382e09a98..1ecf3821b2 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -13,7 +13,7 @@ For a detailed CLI description, refer to the [tx-status command reference](../ap You can track the details about the execution and finality status of a transaction in the given network by using the transaction hash as shown below: ```shell -sncast \ +$ sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ --url http://127.0.0.1:5050 diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 011d41db59..eb75048188 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -24,7 +24,7 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: ```shell -sncast \ +$ sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ --contract-name SimpleBalance \ diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index e730240365..a434ff612b 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -39,7 +39,7 @@ Let's write a test that will deploy the `HelloStarknet` contract and call some f > `HelloStarknet` contract has no constructor, so the calldata remains empty in the example above. ```shell -snforge test +$ snforge test ```
@@ -75,7 +75,7 @@ If we called this function in a test, it would result in a failure. ``` ```shell -snforge test +$ snforge test ```
@@ -113,7 +113,7 @@ They allow using the contract without automatically unwrapping the result, which Now the test passes as expected. ```shell -snforge test +$ snforge test ```
diff --git a/docs/src/testing/coverage.md b/docs/src/testing/coverage.md index 0887517f35..2804e29dde 100644 --- a/docs/src/testing/coverage.md +++ b/docs/src/testing/coverage.md @@ -31,7 +31,7 @@ Usage details and limitations are also described there - make sure to check it o All you have to do is use the [`--save-trace-data`](../appendix/snforge/test.md#--save-trace-data) flag: ```shell -snforge test --save-trace-data +$ snforge test --save-trace-data ``` The files with traces will be saved to `snfoundry_trace` directory. Each one of these files can then be used as an input @@ -40,7 +40,7 @@ for the [cairo-coverage](https://github.com/software-mansion/cairo-coverage). If you want `snforge` to call `cairo-coverage` on generated files automatically, use [`--coverage`](../appendix/snforge/test.md#--coverage) flag: ```shell -snforge test --coverage +$ snforge test --coverage ``` This will generate a coverage report in the `coverage` directory named `coverage.lcov`. @@ -51,7 +51,7 @@ You can pass additional arguments to `cairo-coverage` by using the `--` separato to `cairo-coverage`: ```shell -snforge test --coverage -- --include macros +$ snforge test --coverage -- --include macros ``` > 📝 **Note** @@ -66,7 +66,7 @@ In this example we will use the `genhtml` tool from the [lcov package](https://g Run the following command in the directory containing your `coverage.lcov` file: ```shell -genhtml -o coverage_report coverage.lcov +$ genhtml -o coverage_report coverage.lcov ``` You can now open the `index.html` file in the `coverage_report` directory to see the generated coverage report. \ No newline at end of file diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 26294c9b81..604f5a7aa3 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -37,7 +37,7 @@ It is possible to enable more detailed breakdown of resources, on which the gas In order to run tests with this feature, run the `test` command with the appropriate flag: ```shell -snforge test --detailed-resources +$ snforge test --detailed-resources ```
diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index a0772c45a6..6644822774 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -3,7 +3,7 @@ To run tests with `snforge`, simply run the `snforge test` command from the package directory. ```shell -snforge test +$ snforge test ```
@@ -27,7 +27,7 @@ By default, any test with an [absolute module tree path](https://book.cairo-lang matching the filter will be run. ```shell -snforge test calling +$ snforge test calling ```
@@ -54,7 +54,7 @@ Note, you have to use a fully qualified test name, including a module name. > ```shell -snforge test package_name::tests::calling --exact +$ snforge test package_name::tests::calling --exact ```
@@ -74,7 +74,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out To stop the test execution after first failed test, you can pass an `--exit-first` flag along with `snforge test` command. ```shell -snforge test --exit-first +$ snforge test --exit-first ```
@@ -104,7 +104,7 @@ Failures: To track resources like `builtins` / `syscalls` that are used when running tests, use `snforge test --detailed-resources`. ```shell -snforge test --detailed-resources +$ snforge test --detailed-resources ```
diff --git a/docs/src/testing/test-collection.md b/docs/src/testing/test-collection.md index 178496755e..d39fa280dd 100644 --- a/docs/src/testing/test-collection.md +++ b/docs/src/testing/test-collection.md @@ -24,7 +24,7 @@ then it is treated as an entrypoint to the `tests` package from which tests are For example, for a package structured this way: ```shell -tree . +$ tree . ```
@@ -72,7 +72,7 @@ Then this virtual `lib.cairo` is treated as an entrypoint to the `tests` package For example, for a package structured this way: ```shell -tree . +$ tree . ```
diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index f4ad22f440..6ce859dcc1 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -11,7 +11,7 @@ When running `snforge test` in a Scarb workspace with a root package, it will on For a project structure like this ```shell -tree . -L 3 +$ tree . -L 3 ```
@@ -39,7 +39,7 @@ tree . -L 3 only the tests in `./src` and `./tests` folders will be executed. ```shell -snforge test +$ snforge test ```
@@ -58,7 +58,7 @@ To select the specific package to test, pass a `--package package_name` (or `-p You can also run `snforge test` from the package directory to achieve the same effect. ```shell -snforge test --package addition +$ snforge test --package addition ```
@@ -78,7 +78,7 @@ Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out You can also pass `--workspace` flag to run tests for all packages in the workspace. ```shell -snforge test --workspace +$ snforge test --workspace ```
diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index 313badb971..b3d7272667 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -19,7 +19,7 @@ You can find a detailed explanation of how `snforge` collects tests [here](test- Now run `snforge` using a command: ```shell -snforge test +$ snforge test ```
@@ -44,7 +44,7 @@ If your code panics, the test is considered failed. Here's an example of a faili ``` ```shell -snforge test +$ snforge test ```
@@ -92,7 +92,7 @@ With this format, the expected error message needs to be a substring of the actu ``` ```shell -snforge test +$ snforge test ```
@@ -118,7 +118,7 @@ You can achieve it using `#[ignore]` - tests marked with this attribute will be ``` ```shell -snforge test +$ snforge test ```
diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index ebd23f967a..c714109698 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -38,7 +38,7 @@ We can try to create a test that will increase and verify the balance. This test fails, which means that `increase_balance` method panics as we expected. ```shell -snforge test +$ snforge test ```
@@ -74,7 +74,7 @@ address, so it passes our validation. The test will now pass without an error ```shell -snforge test +$ snforge test ```
@@ -104,7 +104,7 @@ We will demonstrate its behavior using `SafeDispatcher` to show when exactly the ``` ```shell -snforge test +$ snforge test ```
From f10ac8ef7f3b6fa8d5da950598817656d2f42c9f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 15:18:35 +0100 Subject: [PATCH 008/183] Restore prompt in other shell snippets --- docs/src/development/environment-setup.md | 6 +++--- docs/src/getting-started/first-steps.md | 6 +++--- docs/src/getting-started/installation.md | 13 +++++++++---- docs/src/starknet/call.md | 6 ++++-- docs/src/testing/testing.md | 1 + 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index 3376c1c18e..62201e9d2f 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -11,7 +11,7 @@ Install the latest stable [Rust](https://www.rust-lang.org/tools/install) versio If you already have Rust installed make sure to upgrade it by running ```shell -rustup update +$ rustup update ``` ### Scarb @@ -86,7 +86,7 @@ Starknet Foundry uses [typos](https://github.com/marketplace/actions/typos-actio You can run the checker with ```shell -typos +$ typos ``` Some typos can be automatically fixed by running``` @@ -95,7 +95,7 @@ Some typos can be automatically fixed by running``` Output: ```shell -typos -w +$ typos -w ```
diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index f0e74b8c35..359d0846c8 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -12,8 +12,8 @@ $ snforge init project_name Let's check out the project structure ```shell -cd project_name -tree . -L 1 +$ cd project_name +$ tree . -L 1 ``` ```shell @@ -88,7 +88,7 @@ using [`scarb add`](https://docs.swmansion.com/scarb/docs/guides/dependencies.ht command. ```shell -scarb add snforge_std \ +$ scarb add snforge_std \ --dev \ --git https://github.com/foundry-rs/starknet-foundry.git \ --tag v0.27.0 diff --git a/docs/src/getting-started/installation.md b/docs/src/getting-started/installation.md index 9f59b52b12..3e18df8124 100644 --- a/docs/src/getting-started/installation.md +++ b/docs/src/getting-started/installation.md @@ -80,10 +80,15 @@ As for now, Starknet Foundry on Windows needs manual installation, but necessary 3. Add path to the snfoundry\bin directory to your PATH environment variable. 4. Verify installation by running the following command in new terminal session: -```shell -$ snforge --version -$ sncast --version -``` + ```shell + $ snforge --version + ``` + + and + + ``` + $ sncast --version + ``` ### Universal-Sierra-Compiler update diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 33bcee9184..9258fd5017 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -17,7 +17,9 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ### General Example ```shell -$ sncast call \ +$ sncast \ + call \ + --url http://127.0.0.1:5050 \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 @@ -45,7 +47,7 @@ $ sncast call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ --calldata 1 2 3 \ - --block-id 1234``` + --block-id 1234 ```
diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index b3d7272667..615879ed79 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -91,6 +91,7 @@ With this format, the expected error message needs to be a substring of the actu {{#include ../../listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo:tuple}} ``` + ```shell $ snforge test ``` From be9c9e5171bd5bfd28fdd8775411fa49c566522e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 15:20:55 +0100 Subject: [PATCH 009/183] Fix forge version check snippet --- docs/src/getting-started/first-steps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 359d0846c8..9f65a5c1f3 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -78,7 +78,7 @@ $ snforge --version Click to expand ```shell -$ snforge 0.27.0 +snforge 0.27.0 ```

From a17d9195107cd63eff08c9805e0868e9bbceb862 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 10 Nov 2024 15:26:53 +0100 Subject: [PATCH 010/183] Add JS script to remove prompt sign when copying code --- docs/book.toml | 2 +- docs/codeSnippets.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 docs/codeSnippets.js diff --git a/docs/book.toml b/docs/book.toml index 202324d063..fff7b3ef69 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -19,7 +19,7 @@ exclude = [ [output.html] git-repository-url = "https://github.com/foundry-rs/starknet-foundry/" edit-url-template = "https://github.com/foundry-rs/starknet-foundry/edit/master/docs/{path}" -additional-js = ["count.js"] +additional-js = ["count.js", "codeSnippets.js"] [output.html.playground] runnable = false diff --git a/docs/codeSnippets.js b/docs/codeSnippets.js new file mode 100644 index 0000000000..fbf8404603 --- /dev/null +++ b/docs/codeSnippets.js @@ -0,0 +1,29 @@ +/** + * Removes the initial prompt characters "$ " from the beginning of each line in a multiline string, if present. + * + * @param {string} text - The input string, potentially containing multiple lines with prompts at the beginning. + * @returns {string} - The modified string with initial prompts removed from each line, or the original lines if no prompt is present. + */ +function removePrompt(text) { + return text.split('\n').map(line => { + if (line.startsWith("$ ")) { + return line.slice(2); + } + return line; + }).join('\n'); +} + + +// Overwrite the default `playground_text` function which is used to extract the code from a playground. +function playground_text(playground, hidden = true) { + let code_block = playground.querySelector("code"); + + if (window.ace && code_block.classList.contains("editable")) { + let editor = window.ace.edit(code_block); + return removePrompt(editor.getValue()); + } else if (hidden) { + return removePrompt(code_block.textContent); + } else { + return removePrompt(code_block.innerText); + } +} From 432e3660cf358739e146741fcf3eba2d129ee2c1 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 11 Nov 2024 23:49:25 +0100 Subject: [PATCH 011/183] Add validation of sncast snippets --- Cargo.lock | 7 ++ crates/shared/Cargo.toml | 1 + .../shared/src/test_utils/docs_validation.rs | 76 +++++++++++++++++++ crates/shared/src/test_utils/mod.rs | 1 + crates/sncast/README.md | 23 ++++-- crates/sncast/tests/docs/mod.rs | 1 + crates/sncast/tests/docs/snippets.rs | 52 +++++++++++++ crates/sncast/tests/main.rs | 1 + docs/README.md | 4 +- docs/src/starknet/account.md | 12 ++- 10 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 crates/shared/src/test_utils/docs_validation.rs create mode 100644 crates/sncast/tests/docs/mod.rs create mode 100644 crates/sncast/tests/docs/snippets.rs diff --git a/Cargo.lock b/Cargo.lock index 5c2a1393f8..213e458580 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4772,12 +4772,19 @@ dependencies = [ "console", "regex", "semver", + "shell-words", "snapbox", "starknet", "starknet-types-core", "url", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shellexpand" version = "3.1.0" diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 02370a8e3f..a7c43b1c1b 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -13,3 +13,4 @@ starknet.workspace = true url.workspace = true regex.workspace = true snapbox.workspace = true +shell-words = "1.0.0" diff --git a/crates/shared/src/test_utils/docs_validation.rs b/crates/shared/src/test_utils/docs_validation.rs new file mode 100644 index 0000000000..d303fa7fc2 --- /dev/null +++ b/crates/shared/src/test_utils/docs_validation.rs @@ -0,0 +1,76 @@ +use regex::Regex; +use std::env; +use std::fs; +use std::io; +use std::path::Path; +use std::path::PathBuf; + +pub fn extract_content_from_file( + file_path: &Path, + re: &Regex, +) -> Result, std::io::Error> { + let content = fs::read_to_string(file_path)?; + let matches: Vec = re + .captures_iter(&content) + .filter_map(|caps| caps.get(1).map(|m| m.as_str().to_string())) + .collect(); + + Ok(matches) +} + +pub fn extract_from_directory( + dir_path: &Path, + re: &Regex, + extension: Option<&str>, +) -> io::Result> { + let mut all_snippets = Vec::new(); + + for entry in fs::read_dir(dir_path)? { + let entry = entry?; + let path = entry.path(); + + if path.is_dir() { + all_snippets.extend(extract_from_directory(&path, re, extension)?); + } else if let Some(ext) = extension { + if path.extension().and_then(|e| e.to_str()) == Some(ext) { + let snippets = extract_content_from_file(&path, re)?; + if !snippets.is_empty() { + all_snippets.extend(snippets); + } + } + } else { + let snippets = extract_content_from_file(&path, re)?; + if !snippets.is_empty() { + all_snippets.extend(snippets); + } + } + } + + Ok(all_snippets) +} + +#[must_use] +pub fn get_parent_dir(levels_up: usize) -> PathBuf { + let mut dir = env::current_dir().expect("Failed to get the current directory"); + + for _ in 0..levels_up { + dir = dir.parent().expect("Failed to navigate up").to_owned(); + } + + dir +} + +pub fn parse_snippet_str_to_command_args(snippet: &str) -> Vec { + let cleaned_snippet = snippet + .lines() + .map(str::trim_end) + .collect::>() + .join(" ") + .replace(" \\", ""); + + shell_words::split(&cleaned_snippet) + .expect("Failed to parse snippet string") + .into_iter() + .map(|arg| arg.trim().to_string()) + .collect() +} diff --git a/crates/shared/src/test_utils/mod.rs b/crates/shared/src/test_utils/mod.rs index ec44362ab1..213914ddac 100644 --- a/crates/shared/src/test_utils/mod.rs +++ b/crates/shared/src/test_utils/mod.rs @@ -1,2 +1,3 @@ +pub mod docs_validation; pub mod node_url; pub mod output_assert; diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 0b92258188..e2afe007da 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -33,9 +33,11 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ```shell $ sncast --account myuser \ - --url http://127.0.0.1:5050/rpc \ declare \ - --contract-name SimpleBalance + --url http://127.0.0.1:5050/rpc \ + --contract-name SimpleBalance \ + --version v3 +``` command: Declare class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a @@ -58,8 +60,10 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ```shell $ sncast --account myuser \ + deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --url http://127.0.0.1:5050/rpc \ - deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a + --version v3 +``` command: Deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a @@ -81,12 +85,15 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +$ sncast \ --account example_user \ invoke \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ - --calldata 1 2 3 + --calldata 1 2 3 \ + --url http://127.0.0.1:5050 \ + --version v3 +``` command: Invoke transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f @@ -108,11 +115,13 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Call a contract ```shell -$ sncast --url http://127.0.0.1:5050 \ +$ sncast \ call \ --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ --function "some_function" \ - --calldata 1 2 3 + --calldata 1 2 3 \ + --url http://127.0.0.1:5050 +``` command: call response: [0x0] diff --git a/crates/sncast/tests/docs/mod.rs b/crates/sncast/tests/docs/mod.rs new file mode 100644 index 0000000000..e46d64ed62 --- /dev/null +++ b/crates/sncast/tests/docs/mod.rs @@ -0,0 +1 @@ +mod snippets; diff --git a/crates/sncast/tests/docs/snippets.rs b/crates/sncast/tests/docs/snippets.rs new file mode 100644 index 0000000000..9ae88bf241 --- /dev/null +++ b/crates/sncast/tests/docs/snippets.rs @@ -0,0 +1,52 @@ +use crate::helpers::runner::runner; +use regex::Regex; +use shared::test_utils::docs_validation::{ + extract_from_directory, get_parent_dir, parse_snippet_str_to_command_args, +}; +use tempfile::tempdir; +#[test] +fn test_docs_snippets() { + let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); + let root_dir = get_parent_dir(2); + + let re = Regex::new(r"(?ms)```shell\n\$ sncast(.*?)").expect("Invalid regex pattern"); + let extension = Some("md"); + let snippets = extract_from_directory(&root_dir, &re, extension) + .expect("Failed to extract sncast command snippets"); + + let skipped_args = [ + // snippet "$ sncast " + vec![""], + // snippet with interactive import example + vec![ + "account", + "import", + "--url", + "http://127.0.0.1:5050", + "--name", + "account_123", + "--address", + "0x1", + "--type", + "oz", + ], + ]; + + for snippet in snippets.clone() { + let args = parse_snippet_str_to_command_args(snippet.as_str()); + let args: Vec<&str> = args.iter().map(String::as_str).collect(); + + if skipped_args.contains(&args) { + continue; + } + + let snapbox = runner(&args).current_dir(tempdir.path()); + let output = snapbox.output().expect("Failed to execute the command"); + let exit_code = output.status.code().unwrap_or_default(); + let stderr = String::from_utf8_lossy(&output.stderr); + + assert_ne!(exit_code, 2, "The command failed. Stderr: {stderr}"); + } + + println!("count: {}", snippets.len()); +} diff --git a/crates/sncast/tests/main.rs b/crates/sncast/tests/main.rs index 5465fce9b8..bce19f4f1f 100644 --- a/crates/sncast/tests/main.rs +++ b/crates/sncast/tests/main.rs @@ -1,3 +1,4 @@ +mod docs; mod e2e; pub mod helpers; mod integration; diff --git a/docs/README.md b/docs/README.md index 6d1038e299..8fe307381a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,11 +11,11 @@ cargo install mdbook ## Building ```shell -mdbook build +$ mdbook build ``` ## Open preview and reload on every change ```shell -mdbook serve +$ mdbook serve ``` \ No newline at end of file diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 598c57a866..74aa7f715c 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -60,19 +60,26 @@ You can do it both by sending tokens from another starknet account or by bridgin #### Deploy account with the `sncast account deploy` command ```shell -sncast \ - account deploy \ +$ sncast \ + account deploy \ --url http://127.0.0.1:5050 \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 +``` + +
+Output: +```shell command: account deploy transaction_hash: 0x20b20896ce63371ef015d66b4dd89bf18c5510a840b4a85a43a983caa6e2579 To see invocation details, visit: transaction: https://starkscan.co/search/0x20b20896ce... ``` +
+
For a detailed CLI description, see [account deploy command reference](../appendix/sncast/account/deploy.md). @@ -144,6 +151,7 @@ sncast \ --name some-name \ --url http://127.0.0.1:5050 \ --class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6 + --type oz ``` #### [`account create`](../appendix/sncast/account/create.md) With Salt Argument From f5f3e41bfa879d1dcb794217c977e8436da469c0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 01:59:12 +0100 Subject: [PATCH 012/183] Remove unnecessary else branch --- crates/shared/src/test_utils/docs_validation.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/shared/src/test_utils/docs_validation.rs b/crates/shared/src/test_utils/docs_validation.rs index d303fa7fc2..8f2553dadb 100644 --- a/crates/shared/src/test_utils/docs_validation.rs +++ b/crates/shared/src/test_utils/docs_validation.rs @@ -38,11 +38,6 @@ pub fn extract_from_directory( all_snippets.extend(snippets); } } - } else { - let snippets = extract_content_from_file(&path, re)?; - if !snippets.is_empty() { - all_snippets.extend(snippets); - } } } From beb0855264a2b4440dad2d0826bc700e4332600a Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:00:45 +0100 Subject: [PATCH 013/183] Fix left docs snippets --- design_documents/parametrizing_tests_with_fixed_values.md | 8 ++++++++ docs/src/getting-started/first-steps.md | 4 ++-- docs/src/starknet/account.md | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/design_documents/parametrizing_tests_with_fixed_values.md b/design_documents/parametrizing_tests_with_fixed_values.md index 8e5d26a407..6ed971fae4 100644 --- a/design_documents/parametrizing_tests_with_fixed_values.md +++ b/design_documents/parametrizing_tests_with_fixed_values.md @@ -120,6 +120,12 @@ An example output could look similarly to this: ```shell $ snforge test +``` + +
+Output: + +```shell [PASS] tests::parametrized(a = 1, b = 2) # unnamed test case [PASS] tests::parametrized[a_test](a = 3, b = 5) # named test case [FAIL] tests::parametrized[my_case](a = 4, b = 5) # named test case @@ -130,6 +136,8 @@ Failure data: [PASS] tests::parametrized(a = 5, b = 7) # ... ``` +
+
## Deterministic Test Output Order diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 9f65a5c1f3..98d2bd9e34 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -74,8 +74,8 @@ Make sure that the version in `tag` matches `snforge`. You can check the current $ snforge --version ``` -
-Click to expand +
+Output: ```shell snforge 0.27.0 diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 03b3cbf83a..27c9cc0809 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -42,7 +42,7 @@ message: Account successfully created. Prefund generated address with at least < To see account creation details, visit: account: https://starkscan.co/search/contract/34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b ``` -
+

For a detailed CLI description, see [account create command reference](../appendix/sncast/account/create.md). @@ -67,12 +67,18 @@ $ sncast \ --fee-token strk \ --max-fee 9999999999999 +
+Output: + +```shell command: account deploy transaction_hash: 0x20b20896ce63371ef015d66b4dd89bf18c5510a840b4a85a43a983caa6e2579 To see invocation details, visit: transaction: https://starkscan.co/search/0x20b20896ce... ``` +
+
For a detailed CLI description, see [account deploy command reference](../appendix/sncast/account/deploy.md). From 18ffce2633ce430d1b963be379147460b06cca67 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:07:46 +0100 Subject: [PATCH 014/183] Make `tree` snippet expandable in first steps section --- docs/src/getting-started/first-steps.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 98d2bd9e34..292f5c6e27 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -16,6 +16,9 @@ $ cd project_name $ tree . -L 1 ``` +
+Output: + ```shell . ├── Scarb.lock @@ -25,6 +28,8 @@ $ tree . -L 1 2 directories, 2 files ``` +
+
* `src/` contains source code of all your contracts. * `tests/` contains tests. From 1d7f2842d317894ee41972d81fc6d322b0ae3d11 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:10:10 +0100 Subject: [PATCH 015/183] Fix typo --- docs/src/development/environment-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/development/environment-setup.md b/docs/src/development/environment-setup.md index 62201e9d2f..8056968e73 100644 --- a/docs/src/development/environment-setup.md +++ b/docs/src/development/environment-setup.md @@ -89,7 +89,7 @@ You can run the checker with $ typos ``` -Some typos can be automatically fixed by running``` +Some typos can be automatically fixed by running
Output: From 48a3fcd895851a88b62915b04f460044d3d6eacf Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:10:46 +0100 Subject: [PATCH 016/183] Fix typo --- docs/src/starknet/deploy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 1caec3fd1f..d5d7e0229f 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -128,7 +128,7 @@ $ sncast deploy \ ```shell command: deploy contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303aa -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e``` +transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e Details: contract: https://starkscan.co/search/0x301316d47a... From 0438352044f26edc5f4f5f0532e135ae0d61952b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:11:50 +0100 Subject: [PATCH 017/183] Fix typos --- docs/src/starknet/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index a746c9510d..b6cf08ecb0 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -96,7 +96,7 @@ Received transaction. Status: Pending Received transaction. Status: Pending command: deploy contract_address: 0x1d91599ec661e97fdcbb10c642a1c4f920986f1a7a9659d157d0db09baaa29e -transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983``` +transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 To see deployment details, visit: contract: https://starkscan.co/search/0x1d91599ec6... From dca617db3a958a054e0caa566fec6c6c3ce0d963 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:31:31 +0100 Subject: [PATCH 018/183] Improve sncast snippets validation test --- crates/sncast/tests/docs/snippets.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/sncast/tests/docs/snippets.rs b/crates/sncast/tests/docs/snippets.rs index 9ae88bf241..4c2f613662 100644 --- a/crates/sncast/tests/docs/snippets.rs +++ b/crates/sncast/tests/docs/snippets.rs @@ -4,20 +4,22 @@ use shared::test_utils::docs_validation::{ extract_from_directory, get_parent_dir, parse_snippet_str_to_command_args, }; use tempfile::tempdir; + #[test] fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); let root_dir = get_parent_dir(2); - let re = Regex::new(r"(?ms)```shell\n\$ sncast(.*?)").expect("Invalid regex pattern"); + let re = Regex::new(r"(?ms)```shell\n\$ sncast(.*?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); let snippets = extract_from_directory(&root_dir, &re, extension) .expect("Failed to extract sncast command snippets"); + // Snippets with following args are skipped let skipped_args = [ // snippet "$ sncast " vec![""], - // snippet with interactive import example + // snippet with interactive account import example vec![ "account", "import", @@ -45,8 +47,14 @@ fn test_docs_snippets() { let exit_code = output.status.code().unwrap_or_default(); let stderr = String::from_utf8_lossy(&output.stderr); - assert_ne!(exit_code, 2, "The command failed. Stderr: {stderr}"); - } + assert_ne!( + exit_code, 2, + "The command {snippet} failed. Stderr: {stderr}" + ); - println!("count: {}", snippets.len()); + println!( + "Validated {} sncast command snippets in the docs", + snippets.len() + ); + } } From 3ae31079dba288294f6557a43797c170ba75d2b1 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:37:34 +0100 Subject: [PATCH 019/183] Fix printing number of validated snippets in sncast test --- crates/sncast/tests/docs/snippets.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/sncast/tests/docs/snippets.rs b/crates/sncast/tests/docs/snippets.rs index 4c2f613662..8782a8060e 100644 --- a/crates/sncast/tests/docs/snippets.rs +++ b/crates/sncast/tests/docs/snippets.rs @@ -51,10 +51,10 @@ fn test_docs_snippets() { exit_code, 2, "The command {snippet} failed. Stderr: {stderr}" ); - - println!( - "Validated {} sncast command snippets in the docs", - snippets.len() - ); } + + println!( + "Validated {} sncast command snippets in the docs", + snippets.len() + ); } From 2f65010387727f889577835fb053fab6ef3701b0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:46:51 +0100 Subject: [PATCH 020/183] Add snforge docs snippets validation test --- crates/forge/tests/e2e/docs_snippets.rs | 38 +++++++++++++++++++ crates/forge/tests/e2e/mod.rs | 1 + .../shared/src/test_utils/docs_validation.rs | 5 ++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 crates/forge/tests/e2e/docs_snippets.rs diff --git a/crates/forge/tests/e2e/docs_snippets.rs b/crates/forge/tests/e2e/docs_snippets.rs new file mode 100644 index 0000000000..f7947f4877 --- /dev/null +++ b/crates/forge/tests/e2e/docs_snippets.rs @@ -0,0 +1,38 @@ +use crate::e2e::common::runner::{setup_package, test_runner}; + +use regex::Regex; +use shared::test_utils::docs_validation::{ + extract_from_directory, get_parent_dir, parse_snippet_str_to_command_args, +}; + +#[test] +fn test_docs_snippets() { + let temp = setup_package("erc20_package"); + let root_dir = get_parent_dir(4); + + let re = Regex::new(r"(?ms)```shell\n\$ snforge(.*?)\n```").expect("Invalid regex pattern"); + + let extension = Some("md"); + let snippets = extract_from_directory(&root_dir, &re, extension) + .expect("Failed to extract snforge command snippets"); + + for snippet in snippets.clone() { + let args = parse_snippet_str_to_command_args(snippet.as_str()); + let args: Vec<&str> = args.iter().map(String::as_str).collect(); + + let snapbox = test_runner(&temp).args(args); + let output = snapbox.output().expect("Failed to execute the command"); + let exit_code = output.status.code().unwrap_or_default(); + let stderr = String::from_utf8_lossy(&output.stderr); + println!("snippet: {}", snippet); + assert_ne!( + exit_code, 2, + "The command {snippet} failed. Stderr: {stderr}" + ); + } + + println!( + "Validated {} snforge command snippets in the docs", + snippets.len() + ); +} diff --git a/crates/forge/tests/e2e/mod.rs b/crates/forge/tests/e2e/mod.rs index f67f9a7544..1e6cefeef8 100644 --- a/crates/forge/tests/e2e/mod.rs +++ b/crates/forge/tests/e2e/mod.rs @@ -7,6 +7,7 @@ mod color; mod components; mod contract_artifacts; mod coverage; +mod docs_snippets; mod env; mod features; mod fork_warning; diff --git a/crates/shared/src/test_utils/docs_validation.rs b/crates/shared/src/test_utils/docs_validation.rs index 8f2553dadb..dff5dfb5fa 100644 --- a/crates/shared/src/test_utils/docs_validation.rs +++ b/crates/shared/src/test_utils/docs_validation.rs @@ -49,7 +49,10 @@ pub fn get_parent_dir(levels_up: usize) -> PathBuf { let mut dir = env::current_dir().expect("Failed to get the current directory"); for _ in 0..levels_up { - dir = dir.parent().expect("Failed to navigate up").to_owned(); + dir = dir + .parent() + .expect("Failed to navigate to parent directory") + .to_owned(); } dir From efc2e1d2d92d48b1d5e4d5e8d3f479975084b02e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 02:50:06 +0100 Subject: [PATCH 021/183] Remove print --- crates/forge/tests/e2e/docs_snippets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets.rs b/crates/forge/tests/e2e/docs_snippets.rs index f7947f4877..e1447d929f 100644 --- a/crates/forge/tests/e2e/docs_snippets.rs +++ b/crates/forge/tests/e2e/docs_snippets.rs @@ -24,7 +24,7 @@ fn test_docs_snippets() { let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); let stderr = String::from_utf8_lossy(&output.stderr); - println!("snippet: {}", snippet); + assert_ne!( exit_code, 2, "The command {snippet} failed. Stderr: {stderr}" From 1b968be5ed6140cfb4e4c3464f5f48a5ab22a7cd Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 15:37:08 +0100 Subject: [PATCH 022/183] Move docs validation into separate crate --- Cargo.lock | 10 +++++++++- Cargo.toml | 2 ++ crates/docs/Cargo.toml | 11 +++++++++++ crates/docs/src/lib.rs | 5 +++++ .../docs_validation.rs => docs/src/validation.rs} | 11 ++++------- crates/forge/Cargo.toml | 1 + ...docs_snippets.rs => docs_snippets_validation.rs} | 13 +++++++------ crates/forge/tests/e2e/mod.rs | 2 +- crates/shared/Cargo.toml | 1 - crates/shared/src/test_utils/mod.rs | 1 - crates/sncast/tests/docs/mod.rs | 1 - crates/sncast/tests/docs_snippets/mod.rs | 1 + .../snippets.rs => docs_snippets/validation.rs} | 13 +++++++------ crates/sncast/tests/main.rs | 2 +- 14 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 crates/docs/Cargo.toml create mode 100644 crates/docs/src/lib.rs rename crates/{shared/src/test_utils/docs_validation.rs => docs/src/validation.rs} (84%) rename crates/forge/tests/e2e/{docs_snippets.rs => docs_snippets_validation.rs} (74%) delete mode 100644 crates/sncast/tests/docs/mod.rs create mode 100644 crates/sncast/tests/docs_snippets/mod.rs rename crates/sncast/tests/{docs/snippets.rs => docs_snippets/validation.rs} (80%) diff --git a/Cargo.lock b/Cargo.lock index 15ee7c6342..ce4275aefe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1889,6 +1889,14 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "docs" +version = "0.33.0" +dependencies = [ + "regex", + "shell-words", +] + [[package]] name = "dyn-clone" version = "1.0.17" @@ -2157,6 +2165,7 @@ dependencies = [ "configuration", "console", "conversions", + "docs", "flatten-serde-json", "forge_runner", "fs_extra", @@ -4773,7 +4782,6 @@ dependencies = [ "console", "regex", "semver", - "shell-words", "snapbox", "starknet", "starknet-types-core", diff --git a/Cargo.toml b/Cargo.toml index f4771d1006..a6a6375380 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ members = [ "crates/configuration", "crates/universal-sierra-compiler-api", "crates/snforge-scarb-plugin", + "crates/docs", ] [workspace.package] @@ -82,6 +83,7 @@ project-root = "0.2.2" which = "5.0.0" conversions = { path = "./crates/conversions" } shared = { path = "./crates/shared" } +docs = { path = "./crates/docs" } test-case = "3.1.0" scarb-metadata = "1.13.0" flatten-serde-json = "0.1.0" diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml new file mode 100644 index 0000000000..4767ec29cd --- /dev/null +++ b/crates/docs/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "docs" +version.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true +license-file.workspace = true + +[dependencies] +regex = "1.11.1" +shell-words = "1.1.0" \ No newline at end of file diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs new file mode 100644 index 0000000000..22049671cb --- /dev/null +++ b/crates/docs/src/lib.rs @@ -0,0 +1,5 @@ +pub mod validation; + +pub use validation::{ + extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, +}; diff --git a/crates/shared/src/test_utils/docs_validation.rs b/crates/docs/src/validation.rs similarity index 84% rename from crates/shared/src/test_utils/docs_validation.rs rename to crates/docs/src/validation.rs index dff5dfb5fa..05ccb4bdc8 100644 --- a/crates/shared/src/test_utils/docs_validation.rs +++ b/crates/docs/src/validation.rs @@ -5,10 +5,7 @@ use std::io; use std::path::Path; use std::path::PathBuf; -pub fn extract_content_from_file( - file_path: &Path, - re: &Regex, -) -> Result, std::io::Error> { +fn extract_matches_from_file(file_path: &Path, re: &Regex) -> Result, std::io::Error> { let content = fs::read_to_string(file_path)?; let matches: Vec = re .captures_iter(&content) @@ -18,7 +15,7 @@ pub fn extract_content_from_file( Ok(matches) } -pub fn extract_from_directory( +pub fn extract_matches_from_directory( dir_path: &Path, re: &Regex, extension: Option<&str>, @@ -30,10 +27,10 @@ pub fn extract_from_directory( let path = entry.path(); if path.is_dir() { - all_snippets.extend(extract_from_directory(&path, re, extension)?); + all_snippets.extend(extract_matches_from_directory(&path, re, extension)?); } else if let Some(ext) = extension { if path.extension().and_then(|e| e.to_str()) == Some(ext) { - let snippets = extract_content_from_file(&path, re)?; + let snippets = extract_matches_from_file(&path, re)?; if !snippets.is_empty() { all_snippets.extend(snippets); } diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index a9279a63fd..4c10dfac01 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -67,6 +67,7 @@ url.workspace = true fs_extra.workspace = true project-root.workspace = true indoc.workspace = true +docs.workspace = true [[bin]] name = "snforge" diff --git a/crates/forge/tests/e2e/docs_snippets.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs similarity index 74% rename from crates/forge/tests/e2e/docs_snippets.rs rename to crates/forge/tests/e2e/docs_snippets_validation.rs index e1447d929f..bc9b568cc2 100644 --- a/crates/forge/tests/e2e/docs_snippets.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,22 +1,23 @@ use crate::e2e::common::runner::{setup_package, test_runner}; - -use regex::Regex; -use shared::test_utils::docs_validation::{ - extract_from_directory, get_parent_dir, parse_snippet_str_to_command_args, +use docs::validation::{ + extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, }; +use regex::Regex; #[test] fn test_docs_snippets() { let temp = setup_package("erc20_package"); let root_dir = get_parent_dir(4); - let re = Regex::new(r"(?ms)```shell\n\$ snforge(.*?)\n```").expect("Invalid regex pattern"); + let re = + Regex::new(r"(?ms)\`\`\`shell\n\$ snforge (.+?)\n\`\`\`").expect("Invalid regex pattern"); let extension = Some("md"); - let snippets = extract_from_directory(&root_dir, &re, extension) + let snippets = extract_matches_from_directory(&root_dir, &re, extension) .expect("Failed to extract snforge command snippets"); for snippet in snippets.clone() { + println!("SNIPPET: {}", snippet); let args = parse_snippet_str_to_command_args(snippet.as_str()); let args: Vec<&str> = args.iter().map(String::as_str).collect(); diff --git a/crates/forge/tests/e2e/mod.rs b/crates/forge/tests/e2e/mod.rs index 1e6cefeef8..9e8d060115 100644 --- a/crates/forge/tests/e2e/mod.rs +++ b/crates/forge/tests/e2e/mod.rs @@ -7,7 +7,7 @@ mod color; mod components; mod contract_artifacts; mod coverage; -mod docs_snippets; +mod docs_snippets_validation; mod env; mod features; mod fork_warning; diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index a7c43b1c1b..02370a8e3f 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -13,4 +13,3 @@ starknet.workspace = true url.workspace = true regex.workspace = true snapbox.workspace = true -shell-words = "1.0.0" diff --git a/crates/shared/src/test_utils/mod.rs b/crates/shared/src/test_utils/mod.rs index 213914ddac..ec44362ab1 100644 --- a/crates/shared/src/test_utils/mod.rs +++ b/crates/shared/src/test_utils/mod.rs @@ -1,3 +1,2 @@ -pub mod docs_validation; pub mod node_url; pub mod output_assert; diff --git a/crates/sncast/tests/docs/mod.rs b/crates/sncast/tests/docs/mod.rs deleted file mode 100644 index e46d64ed62..0000000000 --- a/crates/sncast/tests/docs/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod snippets; diff --git a/crates/sncast/tests/docs_snippets/mod.rs b/crates/sncast/tests/docs_snippets/mod.rs new file mode 100644 index 0000000000..ff0ee8b68f --- /dev/null +++ b/crates/sncast/tests/docs_snippets/mod.rs @@ -0,0 +1 @@ +mod validation; diff --git a/crates/sncast/tests/docs/snippets.rs b/crates/sncast/tests/docs_snippets/validation.rs similarity index 80% rename from crates/sncast/tests/docs/snippets.rs rename to crates/sncast/tests/docs_snippets/validation.rs index 8782a8060e..82dfab6fd7 100644 --- a/crates/sncast/tests/docs/snippets.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,8 +1,8 @@ use crate::helpers::runner::runner; -use regex::Regex; -use shared::test_utils::docs_validation::{ - extract_from_directory, get_parent_dir, parse_snippet_str_to_command_args, +use docs::validation::{ + extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, }; +use regex::Regex; use tempfile::tempdir; #[test] @@ -10,9 +10,9 @@ fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); let root_dir = get_parent_dir(2); - let re = Regex::new(r"(?ms)```shell\n\$ sncast(.*?)\n```").expect("Invalid regex pattern"); + let re = Regex::new(r"(?ms)```shell\n\$ sncast (.+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); - let snippets = extract_from_directory(&root_dir, &re, extension) + let snippets = extract_matches_from_directory(&root_dir, &re, extension) .expect("Failed to extract sncast command snippets"); // Snippets with following args are skipped @@ -41,7 +41,8 @@ fn test_docs_snippets() { if skipped_args.contains(&args) { continue; } - + println!("SNCAST SNIPPET: {}", snippet); + println!("SNCAST ARGS: {:?}", args); let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); diff --git a/crates/sncast/tests/main.rs b/crates/sncast/tests/main.rs index bce19f4f1f..255cc634cd 100644 --- a/crates/sncast/tests/main.rs +++ b/crates/sncast/tests/main.rs @@ -1,4 +1,4 @@ -mod docs; +mod docs_snippets; mod e2e; pub mod helpers; mod integration; From 7bbcd994db0ae5b051f5fef0579cc8846de30334 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 15:39:41 +0100 Subject: [PATCH 023/183] Fix newline --- crates/docs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index 4767ec29cd..70ba2886ac 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -8,4 +8,4 @@ license-file.workspace = true [dependencies] regex = "1.11.1" -shell-words = "1.1.0" \ No newline at end of file +shell-words = "1.1.0" From bdcd4679c31961c50ad4442cb53528fe891f6b89 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 15:59:54 +0100 Subject: [PATCH 024/183] Update `Cargo.toml` in `sncast` --- crates/sncast/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/sncast/Cargo.toml b/crates/sncast/Cargo.toml index 142234b81a..eefec05a44 100644 --- a/crates/sncast/Cargo.toml +++ b/crates/sncast/Cargo.toml @@ -56,6 +56,7 @@ serde_path_to_error.workspace = true walkdir.workspace = true const-hex.workspace = true regex.workspace = true +docs.workspace = true [dev-dependencies] ctor.workspace = true From b6db6a511e1ba80eb2b9d1de084873f6c520bf7d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 16:02:29 +0100 Subject: [PATCH 025/183] Test cast docs validation test --- crates/sncast/tests/docs_snippets/validation.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 82dfab6fd7..bc7c785b1b 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -10,7 +10,7 @@ fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); let root_dir = get_parent_dir(2); - let re = Regex::new(r"(?ms)```shell\n\$ sncast (.+?)\n```").expect("Invalid regex pattern"); + let re = Regex::new(r"(?ms)```shell\n\$ sncast(.+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); let snippets = extract_matches_from_directory(&root_dir, &re, extension) .expect("Failed to extract sncast command snippets"); @@ -41,8 +41,7 @@ fn test_docs_snippets() { if skipped_args.contains(&args) { continue; } - println!("SNCAST SNIPPET: {}", snippet); - println!("SNCAST ARGS: {:?}", args); + let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); From a4535cdfd544c4793fd1d6fec617344892256920 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 12 Nov 2024 16:03:34 +0100 Subject: [PATCH 026/183] Fix linting --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index bc9b568cc2..a42f16350b 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -17,7 +17,7 @@ fn test_docs_snippets() { .expect("Failed to extract snforge command snippets"); for snippet in snippets.clone() { - println!("SNIPPET: {}", snippet); + println!("SNIPPET: {snippet}"); let args = parse_snippet_str_to_command_args(snippet.as_str()); let args: Vec<&str> = args.iter().map(String::as_str).collect(); From dcd4e8093be4b04c271a192cd7ff52efd2a70530 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 13 Nov 2024 02:23:27 +0100 Subject: [PATCH 027/183] Cleanup sncast snippets validation test --- .../sncast/tests/docs_snippets/validation.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index bc7c785b1b..374f8344ed 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,7 @@ use crate::helpers::runner::runner; use docs::validation::{ - extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, + extract_matches_from_directory, extract_matches_from_file, get_parent_dir, + parse_snippet_str_to_command_args, }; use regex::Regex; use tempfile::tempdir; @@ -8,14 +9,24 @@ use tempfile::tempdir; #[test] fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); - let root_dir = get_parent_dir(2); + let root_dir_path = get_parent_dir(2); + let docs_dir_path = root_dir_path.join("docs/src"); + let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); let re = Regex::new(r"(?ms)```shell\n\$ sncast(.+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); - let snippets = extract_matches_from_directory(&root_dir, &re, extension) + let docs_snippets = extract_matches_from_directory(&docs_dir_path, &re, extension) .expect("Failed to extract sncast command snippets"); - // Snippets with following args are skipped + println!("sncast_readme_path: {:?}", sncast_readme_path); + let readme_snippets = extract_matches_from_file(&sncast_readme_path, &re) + .expect("Failed to extract sncast command snippets"); + + let snippets = docs_snippets + .into_iter() + .chain(readme_snippets.into_iter()) + .collect::>(); + let skipped_args = [ // snippet "$ sncast " vec![""], From 9e3479782bdc4c715edf63095162990f17175057 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 13 Nov 2024 03:02:28 +0100 Subject: [PATCH 028/183] Minor refactor of forge snippets validation test --- crates/docs/src/validation.rs | 6 +++++- crates/forge/tests/e2e/docs_snippets_validation.rs | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 05ccb4bdc8..ca385e2e32 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -5,7 +5,10 @@ use std::io; use std::path::Path; use std::path::PathBuf; -fn extract_matches_from_file(file_path: &Path, re: &Regex) -> Result, std::io::Error> { +pub fn extract_matches_from_file( + file_path: &Path, + re: &Regex, +) -> Result, std::io::Error> { let content = fs::read_to_string(file_path)?; let matches: Vec = re .captures_iter(&content) @@ -31,6 +34,7 @@ pub fn extract_matches_from_directory( } else if let Some(ext) = extension { if path.extension().and_then(|e| e.to_str()) == Some(ext) { let snippets = extract_matches_from_file(&path, re)?; + if !snippets.is_empty() { all_snippets.extend(snippets); } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a42f16350b..946e0a9512 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -7,13 +7,13 @@ use regex::Regex; #[test] fn test_docs_snippets() { let temp = setup_package("erc20_package"); - let root_dir = get_parent_dir(4); + let root_dir = get_parent_dir(2); + let docs_dir = root_dir.join("docs/src"); - let re = - Regex::new(r"(?ms)\`\`\`shell\n\$ snforge (.+?)\n\`\`\`").expect("Invalid regex pattern"); + let re = Regex::new(r"(?ms)```shell\n\$ snforge(.+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); - let snippets = extract_matches_from_directory(&root_dir, &re, extension) + let snippets = extract_matches_from_directory(&docs_dir, &re, extension) .expect("Failed to extract snforge command snippets"); for snippet in snippets.clone() { @@ -26,6 +26,7 @@ fn test_docs_snippets() { let exit_code = output.status.code().unwrap_or_default(); let stderr = String::from_utf8_lossy(&output.stderr); + // TODO: Change logic of validating forge commands assert_ne!( exit_code, 2, "The command {snippet} failed. Stderr: {stderr}" From 8ddc8505174abfb4f089da8f3b34753ec3cb8e53 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 13 Nov 2024 03:03:29 +0100 Subject: [PATCH 029/183] Fix linting --- crates/sncast/tests/docs_snippets/validation.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 374f8344ed..1a32632237 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -18,13 +18,12 @@ fn test_docs_snippets() { let docs_snippets = extract_matches_from_directory(&docs_dir_path, &re, extension) .expect("Failed to extract sncast command snippets"); - println!("sncast_readme_path: {:?}", sncast_readme_path); let readme_snippets = extract_matches_from_file(&sncast_readme_path, &re) .expect("Failed to extract sncast command snippets"); let snippets = docs_snippets .into_iter() - .chain(readme_snippets.into_iter()) + .chain(readme_snippets) .collect::>(); let skipped_args = [ From 8e6678c7df409a82b84488e3de894cb1f32fe68f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 13 Nov 2024 03:03:49 +0100 Subject: [PATCH 030/183] Update `Cargo.lock` --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index ce4275aefe..8be0f1c827 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4912,6 +4912,7 @@ dependencies = [ "conversions", "ctor", "data-transformer", + "docs", "fs_extra", "indoc", "itertools 0.12.1", From 92fff9fabbb6fda3e2d3ec562d355eb876034185 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 14 Nov 2024 19:22:18 +0100 Subject: [PATCH 031/183] Fix deploy contract snippet --- crates/sncast/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 0344ec4aea..906bcc6c88 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -73,7 +73,6 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 $ sncast --account myuser \ deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ --url http://127.0.0.1:5050/rpc \ - deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a ```
From d44553142f13ad89e23ba887740092b83aec1e3d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 10:38:37 +0100 Subject: [PATCH 032/183] Use `try_parse_from` in forge docs snippets validation --- crates/docs/src/lib.rs | 4 -- crates/docs/src/validation.rs | 2 +- crates/forge/src/lib.rs | 2 +- .../tests/e2e/docs_snippets_validation.rs | 37 +++++++------------ 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index 22049671cb..8695201df0 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -1,5 +1 @@ pub mod validation; - -pub use validation::{ - extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, -}; diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index ca385e2e32..b5c2e88482 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -59,7 +59,7 @@ pub fn get_parent_dir(levels_up: usize) -> PathBuf { dir } -pub fn parse_snippet_str_to_command_args(snippet: &str) -> Vec { +pub fn snippet_to_command_args(snippet: &str) -> Vec { let cleaned_snippet = snippet .lines() .map(str::trim_end) diff --git a/crates/forge/src/lib.rs b/crates/forge/src/lib.rs index 6753def0f8..13eb286806 100644 --- a/crates/forge/src/lib.rs +++ b/crates/forge/src/lib.rs @@ -53,7 +53,7 @@ Report bugs: https://github.com/foundry-rs/starknet-foundry/issues/new/choose\ )] #[command(about = "snforge - a testing tool for Starknet contracts", long_about = None)] #[clap(name = "snforge")] -struct Cli { +pub struct Cli { #[command(subcommand)] subcommand: ForgeSubcommand, } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 946e0a9512..d1efc6f5cd 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,40 +1,29 @@ -use crate::e2e::common::runner::{setup_package, test_runner}; -use docs::validation::{ - extract_matches_from_directory, get_parent_dir, parse_snippet_str_to_command_args, -}; +use clap::Parser; +use docs::validation::{extract_matches_from_directory, get_parent_dir, snippet_to_command_args}; +use forge::Cli; use regex::Regex; - #[test] fn test_docs_snippets() { - let temp = setup_package("erc20_package"); let root_dir = get_parent_dir(2); let docs_dir = root_dir.join("docs/src"); - let re = Regex::new(r"(?ms)```shell\n\$ snforge(.+?)\n```").expect("Invalid regex pattern"); - + let re = Regex::new(r"(?ms)```shell\n\$ (snforge .+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); + let snippets = extract_matches_from_directory(&docs_dir, &re, extension) .expect("Failed to extract snforge command snippets"); - for snippet in snippets.clone() { - println!("SNIPPET: {snippet}"); - let args = parse_snippet_str_to_command_args(snippet.as_str()); + for snippet in snippets { + let args = snippet_to_command_args(snippet.as_str()); let args: Vec<&str> = args.iter().map(String::as_str).collect(); - let snapbox = test_runner(&temp).args(args); - let output = snapbox.output().expect("Failed to execute the command"); - let exit_code = output.status.code().unwrap_or_default(); - let stderr = String::from_utf8_lossy(&output.stderr); + let parse_result = Cli::try_parse_from(args); - // TODO: Change logic of validating forge commands - assert_ne!( - exit_code, 2, - "The command {snippet} failed. Stderr: {stderr}" + assert!( + parse_result.is_ok(), + "Found invalid snforge snippet in the docs: {:?}\nError: {}", + snippet, + parse_result.err().unwrap() ); } - - println!( - "Validated {} snforge command snippets in the docs", - snippets.len() - ); } From 46aa9d485157199ffa37511d5afcd5f8914654f2 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 11:05:13 +0100 Subject: [PATCH 033/183] Add skipped args in forge --- crates/forge/tests/e2e/docs_snippets_validation.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index d1efc6f5cd..7c77c4b9c1 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -13,15 +13,24 @@ fn test_docs_snippets() { let snippets = extract_matches_from_directory(&docs_dir, &re, extension) .expect("Failed to extract snforge command snippets"); + let skipped_args = [ + // for some reason `try_parse_from` fails on `--version` flag + vec!["snforge", "--version"], + ]; + for snippet in snippets { let args = snippet_to_command_args(snippet.as_str()); let args: Vec<&str> = args.iter().map(String::as_str).collect(); + if skipped_args.contains(&args) { + continue; + } + let parse_result = Cli::try_parse_from(args); assert!( parse_result.is_ok(), - "Found invalid snforge snippet in the docs: {:?}\nError: {}", + "Found invalid snforge snippet in the docs: {:?}\n{}", snippet, parse_result.err().unwrap() ); From 1dd0062c1a2aa36c748aca1fda96d398c4b66038 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 11:05:35 +0100 Subject: [PATCH 034/183] Refactor snippets validation test in cast --- .../sncast/tests/docs_snippets/validation.rs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 1a32632237..01955959fd 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,19 +1,21 @@ -use crate::helpers::runner::runner; use docs::validation::{ extract_matches_from_directory, extract_matches_from_file, get_parent_dir, - parse_snippet_str_to_command_args, + snippet_to_command_args, }; use regex::Regex; use tempfile::tempdir; +use crate::helpers::runner::runner; + #[test] fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); + let root_dir_path = get_parent_dir(2); let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); - let re = Regex::new(r"(?ms)```shell\n\$ sncast(.+?)\n```").expect("Invalid regex pattern"); + let re = Regex::new(r"(?ms)```shell\n\$ (sncast .+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); let docs_snippets = extract_matches_from_directory(&docs_dir_path, &re, extension) .expect("Failed to extract sncast command snippets"); @@ -45,8 +47,9 @@ fn test_docs_snippets() { ]; for snippet in snippets.clone() { - let args = parse_snippet_str_to_command_args(snippet.as_str()); - let args: Vec<&str> = args.iter().map(String::as_str).collect(); + let args = snippet_to_command_args(snippet.as_str()); + let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); + args.remove(0); if skipped_args.contains(&args) { continue; @@ -59,12 +62,8 @@ fn test_docs_snippets() { assert_ne!( exit_code, 2, - "The command {snippet} failed. Stderr: {stderr}" + "Found invalid sncast snippet in the docs: {:?}\n{}", + snippet, stderr ); } - - println!( - "Validated {} sncast command snippets in the docs", - snippets.len() - ); } From 80e5b791465ebc9718dd4b52c9d94cd7d032a581 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 11:15:03 +0100 Subject: [PATCH 035/183] Add todo --- crates/sncast/tests/docs_snippets/validation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 01955959fd..a916a9ca72 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -7,6 +7,8 @@ use tempfile::tempdir; use crate::helpers::runner::runner; +// TODO(#2678) +// While refactoring, please refer to respective test in forge #[test] fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); From 54f42475b7f9ac23fe9ff6028f2cddc0f78d07e0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 11:21:52 +0100 Subject: [PATCH 036/183] Code cleanup --- crates/docs/src/validation.rs | 25 ++++++++----------- .../sncast/tests/docs_snippets/validation.rs | 3 +-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index b5c2e88482..344ca7657d 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -1,9 +1,8 @@ use regex::Regex; -use std::env; -use std::fs; -use std::io; -use std::path::Path; -use std::path::PathBuf; +use std::{ + env, fs, io, + path::{Path, PathBuf}, +}; pub fn extract_matches_from_file( file_path: &Path, @@ -26,19 +25,15 @@ pub fn extract_matches_from_directory( let mut all_snippets = Vec::new(); for entry in fs::read_dir(dir_path)? { - let entry = entry?; - let path = entry.path(); + let path = entry?.path(); if path.is_dir() { all_snippets.extend(extract_matches_from_directory(&path, re, extension)?); - } else if let Some(ext) = extension { - if path.extension().and_then(|e| e.to_str()) == Some(ext) { - let snippets = extract_matches_from_file(&path, re)?; - - if !snippets.is_empty() { - all_snippets.extend(snippets); - } - } + } else if extension.map_or(true, |ext| { + path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) + }) { + let snippets = extract_matches_from_file(&path, re)?; + all_snippets.extend(snippets); } } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index a916a9ca72..0efdf4e7b7 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -64,8 +64,7 @@ fn test_docs_snippets() { assert_ne!( exit_code, 2, - "Found invalid sncast snippet in the docs: {:?}\n{}", - snippet, stderr + "Found invalid sncast snippet in the docs: {snippet}\n{stderr}" ); } } From fab960d4e7b9b8e4d91ec7784788eb5a635c60b3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 15 Nov 2024 11:52:01 +0100 Subject: [PATCH 037/183] Fix typos --- docs/src/getting-started/first-steps.md | 2 -- docs/src/starknet/fees-and-versions.md | 1 - 2 files changed, 3 deletions(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 2d51b96462..c59dcbfd29 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -78,8 +78,6 @@ Make sure that the above version matches the installed `snforge` version. You ca ```shell $ snforge --version ``` -
-
Output: diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 6c2fe7cb5a..918ec8374c 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -57,7 +57,6 @@ $ sncast account deploy \ --version v1 \ --max-fee 9999999999999 ``` -
> 📝 **Note** > The unit used in `--max-fee` flag is the smallest unit of the given fee token. For ETH it is Wei, for STRK it is Fri. From f119e3bd9616c5bd48ea2ced9d2b5c282a5baf09 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 02:44:04 +0100 Subject: [PATCH 038/183] Minor fixes in docs --- docs/src/getting-started/first-steps.md | 1 + docs/src/snforge-advanced-features/conditional-compilation.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index c59dcbfd29..08833008cf 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -23,6 +23,7 @@ $ tree . -L 1 . ├── Scarb.lock ├── Scarb.toml +├── snfoundry.toml ├── src └── tests diff --git a/docs/src/snforge-advanced-features/conditional-compilation.md b/docs/src/snforge-advanced-features/conditional-compilation.md index 28cdc2ba7f..1120cf4f79 100644 --- a/docs/src/snforge-advanced-features/conditional-compilation.md +++ b/docs/src/snforge-advanced-features/conditional-compilation.md @@ -39,8 +39,8 @@ enable_for_tests = [] Then, to use the contract in tests `snforge test` must be provided with a flag defined above: -``` -snforge test --features enable_for_tests +```shell +$ snforge test --features enable_for_tests ``` Also, we can specify which features are going to be enabled by default: From 853c8ed2258dcee6a4df871a4312df37a1a2ade0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 02:44:36 +0100 Subject: [PATCH 039/183] Remove `license-file.workspace` from docs crate --- crates/docs/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index 70ba2886ac..602383d434 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -4,7 +4,6 @@ version.workspace = true edition.workspace = true repository.workspace = true license.workspace = true -license-file.workspace = true [dependencies] regex = "1.11.1" From f6a029c6f847414a8785c39eae7b70f1e3641765 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 09:47:47 +0100 Subject: [PATCH 040/183] Move todo --- crates/sncast/tests/docs_snippets/validation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 0efdf4e7b7..f2f60fe4d1 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -7,8 +7,6 @@ use tempfile::tempdir; use crate::helpers::runner::runner; -// TODO(#2678) -// While refactoring, please refer to respective test in forge #[test] fn test_docs_snippets() { let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); @@ -57,6 +55,8 @@ fn test_docs_snippets() { continue; } + // TODO(#2678): Before running the command we should check it it's at least valid + let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); From 41cb86ab8bb86a800fbf0cdb4d0f57816a815ea8 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 10:05:26 +0100 Subject: [PATCH 041/183] Show validated snippets number --- crates/forge/tests/e2e/docs_snippets_validation.rs | 7 ++++++- crates/sncast/tests/docs_snippets/validation.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 7c77c4b9c1..5b93738d04 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -18,7 +18,7 @@ fn test_docs_snippets() { vec!["snforge", "--version"], ]; - for snippet in snippets { + for snippet in &snippets { let args = snippet_to_command_args(snippet.as_str()); let args: Vec<&str> = args.iter().map(String::as_str).collect(); @@ -35,4 +35,9 @@ fn test_docs_snippets() { parse_result.err().unwrap() ); } + + println!( + "Successfully validated {} snforge docs snippets", + snippets.len() + ) } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index f2f60fe4d1..018f923424 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -46,7 +46,7 @@ fn test_docs_snippets() { ], ]; - for snippet in snippets.clone() { + for snippet in &snippets { let args = snippet_to_command_args(snippet.as_str()); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); args.remove(0); @@ -55,7 +55,7 @@ fn test_docs_snippets() { continue; } - // TODO(#2678): Before running the command we should check it it's at least valid + // TODO(#2678): let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); @@ -67,4 +67,9 @@ fn test_docs_snippets() { "Found invalid sncast snippet in the docs: {snippet}\n{stderr}" ); } + + println!( + "Successfully validated {} sncast docs snippets", + snippets.len() + ) } From 5c84ef1ae6b02ea39a21c0573b2d7b72a5320f7d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 10:21:19 +0100 Subject: [PATCH 042/183] Fix linting --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- crates/sncast/tests/docs_snippets/validation.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 5b93738d04..ec5641a098 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -39,5 +39,5 @@ fn test_docs_snippets() { println!( "Successfully validated {} snforge docs snippets", snippets.len() - ) + ); } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 018f923424..ebf0019cde 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -71,5 +71,5 @@ fn test_docs_snippets() { println!( "Successfully validated {} sncast docs snippets", snippets.len() - ) + ); } From 8292a547e1eab61ff51ff2a9b8e2ddb21fa8b826 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 14:47:13 +0100 Subject: [PATCH 043/183] Display line and file path of failed snippet --- crates/docs/src/validation.rs | 87 ++++++++++++++----- .../tests/e2e/docs_snippets_validation.rs | 19 ++-- .../sncast/tests/docs_snippets/validation.rs | 26 +++--- 3 files changed, 82 insertions(+), 50 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 344ca7657d..f189d28adf 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -4,35 +4,72 @@ use std::{ path::{Path, PathBuf}, }; -pub fn extract_matches_from_file( +pub struct Snippet { + pub command: String, + pub file_path: String, + pub line_start: usize, +} + +impl Snippet { + pub fn to_command_args(&self) -> Vec { + let cleaned_command = self + .command + .lines() + .map(str::trim_end) + .collect::>() + .join(" ") + .replace(" \\", ""); + + shell_words::split(&cleaned_command) + .expect("Failed to parse snippet string") + .into_iter() + .map(|arg| arg.trim().to_string()) + .collect() + } +} + +pub fn extract_snippets_from_file( file_path: &Path, re: &Regex, -) -> Result, std::io::Error> { +) -> Result, std::io::Error> { let content = fs::read_to_string(file_path)?; - let matches: Vec = re - .captures_iter(&content) - .filter_map(|caps| caps.get(1).map(|m| m.as_str().to_string())) - .collect(); + let mut snippets = Vec::new(); - Ok(matches) + for caps in re.captures_iter(&content) { + if let Some(command_match) = caps.get(1) { + let match_position = content[..caps.get(0).unwrap().start()].lines().count(); + let file_path = file_path + .to_str() + .expect("Failed to get file path") + .to_string(); + + snippets.push(Snippet { + command: command_match.as_str().to_string(), + file_path, + line_start: match_position + 1, // Line numbers are 1-based + }); + } + } + + Ok(snippets) } -pub fn extract_matches_from_directory( +pub fn extract_snippets_from_directory( dir_path: &Path, re: &Regex, extension: Option<&str>, -) -> io::Result> { +) -> io::Result> { let mut all_snippets = Vec::new(); for entry in fs::read_dir(dir_path)? { let path = entry?.path(); if path.is_dir() { - all_snippets.extend(extract_matches_from_directory(&path, re, extension)?); + all_snippets.extend(extract_snippets_from_directory(&path, re, extension)?); } else if extension.map_or(true, |ext| { path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) }) { - let snippets = extract_matches_from_file(&path, re)?; + let snippets = extract_snippets_from_file(&path, re)?; all_snippets.extend(snippets); } } @@ -54,17 +91,19 @@ pub fn get_parent_dir(levels_up: usize) -> PathBuf { dir } -pub fn snippet_to_command_args(snippet: &str) -> Vec { - let cleaned_snippet = snippet - .lines() - .map(str::trim_end) - .collect::>() - .join(" ") - .replace(" \\", ""); - - shell_words::split(&cleaned_snippet) - .expect("Failed to parse snippet string") - .into_iter() - .map(|arg| arg.trim().to_string()) - .collect() +pub fn assert_valid_snippet( + condition: bool, + snippet: &Snippet, + tool_name: &str, + err_message: &str, +) { + assert!( + condition, + "Found invalid {} snippet '{}' in the docs in file: {} at line {}\n{}", + tool_name, snippet.command, snippet.file_path, snippet.line_start, err_message + ); +} + +pub fn print_success_message(snippets_len: usize, tool_name: &str) { + println!("Successfully validated {snippets_len} {tool_name} docs snippets"); } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index ec5641a098..a14f464e4d 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,5 +1,7 @@ use clap::Parser; -use docs::validation::{extract_matches_from_directory, get_parent_dir, snippet_to_command_args}; +use docs::validation::{ + assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, print_success_message, +}; use forge::Cli; use regex::Regex; #[test] @@ -10,7 +12,7 @@ fn test_docs_snippets() { let re = Regex::new(r"(?ms)```shell\n\$ (snforge .+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); - let snippets = extract_matches_from_directory(&docs_dir, &re, extension) + let snippets = extract_snippets_from_directory(&docs_dir, &re, extension) .expect("Failed to extract snforge command snippets"); let skipped_args = [ @@ -19,7 +21,7 @@ fn test_docs_snippets() { ]; for snippet in &snippets { - let args = snippet_to_command_args(snippet.as_str()); + let args = snippet.to_command_args(); let args: Vec<&str> = args.iter().map(String::as_str).collect(); if skipped_args.contains(&args) { @@ -28,16 +30,13 @@ fn test_docs_snippets() { let parse_result = Cli::try_parse_from(args); - assert!( + assert_valid_snippet( parse_result.is_ok(), - "Found invalid snforge snippet in the docs: {:?}\n{}", snippet, - parse_result.err().unwrap() + "snforge", + parse_result.err().unwrap().to_string().as_str(), ); } - println!( - "Successfully validated {} snforge docs snippets", - snippets.len() - ); + print_success_message(snippets.len(), "snforge"); } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index ebf0019cde..d387225307 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,6 @@ use docs::validation::{ - extract_matches_from_directory, extract_matches_from_file, get_parent_dir, - snippet_to_command_args, + assert_valid_snippet, extract_snippets_from_directory, extract_snippets_from_file, + get_parent_dir, print_success_message, Snippet, }; use regex::Regex; use tempfile::tempdir; @@ -9,7 +9,7 @@ use crate::helpers::runner::runner; #[test] fn test_docs_snippets() { - let tempdir: tempfile::TempDir = tempdir().expect("Unable to create a temporary directory"); + let tempdir = tempdir().expect("Unable to create a temporary directory"); let root_dir_path = get_parent_dir(2); let docs_dir_path = root_dir_path.join("docs/src"); @@ -17,16 +17,16 @@ fn test_docs_snippets() { let re = Regex::new(r"(?ms)```shell\n\$ (sncast .+?)\n```").expect("Invalid regex pattern"); let extension = Some("md"); - let docs_snippets = extract_matches_from_directory(&docs_dir_path, &re, extension) + let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &re, extension) .expect("Failed to extract sncast command snippets"); - let readme_snippets = extract_matches_from_file(&sncast_readme_path, &re) + let readme_snippets = extract_snippets_from_file(&sncast_readme_path, &re) .expect("Failed to extract sncast command snippets"); let snippets = docs_snippets .into_iter() .chain(readme_snippets) - .collect::>(); + .collect::>(); let skipped_args = [ // snippet "$ sncast " @@ -47,7 +47,7 @@ fn test_docs_snippets() { ]; for snippet in &snippets { - let args = snippet_to_command_args(snippet.as_str()); + let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); args.remove(0); @@ -55,21 +55,15 @@ fn test_docs_snippets() { continue; } - // TODO(#2678): + // TODO(#2678) let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); let stderr = String::from_utf8_lossy(&output.stderr); - assert_ne!( - exit_code, 2, - "Found invalid sncast snippet in the docs: {snippet}\n{stderr}" - ); + assert_valid_snippet(exit_code != 2, snippet, "sncast", &stderr); } - println!( - "Successfully validated {} sncast docs snippets", - snippets.len() - ); + print_success_message(snippets.len(), "sncast"); } From fa40a6b8f69ef56de83eef6957d9d0d5e9971071 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 14:56:08 +0100 Subject: [PATCH 044/183] Fix err message --- crates/forge/tests/e2e/docs_snippets_validation.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a14f464e4d..397df1b0a7 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -29,13 +29,12 @@ fn test_docs_snippets() { } let parse_result = Cli::try_parse_from(args); - - assert_valid_snippet( - parse_result.is_ok(), - snippet, - "snforge", - parse_result.err().unwrap().to_string().as_str(), - ); + let err_message = if let Err(err) = &parse_result { + err.to_string() + } else { + "".to_string() + }; + assert_valid_snippet(parse_result.is_ok(), snippet, "snforge", &err_message); } print_success_message(snippets.len(), "snforge"); From d846b4223f34640788eec07ae4b717ed30bf38d2 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 16:59:49 +0100 Subject: [PATCH 045/183] Code review improvements --- Cargo.lock | 1 + crates/docs/Cargo.toml | 4 ++ crates/docs/src/lib.rs | 1 + crates/docs/src/validation.rs | 44 +++++++++++-------- crates/forge/Cargo.toml | 2 +- .../tests/e2e/docs_snippets_validation.rs | 10 +++-- crates/sncast/Cargo.toml | 2 +- crates/sncast/tests/docs_snippets/mod.rs | 2 +- .../sncast/tests/docs_snippets/validation.rs | 13 +++--- 9 files changed, 47 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cda949f767..bb7c4f1f20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1895,6 +1895,7 @@ version = "0.33.0" dependencies = [ "regex", "shell-words", + "walkdir", ] [[package]] diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index 602383d434..a6a11af985 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -8,3 +8,7 @@ license.workspace = true [dependencies] regex = "1.11.1" shell-words = "1.1.0" +walkdir.workspace = true + +[features] +testing = [] diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index 8695201df0..1506b851ef 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -1 +1,2 @@ +#[cfg(feature = "testing")] pub mod validation; diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index f189d28adf..a5da811704 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -4,6 +4,8 @@ use std::{ path::{Path, PathBuf}, }; +const EXTENSION: Option<&str> = Some("md"); + pub struct Snippet { pub command: String, pub file_path: String, @@ -28,10 +30,7 @@ impl Snippet { } } -pub fn extract_snippets_from_file( - file_path: &Path, - re: &Regex, -) -> Result, std::io::Error> { +pub fn extract_snippets_from_file(file_path: &Path, re: &Regex) -> io::Result> { let content = fs::read_to_string(file_path)?; let mut snippets = Vec::new(); @@ -54,22 +53,22 @@ pub fn extract_snippets_from_file( Ok(snippets) } -pub fn extract_snippets_from_directory( - dir_path: &Path, - re: &Regex, - extension: Option<&str>, -) -> io::Result> { +pub fn extract_snippets_from_directory(dir_path: &Path, re: &Regex) -> io::Result> { let mut all_snippets = Vec::new(); - for entry in fs::read_dir(dir_path)? { - let path = entry?.path(); + let entries = walkdir::WalkDir::new(dir_path) + .into_iter() + .filter_map(Result::ok); + + for entry in entries { + let path = entry.path(); - if path.is_dir() { - all_snippets.extend(extract_snippets_from_directory(&path, re, extension)?); - } else if extension.map_or(true, |ext| { - path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) - }) { - let snippets = extract_snippets_from_file(&path, re)?; + if path.is_file() + && EXTENSION.map_or(true, |ext| { + path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) + }) + { + let snippets = extract_snippets_from_file(path, re)?; all_snippets.extend(snippets); } } @@ -99,11 +98,18 @@ pub fn assert_valid_snippet( ) { assert!( condition, - "Found invalid {} snippet '{}' in the docs in file: {} at line {}\n{}", - tool_name, snippet.command, snippet.file_path, snippet.line_start, err_message + "Found invalid {} snippet in the docs in file: {} at line {}\n{}", + tool_name, snippet.file_path, snippet.line_start, err_message ); } pub fn print_success_message(snippets_len: usize, tool_name: &str) { println!("Successfully validated {snippets_len} {tool_name} docs snippets"); } + +pub fn print_skipped_snippet_message(snippet: &Snippet, tool_name: &str) { + println!( + "Skipped validation of {} snippet in the docs in file: {} at line {}", + tool_name, snippet.file_path, snippet.line_start + ); +} diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 990ef47e8b..a0fe364f3f 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -68,7 +68,7 @@ url.workspace = true fs_extra.workspace = true project-root.workspace = true indoc.workspace = true -docs.workspace = true +docs = { workspace = true, features = ["testing"] } [[bin]] name = "snforge" diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 397df1b0a7..d69b5adf46 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,6 +1,7 @@ use clap::Parser; use docs::validation::{ - assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, print_success_message, + assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, + print_skipped_snippet_message, print_success_message, }; use forge::Cli; use regex::Regex; @@ -10,11 +11,11 @@ fn test_docs_snippets() { let docs_dir = root_dir.join("docs/src"); let re = Regex::new(r"(?ms)```shell\n\$ (snforge .+?)\n```").expect("Invalid regex pattern"); - let extension = Some("md"); - let snippets = extract_snippets_from_directory(&docs_dir, &re, extension) + let snippets = extract_snippets_from_directory(&docs_dir, &re) .expect("Failed to extract snforge command snippets"); + // TODO(#2684) let skipped_args = [ // for some reason `try_parse_from` fails on `--version` flag vec!["snforge", "--version"], @@ -25,6 +26,7 @@ fn test_docs_snippets() { let args: Vec<&str> = args.iter().map(String::as_str).collect(); if skipped_args.contains(&args) { + print_skipped_snippet_message(snippet, "snforge"); continue; } @@ -32,7 +34,7 @@ fn test_docs_snippets() { let err_message = if let Err(err) = &parse_result { err.to_string() } else { - "".to_string() + String::new() }; assert_valid_snippet(parse_result.is_ok(), snippet, "snforge", &err_message); } diff --git a/crates/sncast/Cargo.toml b/crates/sncast/Cargo.toml index eefec05a44..3771657541 100644 --- a/crates/sncast/Cargo.toml +++ b/crates/sncast/Cargo.toml @@ -56,7 +56,7 @@ serde_path_to_error.workspace = true walkdir.workspace = true const-hex.workspace = true regex.workspace = true -docs.workspace = true +docs = { workspace = true, features = ["testing"] } [dev-dependencies] ctor.workspace = true diff --git a/crates/sncast/tests/docs_snippets/mod.rs b/crates/sncast/tests/docs_snippets/mod.rs index ff0ee8b68f..8695201df0 100644 --- a/crates/sncast/tests/docs_snippets/mod.rs +++ b/crates/sncast/tests/docs_snippets/mod.rs @@ -1 +1 @@ -mod validation; +pub mod validation; diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index d387225307..2d649b86d0 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,6 @@ use docs::validation::{ assert_valid_snippet, extract_snippets_from_directory, extract_snippets_from_file, - get_parent_dir, print_success_message, Snippet, + get_parent_dir, print_skipped_snippet_message, print_success_message, Snippet, }; use regex::Regex; use tempfile::tempdir; @@ -15,9 +15,9 @@ fn test_docs_snippets() { let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); - let re = Regex::new(r"(?ms)```shell\n\$ (sncast .+?)\n```").expect("Invalid regex pattern"); - let extension = Some("md"); - let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &re, extension) + let re = Regex::new(r"(?ms)```shell\n\$ sncast(.+?)\n```").expect("Invalid regex pattern"); + + let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &re) .expect("Failed to extract sncast command snippets"); let readme_snippets = extract_snippets_from_file(&sncast_readme_path, &re) @@ -28,6 +28,7 @@ fn test_docs_snippets() { .chain(readme_snippets) .collect::>(); + // TODO(#2684) let skipped_args = [ // snippet "$ sncast " vec![""], @@ -48,10 +49,10 @@ fn test_docs_snippets() { for snippet in &snippets { let args = snippet.to_command_args(); - let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); - args.remove(0); + let args: Vec<&str> = args.iter().map(String::as_str).collect(); if skipped_args.contains(&args) { + print_skipped_snippet_message(snippet, "sncast"); continue; } From cbda065b68536046853b00e134d850631a5d0667 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 18 Nov 2024 17:30:07 +0100 Subject: [PATCH 046/183] Move docs to dev dependencies --- crates/forge/Cargo.toml | 2 +- crates/sncast/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index a0fe364f3f..3c8d119141 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -68,7 +68,6 @@ url.workspace = true fs_extra.workspace = true project-root.workspace = true indoc.workspace = true -docs = { workspace = true, features = ["testing"] } [[bin]] name = "snforge" @@ -84,3 +83,4 @@ tempfile.workspace = true cairo-lang-starknet-classes.workspace = true walkdir.workspace = true test-case.workspace = true +docs = { workspace = true, features = ["testing"] } diff --git a/crates/sncast/Cargo.toml b/crates/sncast/Cargo.toml index 3771657541..ce661ff32c 100644 --- a/crates/sncast/Cargo.toml +++ b/crates/sncast/Cargo.toml @@ -56,7 +56,6 @@ serde_path_to_error.workspace = true walkdir.workspace = true const-hex.workspace = true regex.workspace = true -docs = { workspace = true, features = ["testing"] } [dev-dependencies] ctor.workspace = true @@ -67,6 +66,7 @@ tempfile.workspace = true test-case.workspace = true fs_extra.workspace = true wiremock.workspace = true +docs = { workspace = true, features = ["testing"] } [[bin]] name = "sncast" From 9fe0a3ccfd8a260cf1f24b4ea4e59fe893d5fd19 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 10:53:59 +0100 Subject: [PATCH 047/183] Update `tree` output in first steps sections --- docs/src/getting-started/first-steps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 08833008cf..d504761321 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -27,7 +27,7 @@ $ tree . -L 1 ├── src └── tests -2 directories, 2 files +2 directories, 3 files ```

From 906777b77d510b23dcfeef6c2bc3eab73d24ed42 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 12:51:32 +0100 Subject: [PATCH 048/183] Allow setup packages from docs listings --- crates/forge/tests/e2e/common/runner.rs | 19 +++++++++++++++---- crates/forge/tests/e2e/forking.rs | 8 ++++---- crates/forge/tests/e2e/io_operations.rs | 2 +- .../testing_contract_internals/Scarb.toml | 2 +- .../crates/testing_events/Scarb.toml | 2 +- .../crates/testing_messages_to_l1/Scarb.toml | 2 +- .../crates/testing_smart_contracts/Scarb.toml | 2 +- .../crates/using_cheatcodes/Scarb.toml | 2 +- .../crates/writing_tests/Scarb.toml | 2 +- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 9a8d05e789..8168be27c6 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -34,12 +34,17 @@ pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand { pub(crate) static BASE_FILE_PATTERNS: &[&str] = &["**/*.cairo", "**/*.toml"]; pub(crate) fn setup_package_with_file_patterns( - package_name: &str, + package_path: &str, file_patterns: &[&str], ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - temp.copy_from(format!("tests/data/{package_name}"), file_patterns) - .unwrap(); + let package_path = Utf8PathBuf::from_str(package_path) + .unwrap() + .canonicalize_utf8() + .unwrap() + .to_string() + .replace('\\', "/"); + temp.copy_from(package_path, file_patterns).unwrap(); let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std") .unwrap() @@ -69,7 +74,13 @@ pub(crate) fn setup_package_with_file_patterns( } pub(crate) fn setup_package(package_name: &str) -> TempDir { - setup_package_with_file_patterns(package_name, BASE_FILE_PATTERNS) + let package_path = "tests/data/".to_string() + package_name; + setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) +} + +pub(crate) fn setup_package_from_docs_listings(package_name: &str) -> TempDir { + let package_path = "../../docs/listings/snforge_overview/crates/".to_string() + package_name; + setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) } fn replace_node_rpc_url_placeholders(dir_path: &Path) { diff --git a/crates/forge/tests/e2e/forking.rs b/crates/forge/tests/e2e/forking.rs index 2dc4a26882..633bbb77eb 100644 --- a/crates/forge/tests/e2e/forking.rs +++ b/crates/forge/tests/e2e/forking.rs @@ -8,7 +8,7 @@ use shared::test_utils::output_assert::assert_stdout_contains; #[test] fn without_cache() { - let temp = setup_package_with_file_patterns("forking", BASE_FILE_PATTERNS); + let temp = setup_package_with_file_patterns("tests/data/forking", BASE_FILE_PATTERNS); let output = test_runner(&temp) .arg("forking::tests::test_fork_simple") @@ -40,7 +40,7 @@ fn without_cache() { /// The test that passed when using data from network, should fail for fabricated data. fn with_cache() { let temp = setup_package_with_file_patterns( - "forking", + "tests/data/forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); @@ -75,7 +75,7 @@ fn with_cache() { #[test] fn with_clean_cache() { let temp = setup_package_with_file_patterns( - "forking", + "tests/data/forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); @@ -104,7 +104,7 @@ fn with_clean_cache() { #[test] fn printing_latest_block_number() { let temp = setup_package_with_file_patterns( - "forking", + "tests/data/forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); let node_rpc_url = node_rpc_url(); diff --git a/crates/forge/tests/e2e/io_operations.rs b/crates/forge/tests/e2e/io_operations.rs index af7394c16e..a2d8187a26 100644 --- a/crates/forge/tests/e2e/io_operations.rs +++ b/crates/forge/tests/e2e/io_operations.rs @@ -7,7 +7,7 @@ use shared::test_utils::output_assert::assert_stdout_contains; #[allow(clippy::too_many_lines)] fn file_reading() { let temp = setup_package_with_file_patterns( - "file_reading", + "tests/data/file_reading", &[BASE_FILE_PATTERNS, &["**/*.txt", "**/*.json"]].concat(), ); diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml index fd0ff87b5c..a6fc6a1722 100644 --- a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml index b712ac493f..d46e309491 100644 --- a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml index bee7f589eb..145f028651 100644 --- a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml index 2a22bc631a..17b36bfea4 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml index 537128dcfb..5470a0567a 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml @@ -6,7 +6,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true snforge_std.workspace = true -assert_macros.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml b/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml index f3f793dab6..2c84a28c9f 100644 --- a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml +++ b/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true From 446cdfd2f504abd90b172214e3b6c641b1595033 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 14:06:38 +0100 Subject: [PATCH 049/183] Add example packages for "Running tests" section --- .../detailed_resources_example/.gitignore | 2 + .../detailed_resources_example/Scarb.toml | 18 +++++++ .../detailed_resources_example/src/lib.cairo | 25 ++++++++++ .../tests/test_contract.cairo | 15 ++++++ .../crates/failing_example/.gitignore | 2 + .../crates/failing_example/Scarb.toml | 18 +++++++ .../crates/failing_example/src/lib.cairo | 25 ++++++++++ .../failing_example/tests/test_contract.cairo | 15 ++++++ .../crates/hello_snforge/.gitignore | 2 + .../crates/hello_snforge/Scarb.toml | 18 +++++++ .../crates/hello_snforge/src/lib.cairo | 25 ++++++++++ .../hello_snforge/tests/test_contract.cairo | 14 ++++++ .../crates/hello_starknet/.gitignore | 2 + .../crates/hello_starknet/Scarb.toml | 18 +++++++ .../crates/hello_starknet/src/lib.cairo | 25 ++++++++++ .../hello_starknet/tests/test_contract.cairo | 29 +++++++++++ .../testing_contract_internals/Scarb.toml | 2 +- .../crates/testing_events/Scarb.toml | 2 +- .../crates/testing_messages_to_l1/Scarb.toml | 2 +- .../crates/testing_smart_contracts/Scarb.toml | 2 +- .../crates/using_cheatcodes/Scarb.toml | 1 - .../crates/writing_tests/Scarb.toml | 2 +- .../testing/gas-and-resource-estimation.md | 17 ++++--- docs/src/testing/running-tests.md | 50 ++++++++++--------- 24 files changed, 295 insertions(+), 36 deletions(-) create mode 100644 docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore create mode 100644 docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo create mode 100644 docs/listings/snforge_overview/crates/failing_example/.gitignore create mode 100644 docs/listings/snforge_overview/crates/failing_example/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/failing_example/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo create mode 100644 docs/listings/snforge_overview/crates/hello_snforge/.gitignore create mode 100644 docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo create mode 100644 docs/listings/snforge_overview/crates/hello_starknet/.gitignore create mode 100644 docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore b/docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore new file mode 100644 index 0000000000..73aa31e608 --- /dev/null +++ b/docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore @@ -0,0 +1,2 @@ +target +.snfoundry_cache/ diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml b/docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml new file mode 100644 index 0000000000..9f43eaa2e1 --- /dev/null +++ b/docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml @@ -0,0 +1,18 @@ +[package] +name = "detailed_resources_example" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo b/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo new file mode 100644 index 0000000000..8cd1124d6d --- /dev/null +++ b/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +pub trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + } +} diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo new file mode 100644 index 0000000000..42968bcd13 --- /dev/null +++ b/docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo @@ -0,0 +1,15 @@ +#[test] +fn test_abc() { + assert(1 == 1, 1); +} + +#[test] +fn test_failing() { + assert(1 == 2, 'failing check'); +} + +#[test] +fn test_xyz() { + assert(1 == 1, 1); +} + diff --git a/docs/listings/snforge_overview/crates/failing_example/.gitignore b/docs/listings/snforge_overview/crates/failing_example/.gitignore new file mode 100644 index 0000000000..73aa31e608 --- /dev/null +++ b/docs/listings/snforge_overview/crates/failing_example/.gitignore @@ -0,0 +1,2 @@ +target +.snfoundry_cache/ diff --git a/docs/listings/snforge_overview/crates/failing_example/Scarb.toml b/docs/listings/snforge_overview/crates/failing_example/Scarb.toml new file mode 100644 index 0000000000..ef4e2fd9ea --- /dev/null +++ b/docs/listings/snforge_overview/crates/failing_example/Scarb.toml @@ -0,0 +1,18 @@ +[package] +name = "failing_example" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo b/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo new file mode 100644 index 0000000000..8cd1124d6d --- /dev/null +++ b/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +pub trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + } +} diff --git a/docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo new file mode 100644 index 0000000000..42968bcd13 --- /dev/null +++ b/docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo @@ -0,0 +1,15 @@ +#[test] +fn test_abc() { + assert(1 == 1, 1); +} + +#[test] +fn test_failing() { + assert(1 == 2, 'failing check'); +} + +#[test] +fn test_xyz() { + assert(1 == 1, 1); +} + diff --git a/docs/listings/snforge_overview/crates/hello_snforge/.gitignore b/docs/listings/snforge_overview/crates/hello_snforge/.gitignore new file mode 100644 index 0000000000..73aa31e608 --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_snforge/.gitignore @@ -0,0 +1,2 @@ +target +.snfoundry_cache/ diff --git a/docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml b/docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml new file mode 100644 index 0000000000..874d8c3a78 --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml @@ -0,0 +1,18 @@ +[package] +name = "hello_snforge" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo b/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo new file mode 100644 index 0000000000..8cd1124d6d --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +pub trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + } +} diff --git a/docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo new file mode 100644 index 0000000000..a747a94cd9 --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo @@ -0,0 +1,14 @@ +#[test] +fn test_executing() { + assert(1 == 1, 1); +} + +#[test] +fn test_calling() { + assert(2 == 2, 2); +} + +#[test] +fn test_calling_another() { + assert(3 == 3, 3); +} diff --git a/docs/listings/snforge_overview/crates/hello_starknet/.gitignore b/docs/listings/snforge_overview/crates/hello_starknet/.gitignore new file mode 100644 index 0000000000..73aa31e608 --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_starknet/.gitignore @@ -0,0 +1,2 @@ +target +.snfoundry_cache/ diff --git a/docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml b/docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml new file mode 100644 index 0000000000..0ecb3f63f5 --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml @@ -0,0 +1,18 @@ +[package] +name = "hello_starknet" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo b/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo new file mode 100644 index 0000000000..8cd1124d6d --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +pub trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + } +} diff --git a/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo new file mode 100644 index 0000000000..8e60dbfcce --- /dev/null +++ b/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo @@ -0,0 +1,29 @@ +use starknet::ContractAddress; + +use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; + +use hello_starknet::IHelloStarknetSafeDispatcher; +use hello_starknet::IHelloStarknetSafeDispatcherTrait; +use hello_starknet::IHelloStarknetDispatcher; +use hello_starknet::IHelloStarknetDispatcherTrait; + +fn deploy_contract(name: ByteArray) -> ContractAddress { + let contract = declare(name).unwrap().contract_class(); + let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + contract_address +} + +#[test] +fn test_increase_balance() { + let contract_address = deploy_contract("HelloStarknet"); + + let dispatcher = IHelloStarknetDispatcher { contract_address }; + + let balance_before = dispatcher.get_balance(); + assert(balance_before == 0, 'Invalid balance'); + + dispatcher.increase_balance(42); + + let balance_after = dispatcher.get_balance(); + assert(balance_after == 42, 'Invalid balance'); +} diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml index a6fc6a1722..fd0ff87b5c 100644 --- a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std = { path = "../../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml index d46e309491..b712ac493f 100644 --- a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std = { path = "../../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml index 145f028651..bee7f589eb 100644 --- a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std = { path = "../../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml index 17b36bfea4..2a22bc631a 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std = { path = "../../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml index 5470a0567a..6ad44a73d1 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml @@ -6,7 +6,6 @@ edition = "2023_11" [dependencies] starknet.workspace = true snforge_std.workspace = true -snforge_std = { path = "../../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml b/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml index 2c84a28c9f..f3f793dab6 100644 --- a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml +++ b/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std = { path = "../../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 0529400270..9657c6b5aa 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -44,13 +44,16 @@ $ snforge test --detailed-resources Output: ```shell -... -[PASS] package_name::tests::resources (gas: ~2213) - steps: 881 - memory holes: 36 - builtins: ("range_check_builtin": 32) - syscalls: (StorageWrite: 1, StorageRead: 1, CallContract: 1) -... +Collected 1 test(s) from hello_starknet package +Running 0 test(s) from src/ +Running 1 test(s) from tests/ +[PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) + steps: 4535 + memory holes: 15 + builtins: (range_check: 95, pedersen: 7) + syscalls: (StorageRead: 3, CallContract: 3, StorageWrite: 1, Deploy: 1) + +Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index bf3382e80b..a2ac328019 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -10,11 +10,12 @@ $ snforge test Output: ```shell -Collected 3 test(s) from package_name package -Running 3 test(s) from src/ -[PASS] package_name::tests::executing -[PASS] package_name::tests::calling -[PASS] package_name::tests::calling_another +Collected 3 test(s) from hello_snforge package +Running 3 test(s) from tests/ +[PASS] hello_snforge_integrationtest::test_contract::test_another (gas: ~1) +[PASS] hello_snforge_integrationtest::test_contract::test_calling (gas: ~1) +[PASS] hello_snforge_integrationtest::test_contract::test_executing (gas: ~1) +Running 0 test(s) from src/ Tests: 3 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -23,8 +24,9 @@ Tests: 3 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ## Filtering Tests You can pass a filter string after the `snforge test` command to filter tests. -By default, any test with an [absolute module tree path](https://book.cairo-lang.org/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree) - matching the filter will be run. +By default, any test with an [absolute module tree path](https://book.cairo-lang.org/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree) matching the filter will be run. + +You're tests may differ, note that we changed the default tests generated by `snforge init` for 3 custom tests: `calling`, `calling_another`, and `executing` just for the sake of this example. ```shell $ snforge test calling @@ -34,10 +36,11 @@ $ snforge test calling Output: ```shell -Collected 2 test(s) from package_name package -Running 2 test(s) from src/ -[PASS] package_name::tests::calling -[PASS] package_name::tests::calling_another +Collected 2 test(s) from hello_snforge package +Running 0 test(s) from src/ +Running 2 test(s) from tests/ +[PASS] hello_snforge_integrationtest::test_contract::test_calling_another (gas: ~1) +[PASS] hello_snforge_integrationtest::test_contract::test_calling (gas: ~1) Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 1 filtered out ```
@@ -54,16 +57,17 @@ Note, you have to use a fully qualified test name, including a module name. > ```shell -$ snforge test package_name::tests::calling --exact +$ snforge test hello_snforge_integrationtest::test_contract::test_calling --exact ```
Output: ```shell -Collected 1 test(s) from package_name package -Running 1 test(s) from src/ -[PASS] package_name::tests::calling +Collected 1 test(s) from hello_snforge package +Running 1 test(s) from tests/ +[PASS] hello_snforge_integrationtest::test_contract::test_calling (gas: ~1) +Running 0 test(s) from src/ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out ```
@@ -81,20 +85,20 @@ $ snforge test --exit-first Output: ```shell -Collected 6 test(s) from package_name package -Running 6 test(s) from src/ -[PASS] package_name::tests::executing -[PASS] package_name::tests::calling -[PASS] package_name::tests::calling_another -[FAIL] package_name::tests::failing +Collected 3 test(s) from failing_example package +Running 0 test(s) from src/ +Running 3 test(s) from tests/ +[FAIL] failing_example_integrationtest::test_contract::test_failing Failure data: 0x6661696c696e6720636865636b ('failing check') -Tests: 3 passed, 1 failed, 2 skipped, 0 ignored, 0 filtered out +[PASS] failing_example_integrationtest::test_contract::test_abc (gas: ~1) +[PASS] failing_example_integrationtest::test_contract::test_xyz (gas: ~1) +Tests: 2 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: - package_name::tests::failing + failing_example_integrationtest::test_contract::test_failing ```

From 2a61d99f14982dd0d3af6fe1329a414d28130895 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 16:25:52 +0100 Subject: [PATCH 050/183] wip: Update outputs for snippets in snforge overview --- .../{writing_tests => first_test}/Scarb.toml | 2 +- .../src/lib.cairo} | 0 .../Scarb.toml | 2 +- .../crates/ignoring_example/src/lib.cairo | 8 ++++ .../crates/panicking_test/Scarb.toml | 14 ++++++ .../src/lib.cairo} | 4 +- .../crates/should_panic_test/Scarb.toml | 14 ++++++ .../crates/should_panic_test/src/lib.cairo | 45 ++++++++++++++++++ .../testing_smart_contracts/src/lib.cairo | 2 - .../src/simple_contract.cairo | 26 ----------- .../Scarb.toml | 14 ++++++ .../src/lib.cairo} | 0 .../tests/handle_panic.cairo | 0 .../tests/panic.cairo | 3 +- .../Scarb.toml | 14 ++++++ .../src/lib.cairo | 26 +++++++++++ .../tests/safe_dispatcher.cairo | 2 +- .../Scarb.toml | 14 ++++++ .../src/lib.cairo | 21 +++++++++ .../tests/simple_contract.cairo | 2 +- .../crates/using_cheatcodes/Scarb.toml | 3 ++ .../crates/writing_tests_orig/Scarb.toml | 14 ++++++ .../writing_tests_orig/src/first_test.cairo | 13 ++++++ .../src/lib.cairo | 0 .../src/panicking_tests.cairo | 15 ++++++ .../tests/expected_failures.cairo | 0 .../tests/ignoring.cairo | 0 docs/src/testing/contracts.md | 32 ++++++------- docs/src/testing/testing.md | 46 ++++++++++--------- 29 files changed, 261 insertions(+), 75 deletions(-) rename docs/listings/snforge_overview/crates/{writing_tests => first_test}/Scarb.toml (89%) rename docs/listings/snforge_overview/crates/{writing_tests/src/first_test.cairo => first_test/src/lib.cairo} (100%) rename docs/listings/snforge_overview/crates/{testing_smart_contracts => ignoring_example}/Scarb.toml (85%) create mode 100644 docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/panicking_test/Scarb.toml rename docs/listings/snforge_overview/crates/{writing_tests/src/panicking_tests.cairo => panicking_test/src/lib.cairo} (76%) create mode 100644 docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo delete mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts/src/lib.cairo delete mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts/src/simple_contract.cairo create mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml rename docs/listings/snforge_overview/crates/{testing_smart_contracts/src/handling_errors.cairo => testing_smart_contracts_handling_errors/src/lib.cairo} (100%) rename docs/listings/snforge_overview/crates/{testing_smart_contracts => testing_smart_contracts_handling_errors}/tests/handle_panic.cairo (100%) rename docs/listings/snforge_overview/crates/{testing_smart_contracts => testing_smart_contracts_handling_errors}/tests/panic.cairo (84%) create mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo rename docs/listings/snforge_overview/crates/{testing_smart_contracts => testing_smart_contracts_safe_dispatcher}/tests/safe_dispatcher.cairo (93%) create mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo rename docs/listings/snforge_overview/crates/{testing_smart_contracts => testing_smart_contracts_writing_tests}/tests/simple_contract.cairo (95%) create mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo rename docs/listings/snforge_overview/crates/{writing_tests => writing_tests_orig}/src/lib.cairo (100%) create mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo rename docs/listings/snforge_overview/crates/{writing_tests => writing_tests_orig}/tests/expected_failures.cairo (100%) rename docs/listings/snforge_overview/crates/{writing_tests => writing_tests_orig}/tests/ignoring.cairo (100%) diff --git a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml b/docs/listings/snforge_overview/crates/first_test/Scarb.toml similarity index 89% rename from docs/listings/snforge_overview/crates/writing_tests/Scarb.toml rename to docs/listings/snforge_overview/crates/first_test/Scarb.toml index f3f793dab6..6e0a381d4a 100644 --- a/docs/listings/snforge_overview/crates/writing_tests/Scarb.toml +++ b/docs/listings/snforge_overview/crates/first_test/Scarb.toml @@ -1,5 +1,5 @@ [package] -name = "writing_tests" +name = "first_test" version = "0.1.0" edition = "2023_11" diff --git a/docs/listings/snforge_overview/crates/writing_tests/src/first_test.cairo b/docs/listings/snforge_overview/crates/first_test/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/writing_tests/src/first_test.cairo rename to docs/listings/snforge_overview/crates/first_test/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml b/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml similarity index 85% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml rename to docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml index 2a22bc631a..37dc52f448 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/Scarb.toml +++ b/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml @@ -1,5 +1,5 @@ [package] -name = "testing_smart_contracts" +name = "ignoring_example" version = "0.1.0" edition = "2023_11" diff --git a/docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo b/docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo new file mode 100644 index 0000000000..f76a6eede4 --- /dev/null +++ b/docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + #[ignore] + fn ignored_test() { // test code + } +} + diff --git a/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml b/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml new file mode 100644 index 0000000000..b79df6ce0f --- /dev/null +++ b/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "panicking_test" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/writing_tests/src/panicking_tests.cairo b/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo similarity index 76% rename from docs/listings/snforge_overview/crates/writing_tests/src/panicking_tests.cairo rename to docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo index f9701e34dd..3d179acb26 100644 --- a/docs/listings/snforge_overview/crates/writing_tests/src/panicking_tests.cairo +++ b/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo @@ -1,7 +1,7 @@ //ANCHOR:first_half fn panicking_function() { let mut data = array![]; - data.append('aaa'); + data.append('panic message'); panic(data) } @@ -11,7 +11,6 @@ mod tests { #[test] //ANCHOR_END:first_half - #[should_panic(expected: 'aaa')] //ANCHOR:second_half fn failing() { panicking_function(); @@ -20,4 +19,3 @@ mod tests { } //ANCHOR_END:second_half -mod dummy {} // trick `scarb fmt --check` diff --git a/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml b/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml new file mode 100644 index 0000000000..be1bd297ee --- /dev/null +++ b/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "should_panic_test" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo b/docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo new file mode 100644 index 0000000000..fc59c2ac77 --- /dev/null +++ b/docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo @@ -0,0 +1,45 @@ +#[cfg(test)] +mod tests { + //ANCHOR:byte_array + #[test] + #[should_panic(expected: "This will panic")] + fn should_panic_exact() { + panic!("This will panic"); + } + + // here the expected message is a substring of the actual message + #[test] + #[should_panic(expected: "will panic")] + fn should_panic_expected_is_substring() { + panic!("This will panic"); + } + //ANCHOR_END:byte_array + + //ANCHOR:felt + #[test] + #[should_panic(expected: 'panic message')] + fn should_panic_felt_matching() { + assert(1 != 1, 'panic message'); + } + //ANCHOR_END:felt + + //ANCHOR:tuple + use core::panic_with_felt252; + + #[test] + #[should_panic(expected: ('panic message',))] + fn should_panic_check_data() { + panic_with_felt252('panic message'); + } + + // works for multiple messages + #[test] + #[should_panic(expected: ('panic message', 'second message',))] + fn should_panic_multiple_messages() { + let mut arr = ArrayTrait::new(); + arr.append('panic message'); + arr.append('second message'); + panic(arr); + } + //ANCHOR_END:tuple +} diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/src/lib.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts/src/lib.cairo deleted file mode 100644 index 7a2182058d..0000000000 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/src/lib.cairo +++ /dev/null @@ -1,2 +0,0 @@ -pub mod simple_contract; -pub mod handling_errors; diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/src/simple_contract.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts/src/simple_contract.cairo deleted file mode 100644 index af38fd767e..0000000000 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/src/simple_contract.cairo +++ /dev/null @@ -1,26 +0,0 @@ -#[starknet::interface] -pub trait ISimpleContract { - fn increase_balance(ref self: TContractState, amount: felt252); - fn get_balance(self: @TContractState) -> felt252; -} - -#[starknet::contract] -pub mod SimpleContract { - #[storage] - struct Storage { - balance: felt252, - } - - #[abi(embed_v0)] - pub impl SimpleContractImpl of super::ISimpleContract { - // Increases the balance by the given amount - fn increase_balance(ref self: ContractState, amount: felt252) { - self.balance.write(self.balance.read() + amount); - } - - // Gets the balance. - fn get_balance(self: @ContractState) -> felt252 { - self.balance.read() - } - } -} diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml new file mode 100644 index 0000000000..ae20249296 --- /dev/null +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "testing_smart_contracts_handling_errors" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/src/handling_errors.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/src/handling_errors.cairo rename to docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/handle_panic.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/tests/handle_panic.cairo rename to docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/panic.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo similarity index 84% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/tests/panic.cairo rename to docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo index d42ec2108d..5bdd7006fd 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/panic.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo @@ -1,13 +1,12 @@ //ANCHOR:first_half use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use testing_smart_contracts::handling_errors::{ +use testing_smart_contracts_handling_errors::{ IPanicContractDispatcher, IPanicContractDispatcherTrait }; #[test] //ANCHOR_END:first_half -#[should_panic(expected: ('PANIC', 'DAYTAH'))] //ANCHOR:second_half fn failing() { let contract = declare("PanicContract").unwrap().contract_class(); diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml new file mode 100644 index 0000000000..3850e037e7 --- /dev/null +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "testing_smart_contracts_safe_dispatcher" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo new file mode 100644 index 0000000000..be964fec2a --- /dev/null +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo @@ -0,0 +1,26 @@ +#[starknet::interface] +pub trait IPanicContract { + fn do_a_panic(self: @TContractState); + fn do_a_string_panic(self: @TContractState); +} + +#[starknet::contract] +pub mod PanicContract { + use core::array::ArrayTrait; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + pub impl PanicContractImpl of super::IPanicContract { + // Panics + fn do_a_panic(self: @ContractState) { + panic(array!['PANIC', 'DAYTAH']); + } + + fn do_a_string_panic(self: @ContractState) { + // A macro which allows panicking with a ByteArray (string) instance + panic!("This is panicking with a string, which can be longer than 31 characters"); + } + } +} diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/safe_dispatcher.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo similarity index 93% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/tests/safe_dispatcher.cairo rename to docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo index 779c9c6ab2..56ca89580a 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/safe_dispatcher.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo @@ -1,6 +1,6 @@ use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use testing_smart_contracts::handling_errors::{ +use testing_smart_contracts_safe_dispatcher::{ IPanicContractSafeDispatcher, IPanicContractSafeDispatcherTrait }; diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml new file mode 100644 index 0000000000..ccd121ff1f --- /dev/null +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "testing_smart_contracts_writing_tests" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo new file mode 100644 index 0000000000..832961c6b7 --- /dev/null +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo @@ -0,0 +1,21 @@ +use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; + +use testing_smart_contracts_handling_errors::{ + IPanicContractSafeDispatcher, IPanicContractSafeDispatcherTrait +}; + +#[test] +#[feature("safe_dispatcher")] +fn handling_errors() { + let contract = declare("PanicContract").unwrap().contract_class(); + let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let safe_dispatcher = IPanicContractSafeDispatcher { contract_address }; + + match safe_dispatcher.do_a_panic() { + Result::Ok(_) => panic!("Entrypoint did not panic"), + Result::Err(panic_data) => { + assert(*panic_data.at(0) == 'PANIC', *panic_data.at(0)); + assert(*panic_data.at(1) == 'DAYTAH', *panic_data.at(1)); + } + }; +} diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/simple_contract.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo similarity index 95% rename from docs/listings/snforge_overview/crates/testing_smart_contracts/tests/simple_contract.cairo rename to docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo index 11a6a32451..c55f0f5a68 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts/tests/simple_contract.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo @@ -1,6 +1,6 @@ use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use testing_smart_contracts::simple_contract::{ +use testing_smart_contracts_handling_errors::{ ISimpleContractDispatcher, ISimpleContractDispatcherTrait }; diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml index 6ad44a73d1..7a5cccb821 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml @@ -7,6 +7,9 @@ edition = "2023_11" starknet.workspace = true snforge_std.workspace = true +[dev-dependencies] +assert_macros.workspace = true + [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml b/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml new file mode 100644 index 0000000000..08adb9be1b --- /dev/null +++ b/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml @@ -0,0 +1,14 @@ +[package] +name = "writing_tests_orig" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo new file mode 100644 index 0000000000..45e03bf175 --- /dev/null +++ b/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo @@ -0,0 +1,13 @@ +fn sum(a: felt252, b: felt252) -> felt252 { + return a + b; +} + +#[cfg(test)] +mod tests { + use super::sum; + + #[test] + fn test_sum() { + assert(sum(2, 3) == 5, 'sum incorrect'); + } +} diff --git a/docs/listings/snforge_overview/crates/writing_tests/src/lib.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/writing_tests/src/lib.cairo rename to docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo new file mode 100644 index 0000000000..e36d827abb --- /dev/null +++ b/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo @@ -0,0 +1,15 @@ +#[cfg(test)] +mod tests { + use super::panicking_function; + + #[test] + //ANCHOR_END:first_half + #[should_panic(expected: 'aaa')] + //ANCHOR:second_half + fn failing() { + panicking_function(); + assert(2 == 2, '2 == 2'); + } +} + +mod dummy {} // trick `scarb fmt --check` diff --git a/docs/listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo rename to docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo diff --git a/docs/listings/snforge_overview/crates/writing_tests/tests/ignoring.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/writing_tests/tests/ignoring.cairo rename to docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index 08e600fb4f..ef10033567 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -19,7 +19,7 @@ writing smart contracts, you often want to test their interactions with the bloc Let's consider a simple smart contract with two methods. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/src/simple_contract.cairo}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo}} ``` Note that the name after `mod` will be used as the contract name for testing purposes. @@ -29,7 +29,7 @@ Note that the name after `mod` will be used as the contract name for testing pur Let's write a test that will deploy the `HelloStarknet` contract and call some functions. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/tests/simple_contract.cairo}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo}} ``` > 📝 **Note** @@ -46,10 +46,10 @@ $ snforge test Output: ```shell -Collected 1 test(s) from testing_smart_contracts package -Running 0 test(s) from src/ +Collected 1 test(s) from testing_smart_contracts_writing_tests package Running 1 test(s) from tests/ -[PASS] tests::call_and_invoke +[PASS] testing_smart_contracts_writing_tests_integrationtest::simple_contract::call_and_invoke (gas: ~172) +Running 0 test(s) from src/ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -64,14 +64,14 @@ panicking. First, let's add a new, panicking function to our contract. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/src/handling_errors.cairo}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo}} ``` If we called this function in a test, it would result in a failure. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/tests/panic.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/tests/panic.cairo:second_half}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo:first_half}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo:second_half}} ``` ```shell @@ -82,18 +82,18 @@ $ snforge test Output: ```shell -Collected 1 test(s) from testing_smart_contracts package -Running 0 test(s) from src/ +Collected 1 test(s) from testing_smart_contracts_handling_errors package Running 1 test(s) from tests/ -[FAIL] tests::failing +[FAIL] testing_smart_contracts_handling_errors_integrationtest::panic::failing Failure data: (0x50414e4943 ('PANIC'), 0x444159544148 ('DAYTAH')) +Running 0 test(s) from src/ Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: - tests::failing + testing_smart_contracts_handling_errors_integrationtest::panic::failing ```

@@ -107,7 +107,7 @@ but are available for testing purposes. They allow using the contract without automatically unwrapping the result, which allows to catch the error like shown below. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/tests/safe_dispatcher.cairo}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo}} ``` Now the test passes as expected. @@ -120,10 +120,10 @@ $ snforge test Output: ```shell -Collected 1 test(s) from package_name package +Collected 1 test(s) from testing_smart_contracts_safe_dispatcher package Running 0 test(s) from src/ Running 1 test(s) from tests/ -[PASS] tests::handling_errors +[PASS] testing_smart_contracts_safe_dispatcher_integrationtest::safe_dispatcher::handling_errors (gas: ~103) Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -132,7 +132,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out Similarly, you can handle the panics which use `ByteArray` as an argument (like an `assert!` or `panic!` macro) ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts/tests/handle_panic.cairo}} +{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo}} ``` You also could skip the de-serialization of the `panic_data`, and not use `try_deserialize_bytearray_error`, but this way you can actually use assertions on the `ByteArray` that was used to panic. diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index bdff23bcc6..af813d285c 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -8,7 +8,7 @@ should write as many unit tests as possible as these are faster than integration First, add the following code to the `src/lib.cairo` file: ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/src/first_test.cairo}} +{{#include ../../listings/snforge_overview/crates/first_test/src/lib.cairo}} ``` It is a common practice to keep your unit tests in the same file as the tested code. @@ -26,9 +26,9 @@ $ snforge test Output: ```shell -Collected 1 test(s) from writing_tests package +Collected 1 test(s) from first_test package Running 1 test(s) from src/ -[PASS] writing::first_test::tests::test_sum +[PASS] first_test::tests::test_sum (gas: ~1) Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -39,8 +39,8 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out If your code panics, the test is considered failed. Here's an example of a failing test. ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/src/panicking_tests.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/writing_tests/src/panicking_tests.cairo:second_half}} +{{#include ../../listings/snforge_overview/crates/panicking_test/src/lib.cairo:first_half}} +{{#include ../../listings/snforge_overview/crates/panicking_test/src/lib.cairo:second_half}} ``` ```shell @@ -51,17 +51,17 @@ $ snforge test Output: ```shell -Collected 1 test(s) from writing_tests package +Collected 1 test(s) from panicking_test package Running 1 test(s) from src/ -[FAIL] writing_tests::panicking_tests::tests::failing +[FAIL] panicking_test::tests::failing Failure data: - 0x616161 ('aaa') + 0x70616e6963206d657373616765 ('panic message') Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: - writing_tests::panicking_tests::tests::failing + panicking_test::tests::failing ```

@@ -77,18 +77,18 @@ You can specify the expected failure message in three ways: 1. **With ByteArray**: ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo:byte_array}} +{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:byte_array}} ``` With this format, the expected error message needs to be a substring of the actual error message. This is particularly useful when the error message includes dynamic data such as a hash or address. 2. **With felt** ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo:felt}} +{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:felt}} ``` 3. **With tuple of felts**: ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/tests/expected_failures.cairo:tuple}} +{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:tuple}} ``` @@ -100,11 +100,14 @@ $ snforge test Output: ```shell -Collected 1 test(s) from writing_tests package -Running 0 test(s) from src/ -Running 1 test(s) from tests/ -[PASS] snforge_overview_integrationtest::should_panic_check_data -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Collected 5 test(s) from should_panic_test package +Running 5 test(s) from src/ +[PASS] should_panic_test::tests::should_panic_felt_matching (gas: ~1) +[PASS] should_panic_test::tests::should_panic_multiple_messages (gas: ~1) +[PASS] should_panic_test::tests::should_panic_exact (gas: ~1) +[PASS] should_panic_test::tests::should_panic_expected_is_substring (gas: ~1) +[PASS] should_panic_test::tests::should_panic_check_data (gas: ~1) +Tests: 5 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

@@ -115,7 +118,7 @@ Sometimes you may have tests that you want to exclude during most runs of `snfor You can achieve it using `#[ignore]` - tests marked with this attribute will be skipped by default. ```rust -{{#include ../../listings/snforge_overview/crates/writing_tests/tests/ignoring.cairo}} +{{#include ../../listings/snforge_overview/crates/ignoring_example/src/lib.cairo}} ``` ```shell @@ -126,10 +129,9 @@ $ snforge test Output: ```shell -Collected 1 test(s) from writing_tests package -Running 0 test(s) from src/ -Running 1 test(s) from tests/ -[IGNORE] writing_tests_integrationtest::ignoring::ignored_test +Collected 1 test(s) from ignoring_example package +Running 1 test(s) from src/ +[IGNORE] ignoring_example::tests::ignored_test Tests: 0 passed, 0 failed, 0 skipped, 1 ignored, 0 filtered out ```
From bcf5f406b1d1e6ad260e1a5540e13cb9d2d88e20 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 16:52:51 +0100 Subject: [PATCH 051/183] Fix typo --- docs/src/testing/using-cheatcodes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index eb8d0e6202..aea3da6386 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -90,7 +90,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out

-### Canceling the Cheat +### Cancelling the Cheat Most cheatcodes come with corresponding `start_` and `stop_` functions that can be used to start and stop the state change. From aa4be238bbbb6227956ae98ab5aa8e31104d24d6 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 17:10:50 +0100 Subject: [PATCH 052/183] wip: Update outputs for cheatcode snippets --- .../tests/caller_address.cairo | 5 -- .../tests/caller_address/failing.cairo | 24 -------- .../crates/using_cheatcodes/tests/lib.cairo | 19 ++++++- .../Scarb.toml | 17 ++++++ .../src/lib.cairo | 55 +++++++++++++++++++ .../tests/lib.cairo} | 11 +--- .../using_cheatcodes_cheat_address/Scarb.toml | 17 ++++++ .../src/lib.cairo | 55 +++++++++++++++++++ .../tests/lib.cairo} | 2 +- .../crates/using_cheatcodes_others/Scarb.toml | 17 ++++++ .../using_cheatcodes_others/src/lib.cairo | 55 +++++++++++++++++++ .../tests/caller_address.cairo | 2 + .../caller_address/proper_use_global.cairo | 2 +- .../tests/caller_address/span.cairo | 4 +- .../tests/cheat_constructor.cairo | 2 +- .../using_cheatcodes_others/tests/lib.cairo | 2 + docs/src/testing/using-cheatcodes.md | 35 +++++++----- 17 files changed, 266 insertions(+), 58 deletions(-) delete mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address.cairo delete mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo rename docs/listings/snforge_overview/crates/{using_cheatcodes/tests/caller_address/cancel.cairo => using_cheatcodes_cancelling_cheat/tests/lib.cairo} (80%) create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo rename docs/listings/snforge_overview/crates/{using_cheatcodes/tests/caller_address/proper_use.cairo => using_cheatcodes_cheat_address/tests/lib.cairo} (87%) create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo rename docs/listings/snforge_overview/crates/{using_cheatcodes => using_cheatcodes_others}/tests/caller_address/proper_use_global.cairo (93%) rename docs/listings/snforge_overview/crates/{using_cheatcodes => using_cheatcodes_others}/tests/caller_address/span.cairo (93%) rename docs/listings/snforge_overview/crates/{using_cheatcodes => using_cheatcodes_others}/tests/cheat_constructor.cairo (91%) create mode 100644 docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address.cairo deleted file mode 100644 index 5d6f615f9c..0000000000 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address.cairo +++ /dev/null @@ -1,5 +0,0 @@ -pub mod failing; -pub mod proper_use; -pub mod proper_use_global; -pub mod cancel; -pub mod span; diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo deleted file mode 100644 index a44eac2e7e..0000000000 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo +++ /dev/null @@ -1,24 +0,0 @@ -//ANCHOR:first_half -use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use using_cheatcodes::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; - -#[test] -//ANCHOR_END:first_half -#[should_panic(expected: 'user is not allowed')] -//ANCHOR:second_half -fn call_and_invoke() { - let contract = declare("CheatcodeChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); - let dispatcher = ICheatcodeCheckerDispatcher { contract_address }; - - let balance = dispatcher.get_balance(); - assert(balance == 0, 'balance == 0'); - - dispatcher.increase_balance(100); - - let balance = dispatcher.get_balance(); - assert(balance == 100, 'balance == 100'); -} -//ANCHOR_END:second_half - -mod dummy {} // trick `scarb fmt -c` diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo index 1a698e2d20..646dfdf4ea 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo @@ -1,2 +1,17 @@ -pub mod caller_address; -pub mod cheat_constructor; +use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; +use using_cheatcodes::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; + +#[test] +fn call_and_invoke() { + let contract = declare("CheatcodeChecker").unwrap().contract_class(); + let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let dispatcher = ICheatcodeCheckerDispatcher { contract_address }; + + let balance = dispatcher.get_balance(); + assert(balance == 0, 'balance == 0'); + + dispatcher.increase_balance(100); + + let balance = dispatcher.get_balance(); + assert(balance == 100, 'balance == 100'); +} diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml new file mode 100644 index 0000000000..2c57c48bfa --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml @@ -0,0 +1,17 @@ +[package] +name = "using_cheatcodes_canelling_cheat" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[dev-dependencies] +assert_macros.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo new file mode 100644 index 0000000000..b6c20ffcad --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo @@ -0,0 +1,55 @@ +#[starknet::interface] +pub trait ICheatcodeChecker { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; + fn get_block_number_at_construction(self: @TContractState) -> u64; + fn get_block_timestamp_at_construction(self: @TContractState) -> u64; +} + +#[starknet::contract] +pub mod CheatcodeChecker { + use core::box::BoxTrait; + use starknet::get_caller_address; + + #[storage] + struct Storage { + balance: felt252, + blk_nb: u64, + blk_timestamp: u64, + } + + #[constructor] + fn constructor(ref self: ContractState) { + // store the current block number + self.blk_nb.write(starknet::get_block_info().unbox().block_number); + // store the current block timestamp + self.blk_timestamp.write(starknet::get_block_info().unbox().block_timestamp); + } + + #[abi(embed_v0)] + impl ICheatcodeCheckerImpl of super::ICheatcodeChecker { + // Increases the balance by the given amount + fn increase_balance(ref self: ContractState, amount: felt252) { + assert_is_allowed_user(); + self.balance.write(self.balance.read() + amount); + } + // Gets the balance. + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + // Gets the block number + fn get_block_number_at_construction(self: @ContractState) -> u64 { + self.blk_nb.read() + } + // Gets the block timestamp + fn get_block_timestamp_at_construction(self: @ContractState) -> u64 { + self.blk_timestamp.read() + } + } + + fn assert_is_allowed_user() { + // checks if caller is '123' + let address = get_caller_address(); + assert(address.into() == 123, 'user is not allowed'); + } +} diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/cancel.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo similarity index 80% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/cancel.cairo rename to docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo index 2b550e0068..414246a13d 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/cancel.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo @@ -1,15 +1,13 @@ -//ANCHOR:first_half use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_caller_address, stop_cheat_caller_address }; -use using_cheatcodes::{ICheatcodeCheckerSafeDispatcher, ICheatcodeCheckerSafeDispatcherTrait}; +use using_cheatcodes_canelling_cheat::{ + ICheatcodeCheckerSafeDispatcher, ICheatcodeCheckerSafeDispatcherTrait +}; #[test] -//ANCHOR_END:first_half -#[should_panic(expected: 'Second call failed!')] -//ANCHOR:second_half #[feature("safe_dispatcher")] fn call_and_invoke() { let contract = declare("CheatcodeChecker").unwrap().contract_class(); @@ -37,6 +35,3 @@ fn call_and_invoke() { let balance = dispatcher.get_balance(); assert_eq!(balance, Result::Ok(100)); } -//ANCHOR_END:second_half - -mod dummy {} // trick `scarb fmt -c` diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml new file mode 100644 index 0000000000..3a88def6be --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml @@ -0,0 +1,17 @@ +[package] +name = "using_cheatcodes_cheat_address" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[dev-dependencies] +assert_macros.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo new file mode 100644 index 0000000000..b6c20ffcad --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo @@ -0,0 +1,55 @@ +#[starknet::interface] +pub trait ICheatcodeChecker { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; + fn get_block_number_at_construction(self: @TContractState) -> u64; + fn get_block_timestamp_at_construction(self: @TContractState) -> u64; +} + +#[starknet::contract] +pub mod CheatcodeChecker { + use core::box::BoxTrait; + use starknet::get_caller_address; + + #[storage] + struct Storage { + balance: felt252, + blk_nb: u64, + blk_timestamp: u64, + } + + #[constructor] + fn constructor(ref self: ContractState) { + // store the current block number + self.blk_nb.write(starknet::get_block_info().unbox().block_number); + // store the current block timestamp + self.blk_timestamp.write(starknet::get_block_info().unbox().block_timestamp); + } + + #[abi(embed_v0)] + impl ICheatcodeCheckerImpl of super::ICheatcodeChecker { + // Increases the balance by the given amount + fn increase_balance(ref self: ContractState, amount: felt252) { + assert_is_allowed_user(); + self.balance.write(self.balance.read() + amount); + } + // Gets the balance. + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + // Gets the block number + fn get_block_number_at_construction(self: @ContractState) -> u64 { + self.blk_nb.read() + } + // Gets the block timestamp + fn get_block_timestamp_at_construction(self: @ContractState) -> u64 { + self.blk_timestamp.read() + } + } + + fn assert_is_allowed_user() { + // checks if caller is '123' + let address = get_caller_address(); + assert(address.into() == 123, 'user is not allowed'); + } +} diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo similarity index 87% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use.cairo rename to docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo index cd4b71f24b..5c29b4d211 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo @@ -1,5 +1,5 @@ use snforge_std::{declare, ContractClassTrait, DeclareResultTrait, start_cheat_caller_address}; -use using_cheatcodes::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; +use using_cheatcodes_cheat_address::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; #[test] fn call_and_invoke() { diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml new file mode 100644 index 0000000000..316f64670e --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml @@ -0,0 +1,17 @@ +[package] +name = "using_cheatcodes_others" +version = "0.1.0" +edition = "2023_11" + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[dev-dependencies] +assert_macros.workspace = true + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo new file mode 100644 index 0000000000..b6c20ffcad --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo @@ -0,0 +1,55 @@ +#[starknet::interface] +pub trait ICheatcodeChecker { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; + fn get_block_number_at_construction(self: @TContractState) -> u64; + fn get_block_timestamp_at_construction(self: @TContractState) -> u64; +} + +#[starknet::contract] +pub mod CheatcodeChecker { + use core::box::BoxTrait; + use starknet::get_caller_address; + + #[storage] + struct Storage { + balance: felt252, + blk_nb: u64, + blk_timestamp: u64, + } + + #[constructor] + fn constructor(ref self: ContractState) { + // store the current block number + self.blk_nb.write(starknet::get_block_info().unbox().block_number); + // store the current block timestamp + self.blk_timestamp.write(starknet::get_block_info().unbox().block_timestamp); + } + + #[abi(embed_v0)] + impl ICheatcodeCheckerImpl of super::ICheatcodeChecker { + // Increases the balance by the given amount + fn increase_balance(ref self: ContractState, amount: felt252) { + assert_is_allowed_user(); + self.balance.write(self.balance.read() + amount); + } + // Gets the balance. + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + // Gets the block number + fn get_block_number_at_construction(self: @ContractState) -> u64 { + self.blk_nb.read() + } + // Gets the block timestamp + fn get_block_timestamp_at_construction(self: @ContractState) -> u64 { + self.blk_timestamp.read() + } + } + + fn assert_is_allowed_user() { + // checks if caller is '123' + let address = get_caller_address(); + assert(address.into() == 123, 'user is not allowed'); + } +} diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo new file mode 100644 index 0000000000..e8df5dd455 --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo @@ -0,0 +1,2 @@ +pub mod proper_use_global; +pub mod span; diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use_global.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo similarity index 93% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use_global.cairo rename to docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo index b810ded3f0..e8f4262be1 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use_global.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo @@ -2,7 +2,7 @@ use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_caller_address_global, stop_cheat_caller_address_global }; -use using_cheatcodes::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; +use using_cheatcodes_others::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; #[test] fn call_and_invoke_global() { diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/span.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo similarity index 93% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/span.cairo rename to docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo index 0b05f181bf..eec19b9e60 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/span.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo @@ -1,7 +1,9 @@ use snforge_std::{declare, ContractClassTrait, DeclareResultTrait, cheat_caller_address, CheatSpan}; use starknet::ContractAddress; -use using_cheatcodes::{ICheatcodeCheckerSafeDispatcher, ICheatcodeCheckerSafeDispatcherTrait}; +use using_cheatcodes_others::{ + ICheatcodeCheckerSafeDispatcher, ICheatcodeCheckerSafeDispatcherTrait +}; #[test] #[feature("safe_dispatcher")] diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/cheat_constructor.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo similarity index 91% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/cheat_constructor.cairo rename to docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo index 829d269a35..fa39e238fb 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/cheat_constructor.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo @@ -3,7 +3,7 @@ use snforge_std::{ start_cheat_block_timestamp }; -use using_cheatcodes::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; +use using_cheatcodes_others::{ICheatcodeCheckerDispatcher, ICheatcodeCheckerDispatcherTrait}; #[test] fn call_and_invoke() { diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo new file mode 100644 index 0000000000..1a698e2d20 --- /dev/null +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo @@ -0,0 +1,2 @@ +pub mod caller_address; +pub mod cheat_constructor; diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index aea3da6386..f634bd0d54 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -31,8 +31,7 @@ In this tutorial, we will be using the following Starknet contract: We can try to create a test that will increase and verify the balance. ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/failing.cairo:second_half}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo}} ``` This test fails, which means that `increase_balance` method panics as we expected. @@ -46,13 +45,17 @@ $ snforge test ```shell Collected 1 test(s) from using_cheatcodes package +Running 0 test(s) from src/ Running 1 test(s) from tests/ -[FAIL] using_cheatcodes_tests::caller_address::failing::call_and_invoke +[FAIL] using_cheatcodes_tests::call_and_invoke Failure data: 0x75736572206973206e6f7420616c6c6f776564 ('user is not allowed') Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out + +Failures: + using_cheatcodes_tests::call_and_invoke ```

@@ -68,7 +71,7 @@ address, so it passes our validation. ### Cheating an Address ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use.cairo}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo}} ``` The test will now pass without an error @@ -81,10 +84,10 @@ $ snforge test Output: ```shell -Collected 1 test(s) from using_cheatcodes package +Collected 1 test(s) from using_cheatcodes_cheat_address package Running 0 test(s) from src/ Running 1 test(s) from tests/ -[PASS] using_cheatcodes_integrationtest::caller_address::proper_use::call_and_invoke (gas: ~239) +[PASS] using_cheatcodes_cheat_address_tests::call_and_invoke (gas: ~239) Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -99,8 +102,7 @@ using [`stop_cheat_caller_address`](../appendix/cheatcodes/caller_address.md#sto We will demonstrate its behavior using `SafeDispatcher` to show when exactly the fail occurs: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/cancel.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/cancel.cairo:second_half}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo}} ``` ```shell @@ -111,15 +113,18 @@ $ snforge test Output: ```shell -Collected 1 test(s) from using_cheatcodes package -Running 0 test(s) from src/ +Collected 1 test(s) from using_cheatcodes_canelling_cheat package Running 1 test(s) from tests/ -[FAIL] using_cheatcodes_tests::caller_address::cancel::call_and_invoke +[FAIL] using_cheatcodes_canelling_cheat_tests::call_and_invoke Failure data: 0x5365636f6e642063616c6c206661696c656421 ('Second call failed!') -Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 4 filtered out +Running 0 test(s) from src/ +Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out + +Failures: + using_cheatcodes_canelling_cheat_tests::call_and_invoke ```

@@ -132,7 +137,7 @@ In case you want to cheat the caller address for all contracts, you can use the For more see [Cheating Globally](../appendix/cheatcodes/global.md). ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/proper_use_global.cairo}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo}} ``` ### Cheating the Constructor @@ -144,7 +149,7 @@ Let's say, that you have a contract that saves the caller address (deployer) in To `cheat_caller_address` the constructor, you need to `start_cheat_caller_address` before it is invoked, with the right address. To achieve this, you need to precalculate the address of the contract by using the `precalculate_address` function of `ContractClassTrait` on the declared contract, and then use it in `start_cheat_caller_address` as an argument: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/cheat_constructor.cairo}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo}} ``` ### Setting Cheatcode Span @@ -178,5 +183,5 @@ Of course the cheatcode can still be canceled before its `CheatSpan` goes down t To better understand the functionality of `CheatSpan`, here's a full example: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/caller_address/span.cairo}} +{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo}} ``` From 8449f5e64ea6f3ad5e361d4ba9b7bbe42003fe87 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 19 Nov 2024 17:20:30 +0100 Subject: [PATCH 053/183] Update outputs for workspaces --- docs/src/testing/running-tests.md | 17 ++--- docs/src/testing/testing-workspaces.md | 87 ++++++++++++++++++++------ 2 files changed, 76 insertions(+), 28 deletions(-) diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index a2ac328019..0b27b7161c 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -115,14 +115,15 @@ $ snforge test --detailed-resources Output: ```shell -Collected 1 test(s) from package_name package -Running 1 test(s) from src/ -[PASS] package_name::tests::resources (gas: ~2213) - steps: 881 - memory holes: 36 - builtins: ("range_check_builtin": 32) - syscalls: (StorageWrite: 1, StorageRead: 1, CallContract: 1) - +Collected 1 test(s) from hello_starknet package +Running 0 test(s) from src/ +Running 1 test(s) from tests/ +[PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) + steps: 4535 + memory holes: 15 + builtins: (range_check: 95, pedersen: 7) + syscalls: (StorageRead: 3, CallContract: 3, StorageWrite: 1, Deploy: 1) + Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index a959874cf4..3e04b3d8c0 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -46,10 +46,25 @@ $ snforge test Output: ```shell -Collected 1 test(s) from hello_workspaces package +Collected 3 test(s) from hello_workspaces package Running 1 test(s) from src/ -[PASS] hello_workspaces::tests::test_simple -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +[PASS] hello_workspaces::tests::test_simple (gas: ~1) +Running 2 test(s) from tests/ +[FAIL] hello_workspaces_integrationtest::test_failing::test_failing + +Failure data: + 0x6661696c696e6720636865636b ('failing check') + +[FAIL] hello_workspaces_integrationtest::test_failing::test_another_failing + +Failure data: + 0x6661696c696e6720636865636b ('failing check') + +Tests: 1 passed, 2 failed, 0 skipped, 0 ignored, 0 filtered out + +Failures: + hello_workspaces_integrationtest::test_failing::test_failing + hello_workspaces_integrationtest::test_failing::test_another_failing ```

@@ -66,12 +81,15 @@ $ snforge test --package addition Output: ```shell -Collected 2 test(s) from addition package +Collected 5 test(s) from addition package +Running 4 test(s) from tests/ +[PASS] addition_integrationtest::nested::test_nested::test_two (gas: ~1) +[PASS] addition_integrationtest::nested::test_nested::test_two_and_two (gas: ~1) +[PASS] addition_integrationtest::nested::simple_case (gas: ~1) +[PASS] addition_integrationtest::nested::contract_test (gas: ~1) Running 1 test(s) from src/ -[PASS] addition::tests::it_works -Running 1 test(s) from tests/ -[PASS] tests::test_simple::simple_case -Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +[PASS] addition::tests::it_works (gas: ~1) +Tests: 5 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

@@ -86,24 +104,53 @@ $ snforge test --workspace Output: ```shell -Collected 2 test(s) from addition package +Collected 5 test(s) from addition package +Running 4 test(s) from tests/ +[PASS] addition_integrationtest::nested::test_nested::test_two (gas: ~1) +[PASS] addition_integrationtest::nested::simple_case (gas: ~1) +[PASS] addition_integrationtest::nested::test_nested::test_two_and_two (gas: ~1) +[PASS] addition_integrationtest::nested::contract_test (gas: ~1) Running 1 test(s) from src/ -[PASS] addition::tests::it_works -Running 1 test(s) from tests/ -[PASS] tests::test_simple::simple_case -Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +[PASS] addition::tests::it_works (gas: ~1) +Tests: 5 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out -Collected 1 test(s) from fibonacci package -Running 1 test(s) from src/ -[PASS] fibonacci::tests::it_works -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Collected 6 test(s) from fibonacci package +Running 2 test(s) from src/ +[PASS] fibonacci::tests::it_works (gas: ~1) +[PASS] fibonacci::tests::contract_test (gas: ~1) +Running 4 test(s) from tests/ +[FAIL] fibonacci_tests::abc::efg::failing_test + +Failure data: + 0x0 ('') +[PASS] fibonacci_tests::abc::efg::efg_test (gas: ~1) +[PASS] fibonacci_tests::lib_test (gas: ~1) +[PASS] fibonacci_tests::abc::abc_test (gas: ~1) +Tests: 5 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out -Collected 1 test(s) from hello_workspaces package + +Collected 3 test(s) from hello_workspaces package Running 1 test(s) from src/ -[PASS] hello_workspaces::tests::test_simple -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +[PASS] hello_workspaces::tests::test_simple (gas: ~1) +Running 2 test(s) from tests/ +[FAIL] hello_workspaces_integrationtest::test_failing::test_another_failing + +Failure data: + 0x6661696c696e6720636865636b ('failing check') + +[FAIL] hello_workspaces_integrationtest::test_failing::test_failing + +Failure data: + 0x6661696c696e6720636865636b ('failing check') + +Tests: 1 passed, 2 failed, 0 skipped, 0 ignored, 0 filtered out + +Failures: + fibonacci_tests::abc::efg::failing_test + hello_workspaces_integrationtest::test_failing::test_another_failing + hello_workspaces_integrationtest::test_failing::test_failing ```

From a96064966215ab652cde51420d1664edaa319f85 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:03:56 +0100 Subject: [PATCH 054/183] Update command outputs docs --- docs/src/getting-started/first-steps.md | 15 ++++----- .../snforge-advanced-features/fuzz-testing.md | 10 +++--- docs/src/testing/contracts.md | 23 +++++++++----- .../testing/gas-and-resource-estimation.md | 18 +++++++---- docs/src/testing/running-tests.md | 31 +++++++++++-------- docs/src/testing/testing-workspaces.md | 1 - docs/src/testing/using-cheatcodes.md | 6 ++-- 7 files changed, 60 insertions(+), 44 deletions(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index d504761321..addc14d9ba 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -6,13 +6,13 @@ We demonstrate how to create a new project, compile, and test it. To start a new project with Starknet Foundry, run `snforge init` ```shell -$ snforge init project_name +$ snforge init hello_starknet ``` Let's check out the project structure ```shell -$ cd project_name +$ cd hello_starknet $ tree . -L 1 ``` @@ -47,15 +47,12 @@ $ snforge test Output: ```shell - Compiling project_name v0.1.0 (project_name/Scarb.toml) - Finished release target(s) in 1 second - -Collected 2 test(s) from project_name package +Collected 2 test(s) from hello_starknet package Running 0 test(s) from src/ Running 2 test(s) from tests/ -[PASS] tests::test_contract::test_increase_balance (gas: ~170) -[PASS] tests::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~104) -Tests: 2 passed, 0 failed, 0 skipped, 0 ignored +[PASS] hello_starknet_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~105) +[PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) +Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

diff --git a/docs/src/snforge-advanced-features/fuzz-testing.md b/docs/src/snforge-advanced-features/fuzz-testing.md index 4b6b579428..ebf2cc56dc 100644 --- a/docs/src/snforge-advanced-features/fuzz-testing.md +++ b/docs/src/snforge-advanced-features/fuzz-testing.md @@ -30,11 +30,11 @@ $ snforge test Output: ```shell -Collected 1 test(s) from fuzz_testing package -Running 1 test(s) from src/ -Running 0 test(s) from tests/ -[PASS] fuzz_testing::basic_example::test_sum (runs: 256, gas: {max: ~1, min: ~1, mean: ~1.00, std deviation: ~0.00}) -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Collected 2 test(s) from fuzz_testing package +Running 2 test(s) from src/ +[PASS] fuzz_testing::with_parameters::tests::test_sum (runs: 22, gas: {max: ~1, min: ~1, mean: ~1.00, std deviation: ~0.00}) +[PASS] fuzz_testing::basic_example::tests::test_sum (runs: 256, gas: {max: ~1, min: ~1, mean: ~1.00, std deviation: ~0.00}) +Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out Fuzzer seed: [..] ```
diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index ef10033567..d6e432c2ed 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -46,11 +46,19 @@ $ snforge test Output: ```shell -Collected 1 test(s) from testing_smart_contracts_writing_tests package -Running 1 test(s) from tests/ -[PASS] testing_smart_contracts_writing_tests_integrationtest::simple_contract::call_and_invoke (gas: ~172) +Collected 2 test(s) from testing_smart_contracts_handling_errors package +Running 2 test(s) from tests/ +[FAIL] testing_smart_contracts_handling_errors_integrationtest::panic::failing + +Failure data: + (0x50414e4943 ('PANIC'), 0x444159544148 ('DAYTAH')) + +[PASS] testing_smart_contracts_handling_errors_integrationtest::handle_panic::handling_string_errors (gas: ~103) Running 0 test(s) from src/ -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Tests: 1 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out + +Failures: + testing_smart_contracts_handling_errors_integrationtest::panic::failing ```

@@ -82,15 +90,16 @@ $ snforge test Output: ```shell -Collected 1 test(s) from testing_smart_contracts_handling_errors package -Running 1 test(s) from tests/ +Collected 2 test(s) from testing_smart_contracts_handling_errors package +Running 2 test(s) from tests/ [FAIL] testing_smart_contracts_handling_errors_integrationtest::panic::failing Failure data: (0x50414e4943 ('PANIC'), 0x444159544148 ('DAYTAH')) +[PASS] testing_smart_contracts_handling_errors_integrationtest::handle_panic::handling_string_errors (gas: ~103) Running 0 test(s) from src/ -Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out +Tests: 1 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: testing_smart_contracts_handling_errors_integrationtest::panic::failing diff --git a/docs/src/testing/gas-and-resource-estimation.md b/docs/src/testing/gas-and-resource-estimation.md index 9657c6b5aa..c91cb15782 100644 --- a/docs/src/testing/gas-and-resource-estimation.md +++ b/docs/src/testing/gas-and-resource-estimation.md @@ -44,16 +44,22 @@ $ snforge test --detailed-resources Output: ```shell -Collected 1 test(s) from hello_starknet package -Running 0 test(s) from src/ -Running 1 test(s) from tests/ +Collected 2 test(s) from hello_starknet package +Running 2 test(s) from tests/ +[PASS] hello_starknet_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~105) + steps: 3405 + memory holes: 22 + builtins: ([..]) + syscalls: ([..]) + [PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) steps: 4535 memory holes: 15 - builtins: (range_check: 95, pedersen: 7) - syscalls: (StorageRead: 3, CallContract: 3, StorageWrite: 1, Deploy: 1) + builtins: ([..]) + syscalls: ([..]) -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Running 0 test(s) from src/ +Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index 0b27b7161c..15d2dde9c1 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -11,11 +11,11 @@ $ snforge test ```shell Collected 3 test(s) from hello_snforge package +Running 0 test(s) from src/ Running 3 test(s) from tests/ -[PASS] hello_snforge_integrationtest::test_contract::test_another (gas: ~1) [PASS] hello_snforge_integrationtest::test_contract::test_calling (gas: ~1) [PASS] hello_snforge_integrationtest::test_contract::test_executing (gas: ~1) -Running 0 test(s) from src/ +[PASS] hello_snforge_integrationtest::test_contract::test_calling_another (gas: ~1) Tests: 3 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
@@ -86,19 +86,18 @@ $ snforge test --exit-first ```shell Collected 3 test(s) from failing_example package -Running 0 test(s) from src/ Running 3 test(s) from tests/ -[FAIL] failing_example_integrationtest::test_contract::test_failing +[FAIL] failing_example_tests::test_failing Failure data: 0x6661696c696e6720636865636b ('failing check') -[PASS] failing_example_integrationtest::test_contract::test_abc (gas: ~1) -[PASS] failing_example_integrationtest::test_contract::test_xyz (gas: ~1) +[PASS] failing_example_tests::test_abc (gas: ~1) +[PASS] failing_example_tests::test_xyz (gas: ~1) Tests: 2 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: - failing_example_integrationtest::test_contract::test_failing + failing_example_tests::test_failing ```

@@ -115,16 +114,22 @@ $ snforge test --detailed-resources Output: ```shell -Collected 1 test(s) from hello_starknet package -Running 0 test(s) from src/ -Running 1 test(s) from tests/ +Collected 2 test(s) from hello_starknet package +Running 2 test(s) from tests/ +[PASS] hello_starknet_integrationtest::test_contract::test_cannot_increase_balance_with_zero_value (gas: ~105) + steps: 3405 + memory holes: 22 + builtins: ([..]) + syscalls: ([..]) + [PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (gas: ~172) steps: 4535 memory holes: 15 - builtins: (range_check: 95, pedersen: 7) - syscalls: (StorageRead: 3, CallContract: 3, StorageWrite: 1, Deploy: 1) + builtins: ([..]) + syscalls: ([..]) -Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out +Running 0 test(s) from src/ +Tests: 2 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```

diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index 3e04b3d8c0..460d1bdb91 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -72,7 +72,6 @@ Failures: To select the specific package to test, pass a `--package package_name` (or `-p package_name` for short) flag. You can also run `snforge test` from the package directory to achieve the same effect. - ```shell $ snforge test --package addition ``` diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index f634bd0d54..eb48c3b976 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -113,9 +113,9 @@ $ snforge test Output: ```shell -Collected 1 test(s) from using_cheatcodes_canelling_cheat package +Collected 1 test(s) from using_cheatcodes_cancelling_cheat package Running 1 test(s) from tests/ -[FAIL] using_cheatcodes_canelling_cheat_tests::call_and_invoke +[FAIL] using_cheatcodes_cancelling_cheat_tests::call_and_invoke Failure data: 0x5365636f6e642063616c6c206661696c656421 ('Second call failed!') @@ -124,7 +124,7 @@ Running 0 test(s) from src/ Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: - using_cheatcodes_canelling_cheat_tests::call_and_invoke + using_cheatcodes_cancelling_cheat_tests::call_and_invoke ```

From 826be457f7d1d2341b1ab8629f3c78e3f1e07d8d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:34:16 +0100 Subject: [PATCH 055/183] Update packages and manifests in docs listings --- .../crates/conditional_compilation/Scarb.toml | 4 +- .../crates/direct_storage_access/Scarb.toml | 4 +- .../crates/fork_testing/Scarb.toml | 4 +- .../crates/fuzz_testing/Scarb.toml | 5 ++- .../tests/{test_contract.cairo => lib.cairo} | 0 .../crates/first_test/Scarb.toml | 2 + .../hello_starknet/tests/test_contract.cairo | 18 +++++++++ .../crates/ignoring_example/Scarb.toml | 2 + .../crates/panicking_test/Scarb.toml | 2 + .../crates/should_panic_test/Scarb.toml | 2 + .../testing_contract_internals/Scarb.toml | 2 + .../crates/testing_events/Scarb.toml | 2 + .../crates/testing_messages_to_l1/Scarb.toml | 2 + .../Scarb.toml | 2 + .../tests/handle_panic.cairo | 2 +- .../Scarb.toml | 2 + .../Scarb.toml | 2 + .../src/lib.cairo | 37 +++++++++++-------- .../tests/simple_contract.cairo | 2 +- .../crates/using_cheatcodes/Scarb.toml | 4 +- .../Scarb.toml | 6 +-- .../tests/lib.cairo | 2 +- .../using_cheatcodes_cheat_address/Scarb.toml | 4 +- .../crates/using_cheatcodes_others/Scarb.toml | 4 +- .../crates/writing_tests_orig/Scarb.toml | 2 + 25 files changed, 86 insertions(+), 32 deletions(-) rename docs/listings/snforge_overview/crates/failing_example/tests/{test_contract.cairo => lib.cairo} (100%) diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml b/docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml index 598a980be5..7562310842 100644 --- a/docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml +++ b/docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml @@ -9,9 +9,11 @@ enable_for_tests = [] [dependencies] starknet.workspace = true -snforge_std.workspace = true assert_macros.workspace = true +[dev-dependencies] +snforge_std.workspace = true + [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml b/docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml index 118608e7cb..4662e35f46 100644 --- a/docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml +++ b/docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml @@ -5,9 +5,11 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true assert_macros.workspace = true +[dev-dependencies] +snforge_std.workspace = true + [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml b/docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml index ba8e0d5257..36eda9eda5 100644 --- a/docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml +++ b/docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml @@ -5,9 +5,11 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true assert_macros.workspace = true +[dev-dependencies] +snforge_std.workspace = true + [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml b/docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml index 147edffe81..bd9e3c1248 100644 --- a/docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml +++ b/docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml @@ -4,9 +4,12 @@ version = "0.1.0" edition = "2023_11" [dependencies] -snforge_std.workspace = true +starknet.workspace = true assert_macros.workspace = true +[dev-dependencies] +snforge_std.workspace = true + [[target.lib]] sierra = true diff --git a/docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/failing_example/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/failing_example/tests/test_contract.cairo rename to docs/listings/snforge_overview/crates/failing_example/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/first_test/Scarb.toml b/docs/listings/snforge_overview/crates/first_test/Scarb.toml index 6e0a381d4a..80a3666c8d 100644 --- a/docs/listings/snforge_overview/crates/first_test/Scarb.toml +++ b/docs/listings/snforge_overview/crates/first_test/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo b/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo index 8e60dbfcce..b1f395afc1 100644 --- a/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo +++ b/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo @@ -27,3 +27,21 @@ fn test_increase_balance() { let balance_after = dispatcher.get_balance(); assert(balance_after == 42, 'Invalid balance'); } + +#[test] +#[feature("safe_dispatcher")] +fn test_cannot_increase_balance_with_zero_value() { + let contract_address = deploy_contract("HelloStarknet"); + + let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; + + let balance_before = safe_dispatcher.get_balance().unwrap(); + assert(balance_before == 0, 'Invalid balance'); + + match safe_dispatcher.increase_balance(0) { + Result::Ok(_) => core::panic_with_felt252('Should have panicked'), + Result::Err(panic_data) => { + assert(*panic_data.at(0) == 'Amount cannot be 0', *panic_data.at(0)); + } + }; +} diff --git a/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml b/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml index 37dc52f448..adaf6ad058 100644 --- a/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml +++ b/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml b/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml index b79df6ce0f..260e51c923 100644 --- a/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml +++ b/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml b/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml index be1bd297ee..0ca0e3e93d 100644 --- a/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml +++ b/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml index fd0ff87b5c..3c18aab37c 100644 --- a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml index b712ac493f..d438c69dde 100644 --- a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_events/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml index bee7f589eb..fe4d5827ff 100644 --- a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml index ae20249296..1e812c00cd 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo index ec8d8b2537..ea182b9100 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo @@ -2,7 +2,7 @@ use snforge_std::byte_array::try_deserialize_bytearray_error; use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use testing_smart_contracts::handling_errors::{ +use testing_smart_contracts_handling_errors::{ IPanicContractSafeDispatcher, IPanicContractSafeDispatcherTrait }; diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml index 3850e037e7..2d3d210cd5 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml index ccd121ff1f..2eb5069cc5 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo index 832961c6b7..af38fd767e 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo @@ -1,21 +1,26 @@ -use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; +#[starknet::interface] +pub trait ISimpleContract { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; +} -use testing_smart_contracts_handling_errors::{ - IPanicContractSafeDispatcher, IPanicContractSafeDispatcherTrait -}; +#[starknet::contract] +pub mod SimpleContract { + #[storage] + struct Storage { + balance: felt252, + } -#[test] -#[feature("safe_dispatcher")] -fn handling_errors() { - let contract = declare("PanicContract").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); - let safe_dispatcher = IPanicContractSafeDispatcher { contract_address }; + #[abi(embed_v0)] + pub impl SimpleContractImpl of super::ISimpleContract { + // Increases the balance by the given amount + fn increase_balance(ref self: ContractState, amount: felt252) { + self.balance.write(self.balance.read() + amount); + } - match safe_dispatcher.do_a_panic() { - Result::Ok(_) => panic!("Entrypoint did not panic"), - Result::Err(panic_data) => { - assert(*panic_data.at(0) == 'PANIC', *panic_data.at(0)); - assert(*panic_data.at(1) == 'DAYTAH', *panic_data.at(1)); + // Gets the balance. + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() } - }; + } } diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo index c55f0f5a68..c47b4ed808 100644 --- a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo +++ b/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo @@ -1,6 +1,6 @@ use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; -use testing_smart_contracts_handling_errors::{ +use testing_smart_contracts_writing_tests::{ ISimpleContractDispatcher, ISimpleContractDispatcherTrait }; diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml index 7a5cccb821..29c011667a 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml @@ -5,10 +5,10 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +assert_macros.workspace = true [dev-dependencies] -assert_macros.workspace = true +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml index 2c57c48bfa..ae4219aafe 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml @@ -1,14 +1,14 @@ [package] -name = "using_cheatcodes_canelling_cheat" +name = "using_cheatcodes_cancelling_cheat" version = "0.1.0" edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +assert_macros.workspace = true [dev-dependencies] -assert_macros.workspace = true +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo index 414246a13d..3024c98a43 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo @@ -3,7 +3,7 @@ use snforge_std::{ stop_cheat_caller_address }; -use using_cheatcodes_canelling_cheat::{ +use using_cheatcodes_cancelling_cheat::{ ICheatcodeCheckerSafeDispatcher, ICheatcodeCheckerSafeDispatcherTrait }; diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml index 3a88def6be..bf870bebeb 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml @@ -5,10 +5,10 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +assert_macros.workspace = true [dev-dependencies] -assert_macros.workspace = true +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml b/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml index 316f64670e..918843648a 100644 --- a/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml +++ b/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml @@ -5,10 +5,10 @@ edition = "2023_11" [dependencies] starknet.workspace = true -snforge_std.workspace = true +assert_macros.workspace = true [dev-dependencies] -assert_macros.workspace = true +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml b/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml index 08adb9be1b..86f60ecd38 100644 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml +++ b/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml @@ -5,6 +5,8 @@ edition = "2023_11" [dependencies] starknet.workspace = true + +[dev-dependencies] snforge_std.workspace = true [[target.starknet-contract]] From 0574214bb4a059d1ab02747bdf8cfbf035b0126d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:37:04 +0100 Subject: [PATCH 056/183] Add `SnippetType` enum; Add `output` and `snippet_type` fields in `Snippet` --- crates/docs/src/validation.rs | 58 +++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index ea801187d9..b4e615d584 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -6,10 +6,37 @@ use std::{ const EXTENSION: Option<&str> = Some("md"); +#[derive(Clone, Debug)] +pub enum SnippetType { + Forge, + Sncast, +} + +impl SnippetType { + pub fn as_str(&self) -> &'static str { + match self { + SnippetType::Forge => "snforge", + SnippetType::Sncast => "sncast", + } + } + + pub fn get_re(&self) -> Regex { + let pattern = format!( + r"(?ms)^```shell\n\$ ({} [^\n]+)\n```\s*(?:
\nOutput:\n\n```shell\n([\s\S]+?)\n```\s*<\/details>)?", + self.as_str() + ); + + Regex::new(&pattern).unwrap() + } +} + +#[derive(Debug)] pub struct Snippet { pub command: String, + pub output: Option, pub file_path: String, pub line_start: usize, + pub snippet_type: SnippetType, } impl Snippet { @@ -28,33 +55,52 @@ impl Snippet { .map(|arg| arg.trim().to_string()) .collect() } + + pub fn capture_package_from_output(&self) -> Option { + let re = + Regex::new(r"Collected \d+ test\(s\) from ([a-zA-Z_][a-zA-Z0-9_]*) package").unwrap(); + + re.captures_iter(&self.output.as_ref()?) + .filter_map(|caps| caps.get(1)) + .last() + .map(|m| m.as_str().to_string()) + } } -pub fn extract_snippets_from_file(file_path: &Path, re: &Regex) -> io::Result> { +pub fn extract_snippets_from_file( + file_path: &Path, + snippet_type: &SnippetType, +) -> io::Result> { let content = fs::read_to_string(file_path)?; let file_path_str = file_path .to_str() .expect("Failed to get file path") .to_string(); - let snippets = re + let snippets = snippet_type + .get_re() .captures_iter(&content) .filter_map(|caps| { let command_match = caps.get(1)?; let match_start = caps.get(0)?.start(); + let output = caps.get(2).map(|m| m.as_str().to_string()); Some(Snippet { command: command_match.as_str().to_string(), + output, file_path: file_path_str.clone(), line_start: content[..match_start].lines().count() + 1, + snippet_type: snippet_type.clone(), }) }) .collect(); - Ok(snippets) } -pub fn extract_snippets_from_directory(dir_path: &Path, re: &Regex) -> io::Result> { +pub fn extract_snippets_from_directory( + dir_path: &Path, + snippet_type: &SnippetType, +) -> io::Result> { let mut all_snippets = Vec::new(); let files = walkdir::WalkDir::new(dir_path) @@ -68,7 +114,7 @@ pub fn extract_snippets_from_directory(dir_path: &Path, re: &Regex) -> io::Resul if EXTENSION.map_or(true, |ext| { path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) }) { - let snippets = extract_snippets_from_file(path, re)?; + let snippets = extract_snippets_from_file(path, &snippet_type)?; all_snippets.extend(snippets); } } @@ -98,7 +144,7 @@ pub fn assert_valid_snippet( ) { assert!( condition, - "Found invalid {} snippet in the docs in file: {} at line {}\n{}", + "Found invalid {} snippet in the docs in at {}:{}:1\n{}", tool_name, snippet.file_path, snippet.line_start, err_message ); } From 67346ea9f6259df5586655423f14ce1af040db30 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:38:00 +0100 Subject: [PATCH 057/183] Add `setup_package_from_docs_listings` --- crates/forge/tests/e2e/common/runner.rs | 34 ++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 8168be27c6..9c9cb86d3b 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -5,6 +5,7 @@ use indoc::formatdoc; use shared::command::CommandExt; use shared::test_utils::node_url::node_rpc_url; use snapbox::cmd::{cargo_bin, Command as SnapboxCommand}; +use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; @@ -44,7 +45,7 @@ pub(crate) fn setup_package_with_file_patterns( .unwrap() .to_string() .replace('\\', "/"); - temp.copy_from(package_path, file_patterns).unwrap(); + temp.copy_from(package_path.clone(), file_patterns).unwrap(); let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std") .unwrap() @@ -65,6 +66,12 @@ pub(crate) fn setup_package_with_file_patterns( value(get_assert_macros_version().unwrap().to_string()); scarb_toml["target.starknet-contract"]["sierra"] = value(true); + if package_path.contains("docs/listings") { + scarb_toml["dev-dependencies"]["snforge_std"] + .as_table_mut() + .and_then(|snforge_std| snforge_std.remove("workspace")); + } + manifest_path.write_str(&scarb_toml.to_string()).unwrap(); // TODO (#2074): do that on .cairo.template files only @@ -78,8 +85,29 @@ pub(crate) fn setup_package(package_name: &str) -> TempDir { setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) } -pub(crate) fn setup_package_from_docs_listings(package_name: &str) -> TempDir { - let package_path = "../../docs/listings/snforge_overview/crates/".to_string() + package_name; +fn get_listing_name( + package: &str, + packages_mapping: &HashMap>, +) -> Option { + packages_mapping + .iter() + .find(|(_, packages)| packages.contains(&package.to_string())) + .map(|(listing_name, _)| listing_name.clone()) +} + +pub(crate) fn setup_package_from_docs_listings( + package_name: &str, + packages_mapping: &HashMap>, +) -> TempDir { + let listing_name = get_listing_name(package_name, &packages_mapping).expect(&format!( + "Couldn't find listing for package {}", + package_name + )); + let package_path = format!( + "../../docs/listings/{}/crates/{}", + listing_name, package_name + ); + setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) } From 127842af0bf7e4360e5aab94f2054fea7e71cbdb Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:38:54 +0100 Subject: [PATCH 058/183] Add util functions to retrieve mapping of docs listing -> crates --- crates/docs/src/validation.rs | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index b4e615d584..be4706a936 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -1,8 +1,10 @@ use regex::Regex; use std::{ + collections::HashMap, env, fs, io, path::{Path, PathBuf}, }; +use walkdir::WalkDir; const EXTENSION: Option<&str> = Some("md"); @@ -159,3 +161,52 @@ pub fn print_skipped_snippet_message(snippet: &Snippet, tool_name: &str) { tool_name, snippet.file_path, snippet.line_start ); } + +pub fn create_listings_to_packages_mapping() -> HashMap> { + let docs_listings_path = "../../docs/listings"; + let mut mapping = HashMap::new(); + + for listing in WalkDir::new(docs_listings_path) + .min_depth(1) + .max_depth(1) + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.file_type().is_dir()) + { + let listing_path = listing.path(); + let crates_dir = listing_path.join("crates"); + + if crates_dir.is_dir() { + let packages = list_packages_in_directory(&crates_dir); + if let Some(listing_name) = listing_path.file_name().and_then(|x| x.to_str()) { + if !packages.is_empty() { + mapping.insert(listing_name.to_string(), packages); + } + } + } + } + + mapping +} + +fn list_packages_in_directory(dir_path: &PathBuf) -> Vec { + let crates_path = dir_path.join(""); + + if crates_path.exists() && crates_path.is_dir() { + WalkDir::new(crates_path) + .min_depth(1) + .max_depth(1) + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.path().is_dir()) + .filter_map(|e| { + e.path() + .file_name() + .and_then(|name| name.to_str()) + .map(String::from) + }) + .collect() + } else { + Vec::new() + } +} From f01065da1c4ca693a5bbd2adf63da495c1cb0bfa Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:40:31 +0100 Subject: [PATCH 059/183] Add command execution in forge docs snippets test --- .../tests/e2e/docs_snippets_validation.rs | 69 ++++++++++++++++--- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index d69b5adf46..43c9c0867e 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,43 +1,92 @@ +use std::collections::HashMap; + use clap::Parser; use docs::validation::{ - assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, - print_skipped_snippet_message, print_success_message, + assert_valid_snippet, create_listings_to_packages_mapping, extract_snippets_from_directory, + get_parent_dir, print_skipped_snippet_message, print_success_message, SnippetType, }; use forge::Cli; -use regex::Regex; +use shared::test_utils::output_assert::assert_stdout_contains; + +use super::common::runner::{ + setup_hello_workspace, setup_package, setup_package_from_docs_listings, test_runner, +}; + +fn is_package_from_docs_listings( + package: &str, + listings_to_packages_mapping: &HashMap>, +) -> bool { + for (_, packages) in listings_to_packages_mapping { + if packages.contains(&package.to_string()) { + return true; + } + } + false +} + #[test] fn test_docs_snippets() { + let listings_to_packages_mapping = create_listings_to_packages_mapping(); + let root_dir = get_parent_dir(2); let docs_dir = root_dir.join("docs/src"); - let re = Regex::new(r"(?ms)```shell\n\$ (snforge .+?)\n```").expect("Invalid regex pattern"); + let snippet_type = SnippetType::Forge; - let snippets = extract_snippets_from_directory(&docs_dir, &re) + let snippets = extract_snippets_from_directory(&docs_dir, &snippet_type) .expect("Failed to extract snforge command snippets"); // TODO(#2684) let skipped_args = [ - // for some reason `try_parse_from` fails on `--version` flag + // For some reason `try_parse_from` fails on `--version` flag, it returns Err but procudes the expected output + // Not sure if this edge case is worth handling vec!["snforge", "--version"], ]; for snippet in &snippets { let args = snippet.to_command_args(); - let args: Vec<&str> = args.iter().map(String::as_str).collect(); + let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); if skipped_args.contains(&args) { - print_skipped_snippet_message(snippet, "snforge"); + print_skipped_snippet_message(snippet, snippet_type.as_str()); continue; } - let parse_result = Cli::try_parse_from(args); + let parse_result = Cli::try_parse_from(args.clone()); let err_message = if let Err(err) = &parse_result { err.to_string() } else { String::new() }; + assert_valid_snippet(parse_result.is_ok(), snippet, "snforge", &err_message); + + args.retain(|element| element != &"snforge" && element != &"test"); + + if let Some(snippet_output) = &snippet.output { + let package = snippet + .capture_package_from_output() + .expect("Failed to capture package from command output"); + + let temp = if is_package_from_docs_listings(&package, &listings_to_packages_mapping) { + setup_package_from_docs_listings(&package, &listings_to_packages_mapping) + } else { + let package = if ["addition", "fibonacci"].contains(&package.as_str()) { + "hello_workspaces" + } else { + &package + }; + if package == "hello_workspaces" { + setup_hello_workspace() + } else { + setup_package(&package) + } + }; + let output = test_runner(&temp).args(args).assert(); + + assert_stdout_contains(output, snippet_output); + } } - print_success_message(snippets.len(), "snforge"); + print_success_message(snippets.len(), snippet_type.as_str()); } From 6caf67ba1403952252ea4a3c6b8d7b592b2a3d65 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 19:44:09 +0100 Subject: [PATCH 060/183] Fix linting --- crates/forge/tests/e2e/common/runner.rs | 11 +++-------- crates/forge/tests/e2e/docs_snippets_validation.rs | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 9c9cb86d3b..49bbac40c6 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -99,14 +99,9 @@ pub(crate) fn setup_package_from_docs_listings( package_name: &str, packages_mapping: &HashMap>, ) -> TempDir { - let listing_name = get_listing_name(package_name, &packages_mapping).expect(&format!( - "Couldn't find listing for package {}", - package_name - )); - let package_path = format!( - "../../docs/listings/{}/crates/{}", - listing_name, package_name - ); + let listing_name = get_listing_name(package_name, packages_mapping) + .unwrap_or_else(|| panic!("Couldn't find listing for package {package_name}")); + let package_path = format!("../../docs/listings/{listing_name}/crates/{package_name}",); setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 43c9c0867e..3f14b6dedd 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -16,7 +16,7 @@ fn is_package_from_docs_listings( package: &str, listings_to_packages_mapping: &HashMap>, ) -> bool { - for (_, packages) in listings_to_packages_mapping { + for packages in listings_to_packages_mapping.values() { if packages.contains(&package.to_string()) { return true; } @@ -79,7 +79,7 @@ fn test_docs_snippets() { if package == "hello_workspaces" { setup_hello_workspace() } else { - setup_package(&package) + setup_package(package) } }; let output = test_runner(&temp).args(args).assert(); From eb9520539cac1ac0b5447185711fcd6e064d9917 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 21:07:09 +0100 Subject: [PATCH 061/183] Run `scarb fmt` --- .../crates/detailed_resources_example/src/lib.cairo | 2 +- .../snforge_overview/crates/failing_example/src/lib.cairo | 2 +- .../snforge_overview/crates/hello_snforge/src/lib.cairo | 2 +- .../snforge_overview/crates/panicking_test/src/lib.cairo | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo b/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo index 8cd1124d6d..4955786578 100644 --- a/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo @@ -8,7 +8,7 @@ pub trait IHelloStarknet { mod HelloStarknet { #[storage] struct Storage { - balance: felt252, + balance: felt252, } #[abi(embed_v0)] diff --git a/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo b/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo index 8cd1124d6d..4955786578 100644 --- a/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo @@ -8,7 +8,7 @@ pub trait IHelloStarknet { mod HelloStarknet { #[storage] struct Storage { - balance: felt252, + balance: felt252, } #[abi(embed_v0)] diff --git a/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo b/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo index 8cd1124d6d..4955786578 100644 --- a/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo @@ -8,7 +8,7 @@ pub trait IHelloStarknet { mod HelloStarknet { #[storage] struct Storage { - balance: felt252, + balance: felt252, } #[abi(embed_v0)] diff --git a/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo b/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo index 3d179acb26..b105f93712 100644 --- a/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo @@ -19,3 +19,4 @@ mod tests { } //ANCHOR_END:second_half + From 1c2a863f014dff95524430162e5c32dfd8e5b342 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 21:21:31 +0100 Subject: [PATCH 062/183] Use `scarb check` in `verify_cairo_listings.sh` --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 6f5f4245c3..89a0d7aa97 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb test); done +for d in ./docs/listings/*; do (cd "$d" && scarb check); done From 95d9bb9dd2f9139b5d13577a622ff83c186a5f4c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 21:27:01 +0100 Subject: [PATCH 063/183] Fix linting --- crates/docs/src/validation.rs | 11 +++++++---- crates/sncast/tests/docs_snippets/validation.rs | 9 ++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index be4706a936..35b5b82fa0 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -15,13 +15,15 @@ pub enum SnippetType { } impl SnippetType { - pub fn as_str(&self) -> &'static str { + #[must_use] + pub fn as_str(&self) -> &str { match self { SnippetType::Forge => "snforge", SnippetType::Sncast => "sncast", } } + #[must_use] pub fn get_re(&self) -> Regex { let pattern = format!( r"(?ms)^```shell\n\$ ({} [^\n]+)\n```\s*(?:
\nOutput:\n\n```shell\n([\s\S]+?)\n```\s*<\/details>)?", @@ -58,11 +60,12 @@ impl Snippet { .collect() } + #[must_use] pub fn capture_package_from_output(&self) -> Option { let re = Regex::new(r"Collected \d+ test\(s\) from ([a-zA-Z_][a-zA-Z0-9_]*) package").unwrap(); - re.captures_iter(&self.output.as_ref()?) + re.captures_iter(self.output.as_ref()?) .filter_map(|caps| caps.get(1)) .last() .map(|m| m.as_str().to_string()) @@ -116,7 +119,7 @@ pub fn extract_snippets_from_directory( if EXTENSION.map_or(true, |ext| { path.extension().and_then(|path_ext| path_ext.to_str()) == Some(ext) }) { - let snippets = extract_snippets_from_file(path, &snippet_type)?; + let snippets = extract_snippets_from_file(path, snippet_type)?; all_snippets.extend(snippets); } } @@ -189,7 +192,7 @@ pub fn create_listings_to_packages_mapping() -> HashMap> { mapping } -fn list_packages_in_directory(dir_path: &PathBuf) -> Vec { +fn list_packages_in_directory(dir_path: &Path) -> Vec { let crates_path = dir_path.join(""); if crates_path.exists() && crates_path.is_dir() { diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 2d649b86d0..06425f90fa 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,8 +1,7 @@ use docs::validation::{ assert_valid_snippet, extract_snippets_from_directory, extract_snippets_from_file, - get_parent_dir, print_skipped_snippet_message, print_success_message, Snippet, + get_parent_dir, print_skipped_snippet_message, print_success_message, Snippet, SnippetType, }; -use regex::Regex; use tempfile::tempdir; use crate::helpers::runner::runner; @@ -15,12 +14,12 @@ fn test_docs_snippets() { let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); - let re = Regex::new(r"(?ms)```shell\n\$ sncast(.+?)\n```").expect("Invalid regex pattern"); + let snippet_type = SnippetType::Sncast; - let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &re) + let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &snippet_type) .expect("Failed to extract sncast command snippets"); - let readme_snippets = extract_snippets_from_file(&sncast_readme_path, &re) + let readme_snippets = extract_snippets_from_file(&sncast_readme_path, &snippet_type) .expect("Failed to extract sncast command snippets"); let snippets = docs_snippets From d8481b06db0c7843237ad15b7e336e6c4b83db3e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 21:38:26 +0100 Subject: [PATCH 064/183] Run `scarb fmt` --- .../snforge_overview/crates/hello_starknet/src/lib.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo b/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo index 8cd1124d6d..4955786578 100644 --- a/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo +++ b/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo @@ -8,7 +8,7 @@ pub trait IHelloStarknet { mod HelloStarknet { #[storage] struct Storage { - balance: felt252, + balance: felt252, } #[abi(embed_v0)] From 09bac46e5ad00a93e81c9802ae89ae7507a452cc Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 20 Nov 2024 21:38:33 +0100 Subject: [PATCH 065/183] Fix typo --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 3f14b6dedd..9fccf3c6cc 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -38,7 +38,7 @@ fn test_docs_snippets() { // TODO(#2684) let skipped_args = [ - // For some reason `try_parse_from` fails on `--version` flag, it returns Err but procudes the expected output + // For some reason `try_parse_from` fails on `--version` flag, it returns Err but produces the expected output // Not sure if this edge case is worth handling vec!["snforge", "--version"], ]; From ae39133afe280bb4386538847328ec639400e1b7 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 09:39:46 +0100 Subject: [PATCH 066/183] Remove comment --- crates/forge/tests/e2e/docs_snippets_validation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 9fccf3c6cc..306e34874f 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -39,7 +39,6 @@ fn test_docs_snippets() { // TODO(#2684) let skipped_args = [ // For some reason `try_parse_from` fails on `--version` flag, it returns Err but produces the expected output - // Not sure if this edge case is worth handling vec!["snforge", "--version"], ]; From 7703ce6291cd8a67be190cc137de787398bc7e87 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 09:48:46 +0100 Subject: [PATCH 067/183] Update sncast docs snippets test --- crates/docs/src/validation.rs | 2 +- crates/sncast/tests/docs_snippets/validation.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 35b5b82fa0..b60b7492c1 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -26,7 +26,7 @@ impl SnippetType { #[must_use] pub fn get_re(&self) -> Regex { let pattern = format!( - r"(?ms)^```shell\n\$ ({} [^\n]+)\n```\s*(?:
\nOutput:\n\n```shell\n([\s\S]+?)\n```\s*<\/details>)?", + r"(?ms)^```shell\n\$ ({} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?", self.as_str() ); diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 06425f90fa..265e42ebf0 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -48,7 +48,10 @@ fn test_docs_snippets() { for snippet in &snippets { let args = snippet.to_command_args(); - let args: Vec<&str> = args.iter().map(String::as_str).collect(); + let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); + + // remove "sncast" from the args + args.remove(0); if skipped_args.contains(&args) { print_skipped_snippet_message(snippet, "sncast"); From a106627e205b149bfcf01a0a2fb0893f3a1a21c0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 11:42:03 +0100 Subject: [PATCH 068/183] Refactor `test_docs_snippets` in forge --- .../tests/e2e/docs_snippets_validation.rs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 306e34874f..7374c472cc 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use assert_fs::TempDir; use clap::Parser; use docs::validation::{ assert_valid_snippet, create_listings_to_packages_mapping, extract_snippets_from_directory, @@ -63,24 +64,17 @@ fn test_docs_snippets() { args.retain(|element| element != &"snforge" && element != &"test"); if let Some(snippet_output) = &snippet.output { - let package = snippet + let package_name = snippet .capture_package_from_output() .expect("Failed to capture package from command output"); - let temp = if is_package_from_docs_listings(&package, &listings_to_packages_mapping) { - setup_package_from_docs_listings(&package, &listings_to_packages_mapping) - } else { - let package = if ["addition", "fibonacci"].contains(&package.as_str()) { - "hello_workspaces" + let temp = + if is_package_from_docs_listings(&package_name, &listings_to_packages_mapping) { + setup_package_from_docs_listings(&package_name, &listings_to_packages_mapping) } else { - &package + resolve_package_name(&package_name) }; - if package == "hello_workspaces" { - setup_hello_workspace() - } else { - setup_package(package) - } - }; + let output = test_runner(&temp).args(args).assert(); assert_stdout_contains(output, snippet_output); @@ -89,3 +83,10 @@ fn test_docs_snippets() { print_success_message(snippets.len(), snippet_type.as_str()); } + +fn resolve_package_name(package_name: &str) -> TempDir { + match package_name { + "addition" | "fibonacci" => setup_hello_workspace(), + _ => setup_package(package_name), + } +} From 44077333aa7699486089673e2759fcf66394aed4 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 11:47:36 +0100 Subject: [PATCH 069/183] Refactor util functions --- crates/docs/src/validation.rs | 18 +++++++++--------- .../tests/e2e/docs_snippets_validation.rs | 10 +++++++--- .../sncast/tests/docs_snippets/validation.rs | 10 +++++----- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index b60b7492c1..375a7b73a3 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -141,16 +141,14 @@ pub fn get_parent_dir(levels_up: usize) -> PathBuf { dir } -pub fn assert_valid_snippet( - condition: bool, - snippet: &Snippet, - tool_name: &str, - err_message: &str, -) { +pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &str) { assert!( condition, "Found invalid {} snippet in the docs in at {}:{}:1\n{}", - tool_name, snippet.file_path, snippet.line_start, err_message + snippet.snippet_type.as_str(), + snippet.file_path, + snippet.line_start, + err_message ); } @@ -158,10 +156,12 @@ pub fn print_success_message(snippets_len: usize, tool_name: &str) { println!("Successfully validated {snippets_len} {tool_name} docs snippets"); } -pub fn print_skipped_snippet_message(snippet: &Snippet, tool_name: &str) { +pub fn print_skipped_snippet_message(snippet: &Snippet) { println!( "Skipped validation of {} snippet in the docs in file: {} at line {}", - tool_name, snippet.file_path, snippet.line_start + snippet.snippet_type.as_str(), + snippet.file_path, + snippet.line_start, ); } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 7374c472cc..4de50ddb93 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -48,7 +48,7 @@ fn test_docs_snippets() { let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); if skipped_args.contains(&args) { - print_skipped_snippet_message(snippet, snippet_type.as_str()); + print_skipped_snippet_message(snippet); continue; } @@ -59,9 +59,13 @@ fn test_docs_snippets() { String::new() }; - assert_valid_snippet(parse_result.is_ok(), snippet, "snforge", &err_message); + assert_valid_snippet(parse_result.is_ok(), snippet, &err_message); - args.retain(|element| element != &"snforge" && element != &"test"); + // Remove "snforge" from the args + args.remove(0); + + // Remove "test" from the args + args.retain(|element| element != &"test"); if let Some(snippet_output) = &snippet.output { let package_name = snippet diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 265e42ebf0..bacad3059f 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -17,10 +17,10 @@ fn test_docs_snippets() { let snippet_type = SnippetType::Sncast; let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &snippet_type) - .expect("Failed to extract sncast command snippets"); + .expect("Failed to extract command snippets"); let readme_snippets = extract_snippets_from_file(&sncast_readme_path, &snippet_type) - .expect("Failed to extract sncast command snippets"); + .expect("Failed to extract command snippets"); let snippets = docs_snippets .into_iter() @@ -54,7 +54,7 @@ fn test_docs_snippets() { args.remove(0); if skipped_args.contains(&args) { - print_skipped_snippet_message(snippet, "sncast"); + print_skipped_snippet_message(snippet); continue; } @@ -65,8 +65,8 @@ fn test_docs_snippets() { let exit_code = output.status.code().unwrap_or_default(); let stderr = String::from_utf8_lossy(&output.stderr); - assert_valid_snippet(exit_code != 2, snippet, "sncast", &stderr); + assert_valid_snippet(exit_code != 2, snippet, &stderr); } - print_success_message(snippets.len(), "sncast"); + print_success_message(snippets.len(), snippet_type.as_str()); } From 983e0a656fb91c474966196af284ccf936626208 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 11:48:35 +0100 Subject: [PATCH 070/183] Change err msg while calling `extract_snippets_from_directory` in forge --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 4de50ddb93..b39589afd5 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -35,7 +35,7 @@ fn test_docs_snippets() { let snippet_type = SnippetType::Forge; let snippets = extract_snippets_from_directory(&docs_dir, &snippet_type) - .expect("Failed to extract snforge command snippets"); + .expect("Failed to extract command snippets"); // TODO(#2684) let skipped_args = [ From 78e3c7d5345ca607952b4c9cddd83621e2b916e4 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 11:54:55 +0100 Subject: [PATCH 071/183] Format --- crates/docs/src/validation.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 375a7b73a3..3e11b0887f 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -99,6 +99,7 @@ pub fn extract_snippets_from_file( }) }) .collect(); + Ok(snippets) } From 97df99f538f37d0e57ef21f3ebd00a6de372254f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 12:08:13 +0100 Subject: [PATCH 072/183] Add todo --- crates/forge/tests/e2e/docs_snippets_validation.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index b39589afd5..cecaf0908f 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -72,6 +72,7 @@ fn test_docs_snippets() { .capture_package_from_output() .expect("Failed to capture package from command output"); + // TODO(#2698) let temp = if is_package_from_docs_listings(&package_name, &listings_to_packages_mapping) { setup_package_from_docs_listings(&package_name, &listings_to_packages_mapping) From dc4386c1a97db168e7ae0b3dbd5459c29c571651 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 12:38:08 +0100 Subject: [PATCH 073/183] Remove unused package --- .../crates/writing_tests_orig/Scarb.toml | 16 ------- .../writing_tests_orig/src/first_test.cairo | 13 ------ .../crates/writing_tests_orig/src/lib.cairo | 2 - .../src/panicking_tests.cairo | 15 ------- .../tests/expected_failures.cairo | 44 ------------------- .../writing_tests_orig/tests/ignoring.cairo | 4 -- 6 files changed, 94 deletions(-) delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo delete mode 100644 docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml b/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml deleted file mode 100644 index 86f60ecd38..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/Scarb.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "writing_tests_orig" -version = "0.1.0" -edition = "2023_11" - -[dependencies] -starknet.workspace = true - -[dev-dependencies] -snforge_std.workspace = true - -[[target.starknet-contract]] -sierra = true - -[scripts] -test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo deleted file mode 100644 index 45e03bf175..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/src/first_test.cairo +++ /dev/null @@ -1,13 +0,0 @@ -fn sum(a: felt252, b: felt252) -> felt252 { - return a + b; -} - -#[cfg(test)] -mod tests { - use super::sum; - - #[test] - fn test_sum() { - assert(sum(2, 3) == 5, 'sum incorrect'); - } -} diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo deleted file mode 100644 index dd518b4752..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/src/lib.cairo +++ /dev/null @@ -1,2 +0,0 @@ -pub mod first_test; -pub mod panicking_tests; diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo deleted file mode 100644 index e36d827abb..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/src/panicking_tests.cairo +++ /dev/null @@ -1,15 +0,0 @@ -#[cfg(test)] -mod tests { - use super::panicking_function; - - #[test] - //ANCHOR_END:first_half - #[should_panic(expected: 'aaa')] - //ANCHOR:second_half - fn failing() { - panicking_function(); - assert(2 == 2, '2 == 2'); - } -} - -mod dummy {} // trick `scarb fmt --check` diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo deleted file mode 100644 index da698c1a57..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/tests/expected_failures.cairo +++ /dev/null @@ -1,44 +0,0 @@ -//ANCHOR:byte_array -#[test] -#[should_panic(expected: "This will panic")] -fn should_panic_exact() { - panic!("This will panic"); -} - -// here the expected message is a substring of the actual message -#[test] -#[should_panic(expected: "will panic")] -fn should_panic_expected_is_substring() { - panic!("This will panic"); -} -//ANCHOR_END:byte_array - -//ANCHOR:felt -#[test] -#[should_panic(expected: 'panic message')] -fn should_panic_felt_matching() { - assert(1 != 1, 'panic message'); -} -//ANCHOR_END:felt - -//ANCHOR:tuple -use core::panic_with_felt252; - -#[test] -#[should_panic(expected: ('panic message',))] -fn should_panic_check_data() { - panic_with_felt252('panic message'); -} - -// works for multiple messages -#[test] -#[should_panic(expected: ('panic message', 'second message',))] -fn should_panic_multiple_messages() { - let mut arr = ArrayTrait::new(); - arr.append('panic message'); - arr.append('second message'); - panic(arr); -} -//ANCHOR_END:tuple - -mod dummy {} // trick `scarb fmt -c` diff --git a/docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo b/docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo deleted file mode 100644 index e9d1988135..0000000000 --- a/docs/listings/snforge_overview/crates/writing_tests_orig/tests/ignoring.cairo +++ /dev/null @@ -1,4 +0,0 @@ -#[test] -#[ignore] -fn ignored_test() { // test code -} From 4d245af58b39ac5870895119c9dbe1a4dbd5cd56 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 12:56:48 +0100 Subject: [PATCH 074/183] Allow ignoring snippets --- crates/docs/src/validation.rs | 9 +++++--- .../tests/e2e/docs_snippets_validation.rs | 8 +------ .../sncast/tests/docs_snippets/validation.rs | 21 +------------------ docs/src/getting-started/first-steps.md | 1 + docs/src/starknet/account-import.md | 1 + docs/src/starknet/index.md | 2 ++ 6 files changed, 12 insertions(+), 30 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 3e11b0887f..bbafc9d860 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -26,7 +26,7 @@ impl SnippetType { #[must_use] pub fn get_re(&self) -> Regex { let pattern = format!( - r"(?ms)^```shell\n\$ ({} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?", + r"(?ms)^(?:\n)?```shell\n\$ ({} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?", self.as_str() ); @@ -41,6 +41,7 @@ pub struct Snippet { pub file_path: String, pub line_start: usize, pub snippet_type: SnippetType, + pub ignored: bool, } impl Snippet { @@ -86,9 +87,10 @@ pub fn extract_snippets_from_file( .get_re() .captures_iter(&content) .filter_map(|caps| { - let command_match = caps.get(1)?; + let command_match = caps.get(2)?; let match_start = caps.get(0)?.start(); - let output = caps.get(2).map(|m| m.as_str().to_string()); + let output = caps.get(3).map(|m| m.as_str().to_string()); + let ignored = caps.get(1).map_or(false, |m| m.as_str().contains("ignore")); Some(Snippet { command: command_match.as_str().to_string(), @@ -96,6 +98,7 @@ pub fn extract_snippets_from_file( file_path: file_path_str.clone(), line_start: content[..match_start].lines().count() + 1, snippet_type: snippet_type.clone(), + ignored, }) }) .collect(); diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index cecaf0908f..a4c210d748 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -37,17 +37,11 @@ fn test_docs_snippets() { let snippets = extract_snippets_from_directory(&docs_dir, &snippet_type) .expect("Failed to extract command snippets"); - // TODO(#2684) - let skipped_args = [ - // For some reason `try_parse_from` fails on `--version` flag, it returns Err but produces the expected output - vec!["snforge", "--version"], - ]; - for snippet in &snippets { let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); - if skipped_args.contains(&args) { + if snippet.ignored { print_skipped_snippet_message(snippet); continue; } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index bacad3059f..e7cfddd10d 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -27,25 +27,6 @@ fn test_docs_snippets() { .chain(readme_snippets) .collect::>(); - // TODO(#2684) - let skipped_args = [ - // snippet "$ sncast " - vec![""], - // snippet with interactive account import example - vec![ - "account", - "import", - "--url", - "http://127.0.0.1:5050", - "--name", - "account_123", - "--address", - "0x1", - "--type", - "oz", - ], - ]; - for snippet in &snippets { let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); @@ -53,7 +34,7 @@ fn test_docs_snippets() { // remove "sncast" from the args args.remove(0); - if skipped_args.contains(&args) { + if snippet.ignored { print_skipped_snippet_message(snippet); continue; } diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index addc14d9ba..9d4075cf23 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -73,6 +73,7 @@ snforge_std = "0.33.0" Make sure that the above version matches the installed `snforge` version. You can check the currently installed version with + ```shell $ snforge --version ``` diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 1451365abb..cb46a503dd 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -87,6 +87,7 @@ $ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. + ```shell $ sncast \ account import \ diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index 32f98b060a..8f441eb2a7 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -11,6 +11,8 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal ## How to Use `sncast` To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): + + ```shell $ sncast ``` From 0eadab423cbbfb1e7880f9fd400e9851896a12b0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 13:26:56 +0100 Subject: [PATCH 075/183] Fix failing tests --- .../tests/e2e/docs_snippets_validation.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a4c210d748..394136a9c3 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -67,13 +67,7 @@ fn test_docs_snippets() { .expect("Failed to capture package from command output"); // TODO(#2698) - let temp = - if is_package_from_docs_listings(&package_name, &listings_to_packages_mapping) { - setup_package_from_docs_listings(&package_name, &listings_to_packages_mapping) - } else { - resolve_package_name(&package_name) - }; - + let temp = resolve_temp_dir(&package_name, &listings_to_packages_mapping); let output = test_runner(&temp).args(args).assert(); assert_stdout_contains(output, snippet_output); @@ -83,9 +77,15 @@ fn test_docs_snippets() { print_success_message(snippets.len(), snippet_type.as_str()); } -fn resolve_package_name(package_name: &str) -> TempDir { - match package_name { - "addition" | "fibonacci" => setup_hello_workspace(), - _ => setup_package(package_name), +fn resolve_temp_dir( + package_name: &str, + listings_to_packages_mapping: &HashMap>, +) -> TempDir { + if is_package_from_docs_listings(package_name, listings_to_packages_mapping) { + setup_package_from_docs_listings(package_name, listings_to_packages_mapping) + } else if ["addition", "fibonacci"].contains(&package_name) { + setup_hello_workspace() + } else { + setup_package(package_name) } } From c5e3b19c5f90e1a8df351d532005d22a90f17e79 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 13:39:44 +0100 Subject: [PATCH 076/183] Apply CR suggestions --- crates/docs/src/validation.rs | 26 +++++++++++-------- .../tests/e2e/docs_snippets_validation.rs | 2 +- .../sncast/tests/docs_snippets/validation.rs | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index bbafc9d860..82d38f72f7 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -9,25 +9,29 @@ use walkdir::WalkDir; const EXTENSION: Option<&str> = Some("md"); #[derive(Clone, Debug)] -pub enum SnippetType { - Forge, - Sncast, -} +pub struct SnippetType(String); impl SnippetType { + #[must_use] + pub fn forge() -> Self { + SnippetType("snforge".to_string()) + } + + #[must_use] + pub fn sncast() -> Self { + SnippetType("sncast".to_string()) + } + #[must_use] pub fn as_str(&self) -> &str { - match self { - SnippetType::Forge => "snforge", - SnippetType::Sncast => "sncast", - } + &self.0 } #[must_use] pub fn get_re(&self) -> Regex { + let escaped_command = regex::escape(self.as_str()); let pattern = format!( - r"(?ms)^(?:\n)?```shell\n\$ ({} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?", - self.as_str() + r"(?ms)^(?:\n)?```shell\n\$ ({escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?" ); Regex::new(&pattern).unwrap() @@ -197,7 +201,7 @@ pub fn create_listings_to_packages_mapping() -> HashMap> { } fn list_packages_in_directory(dir_path: &Path) -> Vec { - let crates_path = dir_path.join(""); + let crates_path = dir_path.to_owned(); if crates_path.exists() && crates_path.is_dir() { WalkDir::new(crates_path) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 394136a9c3..13d0b8c34f 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -32,7 +32,7 @@ fn test_docs_snippets() { let root_dir = get_parent_dir(2); let docs_dir = root_dir.join("docs/src"); - let snippet_type = SnippetType::Forge; + let snippet_type = SnippetType::forge(); let snippets = extract_snippets_from_directory(&docs_dir, &snippet_type) .expect("Failed to extract command snippets"); diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index e7cfddd10d..1d85aa4176 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -14,7 +14,7 @@ fn test_docs_snippets() { let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); - let snippet_type = SnippetType::Sncast; + let snippet_type = SnippetType::sncast(); let docs_snippets = extract_snippets_from_directory(&docs_dir_path, &snippet_type) .expect("Failed to extract command snippets"); From 4df85ac2107c278344b597e0c9c5df9b22ca70c0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 13:43:07 +0100 Subject: [PATCH 077/183] Add `hello_workspaces` case in `resolve_temp_dir` --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 13d0b8c34f..000f4ddec9 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -83,7 +83,7 @@ fn resolve_temp_dir( ) -> TempDir { if is_package_from_docs_listings(package_name, listings_to_packages_mapping) { setup_package_from_docs_listings(package_name, listings_to_packages_mapping) - } else if ["addition", "fibonacci"].contains(&package_name) { + } else if ["addition", "fibonacci", "hello_workspaces"].contains(&package_name) { setup_hello_workspace() } else { setup_package(package_name) From 216c10baea28c8eae6da4c8e5e46b42b05276eb3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 16:45:20 +0100 Subject: [PATCH 078/183] Run `scarb clean` before `scarb check` in `verify_cairo_listings.sh` --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 89a0d7aa97..cf7cd7d3f5 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb check); done +for d in ./docs/listings/*; do (cd "$d" && scarb clean && scarb check); done From a2f01d590496f0be57c6c717c58f366154072373 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 16:55:54 +0100 Subject: [PATCH 079/183] Revert "Run `scarb clean` before `scarb check` in `verify_cairo_listings.sh`" This reverts commit 216c10baea28c8eae6da4c8e5e46b42b05276eb3. --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index cf7cd7d3f5..89a0d7aa97 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb clean && scarb check); done +for d in ./docs/listings/*; do (cd "$d" && scarb check); done From a00a460b3eca8437d7550f2950c0eb3776def639 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 21 Nov 2024 19:20:41 +0100 Subject: [PATCH 080/183] Reorganize listings packages --- .../scripts => }/basic_example/Scarb.toml | 0 .../basic_example/src/basic_example.cairo | 0 .../scripts => }/basic_example/src/lib.cairo | 0 .../scripts => }/call/Scarb.toml | 0 .../scripts => }/call/src/lib.cairo | 0 .../conditional_compilation/Scarb.toml | 0 .../conditional_compilation/src/contract.cairo | 0 .../conditional_compilation/src/function.cairo | 0 .../conditional_compilation/src/lib.cairo | 0 .../conditional_compilation/tests/test.cairo | 0 .../scripts => }/declare/Scarb.toml | 0 .../scripts => }/declare/src/lib.cairo | 0 .../scripts => }/deploy/Scarb.toml | 0 .../scripts => }/deploy/src/lib.cairo | 0 .../detailed_resources_example/.gitignore | 0 .../detailed_resources_example/Scarb.toml | 0 .../detailed_resources_example/src/lib.cairo | 0 .../tests/test_contract.cairo | 0 .../direct_storage_access/Scarb.toml | 0 .../src/complex_structures.cairo | 0 .../direct_storage_access/src/felts_only.cairo | 0 .../direct_storage_access/src/lib.cairo | 0 .../tests/complex_structures.cairo | 0 .../tests/felts_only.cairo | 0 .../tests/felts_only/field.cairo | 0 .../tests/felts_only/map_entry.cairo | 0 .../direct_storage_access/tests/lib.cairo | 0 .../tests/storage_address.cairo | 0 .../scripts => }/error_handling/Scarb.toml | 0 .../error_handling/src/error_handling.cairo | 0 .../scripts => }/error_handling/src/lib.cairo | 0 .../crates => }/failing_example/.gitignore | 0 .../crates => }/failing_example/Scarb.toml | 0 .../crates => }/failing_example/src/lib.cairo | 0 .../failing_example/tests/lib.cairo | 0 .../crates => }/first_test/Scarb.toml | 0 .../crates => }/first_test/src/lib.cairo | 0 .../crates => }/fork_testing/Scarb.toml | 0 .../crates => }/fork_testing/src/lib.cairo | 0 .../fork_testing/tests/explicit.cairo | 0 .../tests/explicit/block_hash.cairo | 0 .../tests/explicit/block_number.cairo | 0 .../tests/explicit/block_tag.cairo | 0 .../crates => }/fork_testing/tests/lib.cairo | 0 .../crates => }/fork_testing/tests/name.cairo | 0 .../fork_testing/tests/overridden_name.cairo | 0 .../scripts => }/full_example/Scarb.toml | 0 .../full_example/src/full_example.cairo | 0 .../scripts => }/full_example/src/lib.cairo | 0 .../crates => }/fuzz_testing/Scarb.toml | 0 .../fuzz_testing/src/basic_example.cairo | 0 .../crates => }/fuzz_testing/src/lib.cairo | 0 .../fuzz_testing/src/with_parameters.cairo | 0 .../scripts => }/get_nonce/Scarb.toml | 0 .../scripts => }/get_nonce/src/lib.cairo | 0 .../crates => }/hello_snforge/.gitignore | 0 .../crates => }/hello_snforge/Scarb.toml | 0 .../crates => }/hello_snforge/src/lib.cairo | 0 .../hello_snforge/tests/test_contract.cairo | 0 .../crates => }/hello_starknet/.gitignore | 0 .../crates => }/hello_starknet/Scarb.toml | 0 .../crates => }/hello_starknet/src/lib.cairo | 0 .../hello_starknet/tests/test_contract.cairo | 0 .../crates => }/ignoring_example/Scarb.toml | 0 .../crates => }/ignoring_example/src/lib.cairo | 0 .../scripts => }/invoke/Scarb.toml | 0 .../scripts => }/invoke/src/lib.cairo | 0 .../crates => }/map3/Scarb.toml | 0 .../{sncast_overview => map3}/snfoundry.toml | 0 .../crates => }/map3/src/lib.cairo | 0 .../crates => }/panicking_test/Scarb.toml | 0 .../crates => }/panicking_test/src/lib.cairo | 0 .../crates => }/should_panic_test/Scarb.toml | 0 .../should_panic_test/src/lib.cairo | 0 docs/listings/sncast_library/Scarb.toml | 13 ------------- docs/listings/sncast_overview/.gitignore | 1 - docs/listings/sncast_overview/Scarb.toml | 18 ------------------ .../snforge_advanced_features/Scarb.toml | 13 ------------- docs/listings/snforge_overview/Scarb.toml | 13 ------------- .../testing_contract_internals/Scarb.toml | 0 .../src/basic_example.cairo | 0 .../testing_contract_internals/src/lib.cairo | 0 .../src/spying_for_events.cairo | 0 .../src/using_library_calls.cairo | 0 .../testing_contract_internals/tests/lib.cairo | 0 .../tests/mocking_the_context_info.cairo | 0 .../tests/spying_for_events.cairo | 0 .../spying_for_events/syscall_tests.cairo | 0 .../tests/spying_for_events/tests.cairo | 0 .../tests/using_library_calls.cairo | 0 .../crates => }/testing_events/Scarb.toml | 0 .../testing_events/src/contract.cairo | 0 .../crates => }/testing_events/src/lib.cairo | 0 .../testing_events/src/syscall.cairo | 0 .../testing_events/src/syscall_dummy.cairo | 0 .../testing_events/tests/assert_emitted.cairo | 0 .../testing_events/tests/assert_manually.cairo | 0 .../testing_events/tests/filter.cairo | 0 .../testing_events/tests/syscall.cairo | 0 .../testing_messages_to_l1/Scarb.toml | 0 .../testing_messages_to_l1/src/lib.cairo | 0 .../tests/detailed.cairo | 0 .../testing_messages_to_l1/tests/lib.cairo | 0 .../testing_messages_to_l1/tests/simple.cairo | 0 .../Scarb.toml | 0 .../src/lib.cairo | 0 .../tests/handle_panic.cairo | 0 .../tests/panic.cairo | 0 .../Scarb.toml | 0 .../src/lib.cairo | 0 .../tests/safe_dispatcher.cairo | 0 .../Scarb.toml | 0 .../src/lib.cairo | 0 .../tests/simple_contract.cairo | 0 .../scripts => }/tx_status/Scarb.toml | 0 .../scripts => }/tx_status/src/lib.cairo | 0 .../crates => }/using_cheatcodes/Scarb.toml | 0 .../crates => }/using_cheatcodes/src/lib.cairo | 0 .../using_cheatcodes/tests/lib.cairo | 0 .../Scarb.toml | 0 .../src/lib.cairo | 0 .../tests/lib.cairo | 0 .../using_cheatcodes_cheat_address/Scarb.toml | 0 .../src/lib.cairo | 0 .../tests/lib.cairo | 0 .../using_cheatcodes_others/Scarb.toml | 0 .../using_cheatcodes_others/src/lib.cairo | 0 .../tests/caller_address.cairo | 0 .../caller_address/proper_use_global.cairo | 0 .../tests/caller_address/span.cairo | 0 .../tests/cheat_constructor.cairo | 0 .../using_cheatcodes_others/tests/lib.cairo | 0 132 files changed, 58 deletions(-) rename docs/listings/{sncast_overview/scripts => }/basic_example/Scarb.toml (100%) rename docs/listings/{sncast_overview/scripts => }/basic_example/src/basic_example.cairo (100%) rename docs/listings/{sncast_overview/scripts => }/basic_example/src/lib.cairo (100%) rename docs/listings/{sncast_library/scripts => }/call/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/call/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/conditional_compilation/Scarb.toml (100%) rename docs/listings/{snforge_advanced_features/crates => }/conditional_compilation/src/contract.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/conditional_compilation/src/function.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/conditional_compilation/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/conditional_compilation/tests/test.cairo (100%) rename docs/listings/{sncast_library/scripts => }/declare/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/declare/src/lib.cairo (100%) rename docs/listings/{sncast_library/scripts => }/deploy/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/deploy/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/detailed_resources_example/.gitignore (100%) rename docs/listings/{snforge_overview/crates => }/detailed_resources_example/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/detailed_resources_example/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/detailed_resources_example/tests/test_contract.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/Scarb.toml (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/src/complex_structures.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/src/felts_only.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/complex_structures.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/felts_only.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/felts_only/field.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/felts_only/map_entry.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/direct_storage_access/tests/storage_address.cairo (100%) rename docs/listings/{sncast_overview/scripts => }/error_handling/Scarb.toml (100%) rename docs/listings/{sncast_overview/scripts => }/error_handling/src/error_handling.cairo (100%) rename docs/listings/{sncast_overview/scripts => }/error_handling/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/failing_example/.gitignore (100%) rename docs/listings/{snforge_overview/crates => }/failing_example/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/failing_example/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/failing_example/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/first_test/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/first_test/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/Scarb.toml (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/explicit.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/explicit/block_hash.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/explicit/block_number.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/explicit/block_tag.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/name.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fork_testing/tests/overridden_name.cairo (100%) rename docs/listings/{sncast_overview/scripts => }/full_example/Scarb.toml (100%) rename docs/listings/{sncast_overview/scripts => }/full_example/src/full_example.cairo (100%) rename docs/listings/{sncast_overview/scripts => }/full_example/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fuzz_testing/Scarb.toml (100%) rename docs/listings/{snforge_advanced_features/crates => }/fuzz_testing/src/basic_example.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fuzz_testing/src/lib.cairo (100%) rename docs/listings/{snforge_advanced_features/crates => }/fuzz_testing/src/with_parameters.cairo (100%) rename docs/listings/{sncast_library/scripts => }/get_nonce/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/get_nonce/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/hello_snforge/.gitignore (100%) rename docs/listings/{snforge_overview/crates => }/hello_snforge/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/hello_snforge/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/hello_snforge/tests/test_contract.cairo (100%) rename docs/listings/{snforge_overview/crates => }/hello_starknet/.gitignore (100%) rename docs/listings/{snforge_overview/crates => }/hello_starknet/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/hello_starknet/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/hello_starknet/tests/test_contract.cairo (100%) rename docs/listings/{snforge_overview/crates => }/ignoring_example/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/ignoring_example/src/lib.cairo (100%) rename docs/listings/{sncast_library/scripts => }/invoke/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/invoke/src/lib.cairo (100%) rename docs/listings/{sncast_overview/crates => }/map3/Scarb.toml (100%) rename docs/listings/{sncast_overview => map3}/snfoundry.toml (100%) rename docs/listings/{sncast_overview/crates => }/map3/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/panicking_test/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/panicking_test/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/should_panic_test/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/should_panic_test/src/lib.cairo (100%) delete mode 100644 docs/listings/sncast_library/Scarb.toml delete mode 100644 docs/listings/sncast_overview/.gitignore delete mode 100644 docs/listings/sncast_overview/Scarb.toml delete mode 100644 docs/listings/snforge_advanced_features/Scarb.toml delete mode 100644 docs/listings/snforge_overview/Scarb.toml rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/src/basic_example.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/src/spying_for_events.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/src/using_library_calls.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/mocking_the_context_info.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/spying_for_events.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/spying_for_events/tests.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_contract_internals/tests/using_library_calls.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/src/contract.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/src/syscall.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/src/syscall_dummy.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/tests/assert_emitted.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/tests/assert_manually.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/tests/filter.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_events/tests/syscall.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_messages_to_l1/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_messages_to_l1/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_messages_to_l1/tests/detailed.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_messages_to_l1/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_messages_to_l1/tests/simple.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_handling_errors/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_handling_errors/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_handling_errors/tests/handle_panic.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_handling_errors/tests/panic.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_safe_dispatcher/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_safe_dispatcher/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_writing_tests/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_writing_tests/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/testing_smart_contracts_writing_tests/tests/simple_contract.cairo (100%) rename docs/listings/{sncast_library/scripts => }/tx_status/Scarb.toml (100%) rename docs/listings/{sncast_library/scripts => }/tx_status/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cancelling_cheat/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cancelling_cheat/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cancelling_cheat/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cheat_address/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cheat_address/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_cheat_address/tests/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/Scarb.toml (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/src/lib.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/tests/caller_address.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/tests/caller_address/span.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/tests/cheat_constructor.cairo (100%) rename docs/listings/{snforge_overview/crates => }/using_cheatcodes_others/tests/lib.cairo (100%) diff --git a/docs/listings/sncast_overview/scripts/basic_example/Scarb.toml b/docs/listings/basic_example/Scarb.toml similarity index 100% rename from docs/listings/sncast_overview/scripts/basic_example/Scarb.toml rename to docs/listings/basic_example/Scarb.toml diff --git a/docs/listings/sncast_overview/scripts/basic_example/src/basic_example.cairo b/docs/listings/basic_example/src/basic_example.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/basic_example/src/basic_example.cairo rename to docs/listings/basic_example/src/basic_example.cairo diff --git a/docs/listings/sncast_overview/scripts/basic_example/src/lib.cairo b/docs/listings/basic_example/src/lib.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/basic_example/src/lib.cairo rename to docs/listings/basic_example/src/lib.cairo diff --git a/docs/listings/sncast_library/scripts/call/Scarb.toml b/docs/listings/call/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/call/Scarb.toml rename to docs/listings/call/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/call/src/lib.cairo b/docs/listings/call/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/call/src/lib.cairo rename to docs/listings/call/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml b/docs/listings/conditional_compilation/Scarb.toml similarity index 100% rename from docs/listings/snforge_advanced_features/crates/conditional_compilation/Scarb.toml rename to docs/listings/conditional_compilation/Scarb.toml diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/src/contract.cairo b/docs/listings/conditional_compilation/src/contract.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/conditional_compilation/src/contract.cairo rename to docs/listings/conditional_compilation/src/contract.cairo diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/src/function.cairo b/docs/listings/conditional_compilation/src/function.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/conditional_compilation/src/function.cairo rename to docs/listings/conditional_compilation/src/function.cairo diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/src/lib.cairo b/docs/listings/conditional_compilation/src/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/conditional_compilation/src/lib.cairo rename to docs/listings/conditional_compilation/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/conditional_compilation/tests/test.cairo b/docs/listings/conditional_compilation/tests/test.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/conditional_compilation/tests/test.cairo rename to docs/listings/conditional_compilation/tests/test.cairo diff --git a/docs/listings/sncast_library/scripts/declare/Scarb.toml b/docs/listings/declare/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/declare/Scarb.toml rename to docs/listings/declare/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/declare/src/lib.cairo b/docs/listings/declare/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/declare/src/lib.cairo rename to docs/listings/declare/src/lib.cairo diff --git a/docs/listings/sncast_library/scripts/deploy/Scarb.toml b/docs/listings/deploy/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/deploy/Scarb.toml rename to docs/listings/deploy/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/deploy/src/lib.cairo b/docs/listings/deploy/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/deploy/src/lib.cairo rename to docs/listings/deploy/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore b/docs/listings/detailed_resources_example/.gitignore similarity index 100% rename from docs/listings/snforge_overview/crates/detailed_resources_example/.gitignore rename to docs/listings/detailed_resources_example/.gitignore diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml b/docs/listings/detailed_resources_example/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/detailed_resources_example/Scarb.toml rename to docs/listings/detailed_resources_example/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo b/docs/listings/detailed_resources_example/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/detailed_resources_example/src/lib.cairo rename to docs/listings/detailed_resources_example/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo b/docs/listings/detailed_resources_example/tests/test_contract.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/detailed_resources_example/tests/test_contract.cairo rename to docs/listings/detailed_resources_example/tests/test_contract.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml b/docs/listings/direct_storage_access/Scarb.toml similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/Scarb.toml rename to docs/listings/direct_storage_access/Scarb.toml diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/src/complex_structures.cairo b/docs/listings/direct_storage_access/src/complex_structures.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/src/complex_structures.cairo rename to docs/listings/direct_storage_access/src/complex_structures.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/src/felts_only.cairo b/docs/listings/direct_storage_access/src/felts_only.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/src/felts_only.cairo rename to docs/listings/direct_storage_access/src/felts_only.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/src/lib.cairo b/docs/listings/direct_storage_access/src/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/src/lib.cairo rename to docs/listings/direct_storage_access/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/complex_structures.cairo b/docs/listings/direct_storage_access/tests/complex_structures.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/complex_structures.cairo rename to docs/listings/direct_storage_access/tests/complex_structures.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only.cairo b/docs/listings/direct_storage_access/tests/felts_only.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only.cairo rename to docs/listings/direct_storage_access/tests/felts_only.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only/field.cairo b/docs/listings/direct_storage_access/tests/felts_only/field.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only/field.cairo rename to docs/listings/direct_storage_access/tests/felts_only/field.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only/map_entry.cairo b/docs/listings/direct_storage_access/tests/felts_only/map_entry.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/felts_only/map_entry.cairo rename to docs/listings/direct_storage_access/tests/felts_only/map_entry.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/lib.cairo b/docs/listings/direct_storage_access/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/lib.cairo rename to docs/listings/direct_storage_access/tests/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/storage_address.cairo b/docs/listings/direct_storage_access/tests/storage_address.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/direct_storage_access/tests/storage_address.cairo rename to docs/listings/direct_storage_access/tests/storage_address.cairo diff --git a/docs/listings/sncast_overview/scripts/error_handling/Scarb.toml b/docs/listings/error_handling/Scarb.toml similarity index 100% rename from docs/listings/sncast_overview/scripts/error_handling/Scarb.toml rename to docs/listings/error_handling/Scarb.toml diff --git a/docs/listings/sncast_overview/scripts/error_handling/src/error_handling.cairo b/docs/listings/error_handling/src/error_handling.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/error_handling/src/error_handling.cairo rename to docs/listings/error_handling/src/error_handling.cairo diff --git a/docs/listings/sncast_overview/scripts/error_handling/src/lib.cairo b/docs/listings/error_handling/src/lib.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/error_handling/src/lib.cairo rename to docs/listings/error_handling/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/failing_example/.gitignore b/docs/listings/failing_example/.gitignore similarity index 100% rename from docs/listings/snforge_overview/crates/failing_example/.gitignore rename to docs/listings/failing_example/.gitignore diff --git a/docs/listings/snforge_overview/crates/failing_example/Scarb.toml b/docs/listings/failing_example/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/failing_example/Scarb.toml rename to docs/listings/failing_example/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/failing_example/src/lib.cairo b/docs/listings/failing_example/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/failing_example/src/lib.cairo rename to docs/listings/failing_example/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/failing_example/tests/lib.cairo b/docs/listings/failing_example/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/failing_example/tests/lib.cairo rename to docs/listings/failing_example/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/first_test/Scarb.toml b/docs/listings/first_test/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/first_test/Scarb.toml rename to docs/listings/first_test/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/first_test/src/lib.cairo b/docs/listings/first_test/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/first_test/src/lib.cairo rename to docs/listings/first_test/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml b/docs/listings/fork_testing/Scarb.toml similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/Scarb.toml rename to docs/listings/fork_testing/Scarb.toml diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/src/lib.cairo b/docs/listings/fork_testing/src/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/src/lib.cairo rename to docs/listings/fork_testing/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit.cairo b/docs/listings/fork_testing/tests/explicit.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit.cairo rename to docs/listings/fork_testing/tests/explicit.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_hash.cairo b/docs/listings/fork_testing/tests/explicit/block_hash.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_hash.cairo rename to docs/listings/fork_testing/tests/explicit/block_hash.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_number.cairo b/docs/listings/fork_testing/tests/explicit/block_number.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_number.cairo rename to docs/listings/fork_testing/tests/explicit/block_number.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_tag.cairo b/docs/listings/fork_testing/tests/explicit/block_tag.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/explicit/block_tag.cairo rename to docs/listings/fork_testing/tests/explicit/block_tag.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/lib.cairo b/docs/listings/fork_testing/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/lib.cairo rename to docs/listings/fork_testing/tests/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/name.cairo b/docs/listings/fork_testing/tests/name.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/name.cairo rename to docs/listings/fork_testing/tests/name.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fork_testing/tests/overridden_name.cairo b/docs/listings/fork_testing/tests/overridden_name.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fork_testing/tests/overridden_name.cairo rename to docs/listings/fork_testing/tests/overridden_name.cairo diff --git a/docs/listings/sncast_overview/scripts/full_example/Scarb.toml b/docs/listings/full_example/Scarb.toml similarity index 100% rename from docs/listings/sncast_overview/scripts/full_example/Scarb.toml rename to docs/listings/full_example/Scarb.toml diff --git a/docs/listings/sncast_overview/scripts/full_example/src/full_example.cairo b/docs/listings/full_example/src/full_example.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/full_example/src/full_example.cairo rename to docs/listings/full_example/src/full_example.cairo diff --git a/docs/listings/sncast_overview/scripts/full_example/src/lib.cairo b/docs/listings/full_example/src/lib.cairo similarity index 100% rename from docs/listings/sncast_overview/scripts/full_example/src/lib.cairo rename to docs/listings/full_example/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml b/docs/listings/fuzz_testing/Scarb.toml similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fuzz_testing/Scarb.toml rename to docs/listings/fuzz_testing/Scarb.toml diff --git a/docs/listings/snforge_advanced_features/crates/fuzz_testing/src/basic_example.cairo b/docs/listings/fuzz_testing/src/basic_example.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fuzz_testing/src/basic_example.cairo rename to docs/listings/fuzz_testing/src/basic_example.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fuzz_testing/src/lib.cairo b/docs/listings/fuzz_testing/src/lib.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fuzz_testing/src/lib.cairo rename to docs/listings/fuzz_testing/src/lib.cairo diff --git a/docs/listings/snforge_advanced_features/crates/fuzz_testing/src/with_parameters.cairo b/docs/listings/fuzz_testing/src/with_parameters.cairo similarity index 100% rename from docs/listings/snforge_advanced_features/crates/fuzz_testing/src/with_parameters.cairo rename to docs/listings/fuzz_testing/src/with_parameters.cairo diff --git a/docs/listings/sncast_library/scripts/get_nonce/Scarb.toml b/docs/listings/get_nonce/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/get_nonce/Scarb.toml rename to docs/listings/get_nonce/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/get_nonce/src/lib.cairo b/docs/listings/get_nonce/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/get_nonce/src/lib.cairo rename to docs/listings/get_nonce/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/hello_snforge/.gitignore b/docs/listings/hello_snforge/.gitignore similarity index 100% rename from docs/listings/snforge_overview/crates/hello_snforge/.gitignore rename to docs/listings/hello_snforge/.gitignore diff --git a/docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml b/docs/listings/hello_snforge/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/hello_snforge/Scarb.toml rename to docs/listings/hello_snforge/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo b/docs/listings/hello_snforge/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/hello_snforge/src/lib.cairo rename to docs/listings/hello_snforge/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo b/docs/listings/hello_snforge/tests/test_contract.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/hello_snforge/tests/test_contract.cairo rename to docs/listings/hello_snforge/tests/test_contract.cairo diff --git a/docs/listings/snforge_overview/crates/hello_starknet/.gitignore b/docs/listings/hello_starknet/.gitignore similarity index 100% rename from docs/listings/snforge_overview/crates/hello_starknet/.gitignore rename to docs/listings/hello_starknet/.gitignore diff --git a/docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml b/docs/listings/hello_starknet/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/hello_starknet/Scarb.toml rename to docs/listings/hello_starknet/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo b/docs/listings/hello_starknet/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/hello_starknet/src/lib.cairo rename to docs/listings/hello_starknet/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo b/docs/listings/hello_starknet/tests/test_contract.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/hello_starknet/tests/test_contract.cairo rename to docs/listings/hello_starknet/tests/test_contract.cairo diff --git a/docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml b/docs/listings/ignoring_example/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/ignoring_example/Scarb.toml rename to docs/listings/ignoring_example/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo b/docs/listings/ignoring_example/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/ignoring_example/src/lib.cairo rename to docs/listings/ignoring_example/src/lib.cairo diff --git a/docs/listings/sncast_library/scripts/invoke/Scarb.toml b/docs/listings/invoke/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/invoke/Scarb.toml rename to docs/listings/invoke/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/invoke/src/lib.cairo b/docs/listings/invoke/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/invoke/src/lib.cairo rename to docs/listings/invoke/src/lib.cairo diff --git a/docs/listings/sncast_overview/crates/map3/Scarb.toml b/docs/listings/map3/Scarb.toml similarity index 100% rename from docs/listings/sncast_overview/crates/map3/Scarb.toml rename to docs/listings/map3/Scarb.toml diff --git a/docs/listings/sncast_overview/snfoundry.toml b/docs/listings/map3/snfoundry.toml similarity index 100% rename from docs/listings/sncast_overview/snfoundry.toml rename to docs/listings/map3/snfoundry.toml diff --git a/docs/listings/sncast_overview/crates/map3/src/lib.cairo b/docs/listings/map3/src/lib.cairo similarity index 100% rename from docs/listings/sncast_overview/crates/map3/src/lib.cairo rename to docs/listings/map3/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/panicking_test/Scarb.toml b/docs/listings/panicking_test/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/panicking_test/Scarb.toml rename to docs/listings/panicking_test/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo b/docs/listings/panicking_test/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/panicking_test/src/lib.cairo rename to docs/listings/panicking_test/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml b/docs/listings/should_panic_test/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/should_panic_test/Scarb.toml rename to docs/listings/should_panic_test/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo b/docs/listings/should_panic_test/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/should_panic_test/src/lib.cairo rename to docs/listings/should_panic_test/src/lib.cairo diff --git a/docs/listings/sncast_library/Scarb.toml b/docs/listings/sncast_library/Scarb.toml deleted file mode 100644 index 660b958f63..0000000000 --- a/docs/listings/sncast_library/Scarb.toml +++ /dev/null @@ -1,13 +0,0 @@ -[workspace] -members = ["scripts/*"] - -[workspace.dependencies] -starknet = "2.7.0" -snforge_std = { path = "../../../snforge_std" } -sncast_std = { path = "../../../sncast_std" } - -[[target.starknet-contract]] -sierra = true - -[scripts] -test = "snforge test" diff --git a/docs/listings/sncast_overview/.gitignore b/docs/listings/sncast_overview/.gitignore deleted file mode 100644 index a1d8daa50d..0000000000 --- a/docs/listings/sncast_overview/.gitignore +++ /dev/null @@ -1 +0,0 @@ -scripts/**/*state.json diff --git a/docs/listings/sncast_overview/Scarb.toml b/docs/listings/sncast_overview/Scarb.toml deleted file mode 100644 index 4e682fa59d..0000000000 --- a/docs/listings/sncast_overview/Scarb.toml +++ /dev/null @@ -1,18 +0,0 @@ -[workspace] -members = ["scripts/*", "crates/*"] - -[workspace.dependencies] -starknet = "2.7.0" -snforge_std = { path = "../../../snforge_std" } -sncast_std = { path = "../../../sncast_std" } -assert_macros = "0.1.0" - -[[target.starknet-contract]] -sierra = true - -[[target.lib]] -sierra = true -casm = true - -[scripts] -test = "snforge test" diff --git a/docs/listings/snforge_advanced_features/Scarb.toml b/docs/listings/snforge_advanced_features/Scarb.toml deleted file mode 100644 index ec83246478..0000000000 --- a/docs/listings/snforge_advanced_features/Scarb.toml +++ /dev/null @@ -1,13 +0,0 @@ -[workspace] -members = ["crates/*"] - -[workspace.dependencies] -starknet = "2.7.0" -assert_macros = "0.1.0" -snforge_std = { path = "../../../snforge_std" } - -[[target.starknet-contract]] -sierra = true - -[scripts] -test = "snforge test" diff --git a/docs/listings/snforge_overview/Scarb.toml b/docs/listings/snforge_overview/Scarb.toml deleted file mode 100644 index 437d4c716e..0000000000 --- a/docs/listings/snforge_overview/Scarb.toml +++ /dev/null @@ -1,13 +0,0 @@ -[workspace] -members = ["crates/*"] - -[workspace.dependencies] -starknet = "2.7.0" -snforge_std = { path = "../../../snforge_std" } -assert_macros = "0.1.0" - -[[target.starknet-contract]] -sierra = true - -[scripts] -test = "snforge test" diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml b/docs/listings/testing_contract_internals/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/Scarb.toml rename to docs/listings/testing_contract_internals/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/src/basic_example.cairo b/docs/listings/testing_contract_internals/src/basic_example.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/src/basic_example.cairo rename to docs/listings/testing_contract_internals/src/basic_example.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/src/lib.cairo b/docs/listings/testing_contract_internals/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/src/lib.cairo rename to docs/listings/testing_contract_internals/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/src/spying_for_events.cairo b/docs/listings/testing_contract_internals/src/spying_for_events.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/src/spying_for_events.cairo rename to docs/listings/testing_contract_internals/src/spying_for_events.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/src/using_library_calls.cairo b/docs/listings/testing_contract_internals/src/using_library_calls.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/src/using_library_calls.cairo rename to docs/listings/testing_contract_internals/src/using_library_calls.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/lib.cairo b/docs/listings/testing_contract_internals/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/lib.cairo rename to docs/listings/testing_contract_internals/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/mocking_the_context_info.cairo b/docs/listings/testing_contract_internals/tests/mocking_the_context_info.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/mocking_the_context_info.cairo rename to docs/listings/testing_contract_internals/tests/mocking_the_context_info.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events.cairo b/docs/listings/testing_contract_internals/tests/spying_for_events.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events.cairo rename to docs/listings/testing_contract_internals/tests/spying_for_events.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo b/docs/listings/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo rename to docs/listings/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/tests.cairo b/docs/listings/testing_contract_internals/tests/spying_for_events/tests.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/tests.cairo rename to docs/listings/testing_contract_internals/tests/spying_for_events/tests.cairo diff --git a/docs/listings/snforge_overview/crates/testing_contract_internals/tests/using_library_calls.cairo b/docs/listings/testing_contract_internals/tests/using_library_calls.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_contract_internals/tests/using_library_calls.cairo rename to docs/listings/testing_contract_internals/tests/using_library_calls.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/Scarb.toml b/docs/listings/testing_events/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/Scarb.toml rename to docs/listings/testing_events/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_events/src/contract.cairo b/docs/listings/testing_events/src/contract.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/src/contract.cairo rename to docs/listings/testing_events/src/contract.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/src/lib.cairo b/docs/listings/testing_events/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/src/lib.cairo rename to docs/listings/testing_events/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/src/syscall.cairo b/docs/listings/testing_events/src/syscall.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/src/syscall.cairo rename to docs/listings/testing_events/src/syscall.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/src/syscall_dummy.cairo b/docs/listings/testing_events/src/syscall_dummy.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/src/syscall_dummy.cairo rename to docs/listings/testing_events/src/syscall_dummy.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/tests/assert_emitted.cairo b/docs/listings/testing_events/tests/assert_emitted.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/tests/assert_emitted.cairo rename to docs/listings/testing_events/tests/assert_emitted.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/tests/assert_manually.cairo b/docs/listings/testing_events/tests/assert_manually.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/tests/assert_manually.cairo rename to docs/listings/testing_events/tests/assert_manually.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/tests/filter.cairo b/docs/listings/testing_events/tests/filter.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/tests/filter.cairo rename to docs/listings/testing_events/tests/filter.cairo diff --git a/docs/listings/snforge_overview/crates/testing_events/tests/syscall.cairo b/docs/listings/testing_events/tests/syscall.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_events/tests/syscall.cairo rename to docs/listings/testing_events/tests/syscall.cairo diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml b/docs/listings/testing_messages_to_l1/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_messages_to_l1/Scarb.toml rename to docs/listings/testing_messages_to_l1/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/src/lib.cairo b/docs/listings/testing_messages_to_l1/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_messages_to_l1/src/lib.cairo rename to docs/listings/testing_messages_to_l1/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/detailed.cairo b/docs/listings/testing_messages_to_l1/tests/detailed.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/detailed.cairo rename to docs/listings/testing_messages_to_l1/tests/detailed.cairo diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/lib.cairo b/docs/listings/testing_messages_to_l1/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/lib.cairo rename to docs/listings/testing_messages_to_l1/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/simple.cairo b/docs/listings/testing_messages_to_l1/tests/simple.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_messages_to_l1/tests/simple.cairo rename to docs/listings/testing_messages_to_l1/tests/simple.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/Scarb.toml rename to docs/listings/testing_smart_contracts_handling_errors/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo b/docs/listings/testing_smart_contracts_handling_errors/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo rename to docs/listings/testing_smart_contracts_handling_errors/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo b/docs/listings/testing_smart_contracts_handling_errors/tests/handle_panic.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo rename to docs/listings/testing_smart_contracts_handling_errors/tests/handle_panic.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo b/docs/listings/testing_smart_contracts_handling_errors/tests/panic.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo rename to docs/listings/testing_smart_contracts_handling_errors/tests/panic.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/Scarb.toml rename to docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo b/docs/listings/testing_smart_contracts_safe_dispatcher/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/src/lib.cairo rename to docs/listings/testing_smart_contracts_safe_dispatcher/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo b/docs/listings/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo rename to docs/listings/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/Scarb.toml rename to docs/listings/testing_smart_contracts_writing_tests/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo b/docs/listings/testing_smart_contracts_writing_tests/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo rename to docs/listings/testing_smart_contracts_writing_tests/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo b/docs/listings/testing_smart_contracts_writing_tests/tests/simple_contract.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo rename to docs/listings/testing_smart_contracts_writing_tests/tests/simple_contract.cairo diff --git a/docs/listings/sncast_library/scripts/tx_status/Scarb.toml b/docs/listings/tx_status/Scarb.toml similarity index 100% rename from docs/listings/sncast_library/scripts/tx_status/Scarb.toml rename to docs/listings/tx_status/Scarb.toml diff --git a/docs/listings/sncast_library/scripts/tx_status/src/lib.cairo b/docs/listings/tx_status/src/lib.cairo similarity index 100% rename from docs/listings/sncast_library/scripts/tx_status/src/lib.cairo rename to docs/listings/tx_status/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml b/docs/listings/using_cheatcodes/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes/Scarb.toml rename to docs/listings/using_cheatcodes/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/src/lib.cairo b/docs/listings/using_cheatcodes/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes/src/lib.cairo rename to docs/listings/using_cheatcodes/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo b/docs/listings/using_cheatcodes/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo rename to docs/listings/using_cheatcodes/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml b/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/Scarb.toml rename to docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo b/docs/listings/using_cheatcodes_cancelling_cheat/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/src/lib.cairo rename to docs/listings/using_cheatcodes_cancelling_cheat/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo b/docs/listings/using_cheatcodes_cancelling_cheat/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo rename to docs/listings/using_cheatcodes_cancelling_cheat/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml b/docs/listings/using_cheatcodes_cheat_address/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/Scarb.toml rename to docs/listings/using_cheatcodes_cheat_address/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo b/docs/listings/using_cheatcodes_cheat_address/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/src/lib.cairo rename to docs/listings/using_cheatcodes_cheat_address/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo b/docs/listings/using_cheatcodes_cheat_address/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo rename to docs/listings/using_cheatcodes_cheat_address/tests/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml b/docs/listings/using_cheatcodes_others/Scarb.toml similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/Scarb.toml rename to docs/listings/using_cheatcodes_others/Scarb.toml diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo b/docs/listings/using_cheatcodes_others/src/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/src/lib.cairo rename to docs/listings/using_cheatcodes_others/src/lib.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo b/docs/listings/using_cheatcodes_others/tests/caller_address.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address.cairo rename to docs/listings/using_cheatcodes_others/tests/caller_address.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo b/docs/listings/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo rename to docs/listings/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo b/docs/listings/using_cheatcodes_others/tests/caller_address/span.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo rename to docs/listings/using_cheatcodes_others/tests/caller_address/span.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo b/docs/listings/using_cheatcodes_others/tests/cheat_constructor.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo rename to docs/listings/using_cheatcodes_others/tests/cheat_constructor.cairo diff --git a/docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo b/docs/listings/using_cheatcodes_others/tests/lib.cairo similarity index 100% rename from docs/listings/snforge_overview/crates/using_cheatcodes_others/tests/lib.cairo rename to docs/listings/using_cheatcodes_others/tests/lib.cairo From ad9aa26c0ff52868167464b304953964d0a382bc Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 10:49:41 +0100 Subject: [PATCH 081/183] Update manifests in listings packages --- docs/listings/detailed_resources_example/Scarb.toml | 4 ++-- docs/listings/failing_example/Scarb.toml | 4 ++-- docs/listings/first_test/Scarb.toml | 4 ++-- docs/listings/hello_snforge/Scarb.toml | 4 ++-- docs/listings/hello_starknet/Scarb.toml | 4 ++-- docs/listings/ignoring_example/Scarb.toml | 4 ++-- docs/listings/panicking_test/Scarb.toml | 4 ++-- docs/listings/should_panic_test/Scarb.toml | 4 ++-- docs/listings/testing_contract_internals/Scarb.toml | 4 ++-- docs/listings/testing_events/Scarb.toml | 4 ++-- docs/listings/testing_messages_to_l1/Scarb.toml | 4 ++-- .../testing_smart_contracts_handling_errors/Scarb.toml | 4 ++-- .../testing_smart_contracts_safe_dispatcher/Scarb.toml | 4 ++-- .../listings/testing_smart_contracts_writing_tests/Scarb.toml | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/listings/detailed_resources_example/Scarb.toml b/docs/listings/detailed_resources_example/Scarb.toml index 9f43eaa2e1..9f413181e6 100644 --- a/docs/listings/detailed_resources_example/Scarb.toml +++ b/docs/listings/detailed_resources_example/Scarb.toml @@ -6,10 +6,10 @@ edition = "2023_11" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/failing_example/Scarb.toml b/docs/listings/failing_example/Scarb.toml index ef4e2fd9ea..62dba01f83 100644 --- a/docs/listings/failing_example/Scarb.toml +++ b/docs/listings/failing_example/Scarb.toml @@ -6,10 +6,10 @@ edition = "2023_11" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/first_test/Scarb.toml b/docs/listings/first_test/Scarb.toml index 80a3666c8d..a660442423 100644 --- a/docs/listings/first_test/Scarb.toml +++ b/docs/listings/first_test/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_snforge/Scarb.toml b/docs/listings/hello_snforge/Scarb.toml index 874d8c3a78..9b8058134f 100644 --- a/docs/listings/hello_snforge/Scarb.toml +++ b/docs/listings/hello_snforge/Scarb.toml @@ -6,10 +6,10 @@ edition = "2023_11" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_starknet/Scarb.toml b/docs/listings/hello_starknet/Scarb.toml index 0ecb3f63f5..80f5592f09 100644 --- a/docs/listings/hello_starknet/Scarb.toml +++ b/docs/listings/hello_starknet/Scarb.toml @@ -6,10 +6,10 @@ edition = "2023_11" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/ignoring_example/Scarb.toml b/docs/listings/ignoring_example/Scarb.toml index adaf6ad058..db6dddc1be 100644 --- a/docs/listings/ignoring_example/Scarb.toml +++ b/docs/listings/ignoring_example/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/panicking_test/Scarb.toml b/docs/listings/panicking_test/Scarb.toml index 260e51c923..8ef56c114d 100644 --- a/docs/listings/panicking_test/Scarb.toml +++ b/docs/listings/panicking_test/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/should_panic_test/Scarb.toml b/docs/listings/should_panic_test/Scarb.toml index 0ca0e3e93d..a6e69166ac 100644 --- a/docs/listings/should_panic_test/Scarb.toml +++ b/docs/listings/should_panic_test/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_contract_internals/Scarb.toml b/docs/listings/testing_contract_internals/Scarb.toml index 3c18aab37c..50cd30d7f1 100644 --- a/docs/listings/testing_contract_internals/Scarb.toml +++ b/docs/listings/testing_contract_internals/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_events/Scarb.toml b/docs/listings/testing_events/Scarb.toml index d438c69dde..3123ffe196 100644 --- a/docs/listings/testing_events/Scarb.toml +++ b/docs/listings/testing_events/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_messages_to_l1/Scarb.toml b/docs/listings/testing_messages_to_l1/Scarb.toml index fe4d5827ff..671a4900bb 100644 --- a/docs/listings/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/testing_messages_to_l1/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml index 1e812c00cd..2d03df110d 100644 --- a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml +++ b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml index 2d3d210cd5..be8d6507ee 100644 --- a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml +++ b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml index 2eb5069cc5..d482893893 100644 --- a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml +++ b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +sncast_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true From 12edd486d71bbf572cb5586ba1aaeca857968002 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 10:52:57 +0100 Subject: [PATCH 082/183] Add `hello_workspace` package --- docs/listings/hello_workspaces/Scarb.toml | 39 +++++++++++++++++++ .../crates/addition/Scarb.toml | 15 +++++++ .../crates/addition/src/lib.cairo | 33 ++++++++++++++++ .../crates/addition/tests/nested.cairo | 17 ++++++++ .../addition/tests/nested/test_nested.cairo | 12 ++++++ .../crates/fibonacci/Scarb.toml | 23 +++++++++++ .../crates/fibonacci/src/lib.cairo | 39 +++++++++++++++++++ .../crates/fibonacci/tests/abc.cairo | 10 +++++ .../crates/fibonacci/tests/abc/efg.cairo | 9 +++++ .../crates/fibonacci/tests/lib.cairo | 6 +++ .../fibonacci/tests/not_collected.cairo | 6 +++ docs/listings/hello_workspaces/src/lib.cairo | 28 +++++++++++++ .../hello_workspaces/tests/test_failing.cairo | 9 +++++ 13 files changed, 246 insertions(+) create mode 100644 docs/listings/hello_workspaces/Scarb.toml create mode 100644 docs/listings/hello_workspaces/crates/addition/Scarb.toml create mode 100644 docs/listings/hello_workspaces/crates/addition/src/lib.cairo create mode 100644 docs/listings/hello_workspaces/crates/addition/tests/nested.cairo create mode 100644 docs/listings/hello_workspaces/crates/addition/tests/nested/test_nested.cairo create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/src/lib.cairo create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/tests/abc.cairo create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/tests/abc/efg.cairo create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/tests/lib.cairo create mode 100644 docs/listings/hello_workspaces/crates/fibonacci/tests/not_collected.cairo create mode 100644 docs/listings/hello_workspaces/src/lib.cairo create mode 100644 docs/listings/hello_workspaces/tests/test_failing.cairo diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml new file mode 100644 index 0000000000..b065fd03aa --- /dev/null +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -0,0 +1,39 @@ +[workspace] +members = [ + "crates/*", +] + +[workspace.scripts] +test = "snforge" + +[workspace.tool.snforge] + +[workspace.dependencies] +starknet = "2.7.0" + +[workspace.dev-dependencies] +snforge_std = { path = "../../snforge_std" } + +[workspace.package] +version = "0.1.0" + +[package] +name = "hello_workspaces" +version.workspace = true +edition = "2023_10" + +[scripts] +test.workspace = true + +[tool] +snforge.workspace = true + +[dependencies] +fibonacci = { path = "crates/fibonacci" } +addition = { path = "crates/addition" } + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml new file mode 100644 index 0000000000..a88a9a7d28 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -0,0 +1,15 @@ +[package] +name = "addition" +version.workspace = true +edition = "2023_10" + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true + +[lib] diff --git a/docs/listings/hello_workspaces/crates/addition/src/lib.cairo b/docs/listings/hello_workspaces/crates/addition/src/lib.cairo new file mode 100644 index 0000000000..f53d0a379c --- /dev/null +++ b/docs/listings/hello_workspaces/crates/addition/src/lib.cairo @@ -0,0 +1,33 @@ +fn add(a: felt252, b: felt252) -> felt252 { + a + b +} + +#[starknet::interface] +trait IAdditionContract { + fn answer(ref self: TContractState) -> felt252; +} + +#[starknet::contract] +mod AdditionContract { + use addition::add; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + impl AdditionContractImpl of super::IAdditionContract { + fn answer(ref self: ContractState) -> felt252 { + add(10, 20) + } + } +} + +#[cfg(test)] +mod tests { + use super::add; + + #[test] + fn it_works() { + assert(add(2, 3) == 5, 'it works!'); + } +} diff --git a/docs/listings/hello_workspaces/crates/addition/tests/nested.cairo b/docs/listings/hello_workspaces/crates/addition/tests/nested.cairo new file mode 100644 index 0000000000..1ee9db3963 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/addition/tests/nested.cairo @@ -0,0 +1,17 @@ +use snforge_std::declare; + +mod test_nested; + +fn foo() -> u8 { + 2 +} + +#[test] +fn simple_case() { + assert(1 == 1, 'simple check'); +} + +#[test] +fn contract_test() { + declare("AdditionContract").unwrap(); +} diff --git a/docs/listings/hello_workspaces/crates/addition/tests/nested/test_nested.cairo b/docs/listings/hello_workspaces/crates/addition/tests/nested/test_nested.cairo new file mode 100644 index 0000000000..5aa19b8adf --- /dev/null +++ b/docs/listings/hello_workspaces/crates/addition/tests/nested/test_nested.cairo @@ -0,0 +1,12 @@ +use super::foo; + +#[test] +fn test_two() { + assert(foo() == 2, 'foo() == 2'); +} + +#[test] +fn test_two_and_two() { + assert(2 == 2, '2 == 2'); + assert(2 == 2, '2 == 2'); +} diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml new file mode 100644 index 0000000000..7b11acad0e --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -0,0 +1,23 @@ +[package] +name = "fibonacci" +version.workspace = true +edition = "2023_10" + +[scripts] +test.workspace = true + +[tool] +snforge.workspace = true + +[dependencies] +addition = { path = "../addition" } +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[[target.starknet-contract]] +sierra = true +build-external-contracts = ["addition::AdditionContract"] + +[lib] diff --git a/docs/listings/hello_workspaces/crates/fibonacci/src/lib.cairo b/docs/listings/hello_workspaces/crates/fibonacci/src/lib.cairo new file mode 100644 index 0000000000..005d6453f2 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/src/lib.cairo @@ -0,0 +1,39 @@ +use addition::add; + +fn fib(a: felt252, b: felt252, n: felt252) -> felt252 { + match n { + 0 => a, + _ => fib(b, add(a, b), n - 1), + } +} + +#[starknet::contract] +mod FibonacciContract { + use addition::add; + use fibonacci::fib; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + fn answer(ref self: ContractState) -> felt252 { + add(fib(0, 1, 16), fib(0, 1, 8)) + } +} + +#[cfg(test)] +mod tests { + use super::fib; + use snforge_std::declare; + + #[test] + fn it_works() { + assert(fib(0, 1, 16) == 987, 'it works!'); + } + + #[test] + fn contract_test() { + declare("FibonacciContract").unwrap(); + declare("AdditionContract").unwrap(); + } +} diff --git a/docs/listings/hello_workspaces/crates/fibonacci/tests/abc.cairo b/docs/listings/hello_workspaces/crates/fibonacci/tests/abc.cairo new file mode 100644 index 0000000000..8fbad19666 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/tests/abc.cairo @@ -0,0 +1,10 @@ +mod efg; + +#[test] +fn abc_test() { + assert(foo() == 1, ''); +} + +fn foo() -> u8 { + 1 +} diff --git a/docs/listings/hello_workspaces/crates/fibonacci/tests/abc/efg.cairo b/docs/listings/hello_workspaces/crates/fibonacci/tests/abc/efg.cairo new file mode 100644 index 0000000000..b0c8f2a8b8 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/tests/abc/efg.cairo @@ -0,0 +1,9 @@ +#[test] +fn efg_test() { + assert(super::foo() == 1, ''); +} + +#[test] +fn failing_test() { + assert(1 == 2, ''); +} diff --git a/docs/listings/hello_workspaces/crates/fibonacci/tests/lib.cairo b/docs/listings/hello_workspaces/crates/fibonacci/tests/lib.cairo new file mode 100644 index 0000000000..582c1efab6 --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/tests/lib.cairo @@ -0,0 +1,6 @@ +mod abc; + +#[test] +fn lib_test() { + assert(abc::foo() == 1, ''); +} diff --git a/docs/listings/hello_workspaces/crates/fibonacci/tests/not_collected.cairo b/docs/listings/hello_workspaces/crates/fibonacci/tests/not_collected.cairo new file mode 100644 index 0000000000..a4c1b8d76b --- /dev/null +++ b/docs/listings/hello_workspaces/crates/fibonacci/tests/not_collected.cairo @@ -0,0 +1,6 @@ +// should not be collected + +#[test] +fn not_collected() { + assert(1 == 1, ''); +} diff --git a/docs/listings/hello_workspaces/src/lib.cairo b/docs/listings/hello_workspaces/src/lib.cairo new file mode 100644 index 0000000000..a93dc5d461 --- /dev/null +++ b/docs/listings/hello_workspaces/src/lib.cairo @@ -0,0 +1,28 @@ +#[starknet::interface] +trait IFibContract { + fn answer(ref self: TContractState) -> felt252; +} + +#[starknet::contract] +mod FibContract { + use addition::add; + use fibonacci::fib; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + impl FibContractImpl of super::IFibContract { + fn answer(ref self: ContractState) -> felt252 { + add(fib(0, 1, 16), fib(0, 1, 8)) + } + } +} + +#[cfg(test)] +mod tests { + #[test] + fn test_simple() { + assert(1 == 1, 1); + } +} diff --git a/docs/listings/hello_workspaces/tests/test_failing.cairo b/docs/listings/hello_workspaces/tests/test_failing.cairo new file mode 100644 index 0000000000..864786023b --- /dev/null +++ b/docs/listings/hello_workspaces/tests/test_failing.cairo @@ -0,0 +1,9 @@ +#[test] +fn test_failing() { + assert(1 == 2, 'failing check'); +} + +#[test] +fn test_another_failing() { + assert(2 == 3, 'failing check'); +} From fd78dd45ee5d534cabb3a06139e498b0c2d6428c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 15:52:25 +0100 Subject: [PATCH 083/183] Add `SnippetConfig` --- Cargo.lock | 2 + crates/docs/Cargo.toml | 2 + crates/docs/src/validation.rs | 86 +++++++------------ .../tests/e2e/docs_snippets_validation.rs | 50 +++-------- 4 files changed, 46 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb7c4f1f20..4863352e60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1894,6 +1894,8 @@ name = "docs" version = "0.33.0" dependencies = [ "regex", + "serde", + "serde_json", "shell-words", "walkdir", ] diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index a6a11af985..41e8b672b1 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -9,6 +9,8 @@ license.workspace = true regex = "1.11.1" shell-words = "1.1.0" walkdir.workspace = true +serde.workspace = true +serde_json.workspace = true [features] testing = [] diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 82d38f72f7..08b805cb10 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -1,10 +1,9 @@ use regex::Regex; +use serde::{Deserialize, Serialize}; use std::{ - collections::HashMap, env, fs, io, path::{Path, PathBuf}, }; -use walkdir::WalkDir; const EXTENSION: Option<&str> = Some("md"); @@ -38,6 +37,25 @@ impl SnippetType { } } +#[derive(Debug, Deserialize, Serialize, Default)] +pub struct SnippetConfig { + pub ignored: Option, + pub package_name: Option, +} + +impl SnippetConfig { + pub fn from_json(json_str: &str) -> Result { + serde_json::from_str(json_str) + } + + fn default() -> Self { + SnippetConfig { + ignored: None, + package_name: None, + } + } +} + #[derive(Debug)] pub struct Snippet { pub command: String, @@ -45,7 +63,7 @@ pub struct Snippet { pub file_path: String, pub line_start: usize, pub snippet_type: SnippetType, - pub ignored: bool, + pub config: SnippetConfig, } impl Snippet { @@ -94,7 +112,16 @@ pub fn extract_snippets_from_file( let command_match = caps.get(2)?; let match_start = caps.get(0)?.start(); let output = caps.get(3).map(|m| m.as_str().to_string()); - let ignored = caps.get(1).map_or(false, |m| m.as_str().contains("ignore")); + let config_str = caps + .get(1) + .map(|m| m.as_str().to_string()) + .unwrap_or_else(String::new); + + let config = if config_str.is_empty() { + SnippetConfig::default() + } else { + SnippetConfig::from_json(&config_str).expect("Failed to parse snippet config") + }; Some(Snippet { command: command_match.as_str().to_string(), @@ -102,7 +129,7 @@ pub fn extract_snippets_from_file( file_path: file_path_str.clone(), line_start: content[..match_start].lines().count() + 1, snippet_type: snippet_type.clone(), - ignored, + config, }) }) .collect(); @@ -172,52 +199,3 @@ pub fn print_skipped_snippet_message(snippet: &Snippet) { snippet.line_start, ); } - -pub fn create_listings_to_packages_mapping() -> HashMap> { - let docs_listings_path = "../../docs/listings"; - let mut mapping = HashMap::new(); - - for listing in WalkDir::new(docs_listings_path) - .min_depth(1) - .max_depth(1) - .into_iter() - .filter_map(Result::ok) - .filter(|e| e.file_type().is_dir()) - { - let listing_path = listing.path(); - let crates_dir = listing_path.join("crates"); - - if crates_dir.is_dir() { - let packages = list_packages_in_directory(&crates_dir); - if let Some(listing_name) = listing_path.file_name().and_then(|x| x.to_str()) { - if !packages.is_empty() { - mapping.insert(listing_name.to_string(), packages); - } - } - } - } - - mapping -} - -fn list_packages_in_directory(dir_path: &Path) -> Vec { - let crates_path = dir_path.to_owned(); - - if crates_path.exists() && crates_path.is_dir() { - WalkDir::new(crates_path) - .min_depth(1) - .max_depth(1) - .into_iter() - .filter_map(Result::ok) - .filter(|e| e.path().is_dir()) - .filter_map(|e| { - e.path() - .file_name() - .and_then(|name| name.to_str()) - .map(String::from) - }) - .collect() - } else { - Vec::new() - } -} diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 000f4ddec9..a5fdfdc03c 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,34 +1,15 @@ -use std::collections::HashMap; - -use assert_fs::TempDir; use clap::Parser; use docs::validation::{ - assert_valid_snippet, create_listings_to_packages_mapping, extract_snippets_from_directory, - get_parent_dir, print_skipped_snippet_message, print_success_message, SnippetType, + assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, + print_skipped_snippet_message, print_success_message, SnippetType, }; use forge::Cli; use shared::test_utils::output_assert::assert_stdout_contains; -use super::common::runner::{ - setup_hello_workspace, setup_package, setup_package_from_docs_listings, test_runner, -}; - -fn is_package_from_docs_listings( - package: &str, - listings_to_packages_mapping: &HashMap>, -) -> bool { - for packages in listings_to_packages_mapping.values() { - if packages.contains(&package.to_string()) { - return true; - } - } - false -} +use super::common::runner::{setup_package, test_runner}; #[test] fn test_docs_snippets() { - let listings_to_packages_mapping = create_listings_to_packages_mapping(); - let root_dir = get_parent_dir(2); let docs_dir = root_dir.join("docs/src"); @@ -41,7 +22,7 @@ fn test_docs_snippets() { let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); - if snippet.ignored { + if snippet.config.ignored.unwrap_or(false) { print_skipped_snippet_message(snippet); continue; } @@ -63,11 +44,13 @@ fn test_docs_snippets() { if let Some(snippet_output) = &snippet.output { let package_name = snippet - .capture_package_from_output() - .expect("Failed to capture package from command output"); + .config + .package_name + .clone() + .or_else(|| snippet.capture_package_from_output()) + .expect("Cannot find package name in command output or snippet config"); - // TODO(#2698) - let temp = resolve_temp_dir(&package_name, &listings_to_packages_mapping); + let temp = setup_package(&package_name); let output = test_runner(&temp).args(args).assert(); assert_stdout_contains(output, snippet_output); @@ -76,16 +59,3 @@ fn test_docs_snippets() { print_success_message(snippets.len(), snippet_type.as_str()); } - -fn resolve_temp_dir( - package_name: &str, - listings_to_packages_mapping: &HashMap>, -) -> TempDir { - if is_package_from_docs_listings(package_name, listings_to_packages_mapping) { - setup_package_from_docs_listings(package_name, listings_to_packages_mapping) - } else if ["addition", "fibonacci", "hello_workspaces"].contains(&package_name) { - setup_hello_workspace() - } else { - setup_package(package_name) - } -} From e2eb456a58601bad01bb079c0198cd3a59bc265e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 15:52:57 +0100 Subject: [PATCH 084/183] Refactor `setup_package_with_file_patterns` --- crates/forge/tests/e2e/common/runner.rs | 50 ++++++++----------- .../sncast/tests/docs_snippets/validation.rs | 4 +- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 49bbac40c6..ba6963ff08 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -5,7 +5,6 @@ use indoc::formatdoc; use shared::command::CommandExt; use shared::test_utils::node_url::node_rpc_url; use snapbox::cmd::{cargo_bin, Command as SnapboxCommand}; -use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; @@ -34,18 +33,35 @@ pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand { pub(crate) static BASE_FILE_PATTERNS: &[&str] = &["**/*.cairo", "**/*.toml"]; +fn is_package_from_docs_listings(package: &str) -> bool { + fs::read_dir("../../docs/listings") + .unwrap() + .map(|entry| entry.unwrap().file_name().into_string().unwrap()) + .any(|entry| entry == package) +} + pub(crate) fn setup_package_with_file_patterns( - package_path: &str, + package_name: &str, file_patterns: &[&str], ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - let package_path = Utf8PathBuf::from_str(package_path) + + let is_from_docs_listings = is_package_from_docs_listings(package_name); + + let package_path = if is_from_docs_listings { + format!("../../docs/listings/{package_name}",) + } else { + format!("tests/data/{package_name}",) + }; + + let package_path = Utf8PathBuf::from_str(&package_path) .unwrap() .canonicalize_utf8() .unwrap() .to_string() .replace('\\', "/"); - temp.copy_from(package_path.clone(), file_patterns).unwrap(); + + temp.copy_from(package_path, file_patterns).unwrap(); let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std") .unwrap() @@ -66,7 +82,7 @@ pub(crate) fn setup_package_with_file_patterns( value(get_assert_macros_version().unwrap().to_string()); scarb_toml["target.starknet-contract"]["sierra"] = value(true); - if package_path.contains("docs/listings") { + if is_from_docs_listings { scarb_toml["dev-dependencies"]["snforge_std"] .as_table_mut() .and_then(|snforge_std| snforge_std.remove("workspace")); @@ -81,29 +97,7 @@ pub(crate) fn setup_package_with_file_patterns( } pub(crate) fn setup_package(package_name: &str) -> TempDir { - let package_path = "tests/data/".to_string() + package_name; - setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) -} - -fn get_listing_name( - package: &str, - packages_mapping: &HashMap>, -) -> Option { - packages_mapping - .iter() - .find(|(_, packages)| packages.contains(&package.to_string())) - .map(|(listing_name, _)| listing_name.clone()) -} - -pub(crate) fn setup_package_from_docs_listings( - package_name: &str, - packages_mapping: &HashMap>, -) -> TempDir { - let listing_name = get_listing_name(package_name, packages_mapping) - .unwrap_or_else(|| panic!("Couldn't find listing for package {package_name}")); - let package_path = format!("../../docs/listings/{listing_name}/crates/{package_name}",); - - setup_package_with_file_patterns(&package_path, BASE_FILE_PATTERNS) + setup_package_with_file_patterns(package_name, BASE_FILE_PATTERNS) } fn replace_node_rpc_url_placeholders(dir_path: &Path) { diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 1d85aa4176..9c5444db56 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -34,13 +34,11 @@ fn test_docs_snippets() { // remove "sncast" from the args args.remove(0); - if snippet.ignored { + if snippet.config.ignored.unwrap_or(false) { print_skipped_snippet_message(snippet); continue; } - // TODO(#2678) - let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.output().expect("Failed to execute the command"); let exit_code = output.status.code().unwrap_or_default(); From 3dd6452b37150c5ce7d1d49d6a949de70ee02d03 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 17:09:36 +0100 Subject: [PATCH 085/183] Fix typo in packages manifests --- docs/listings/detailed_resources_example/Scarb.toml | 2 +- docs/listings/failing_example/Scarb.toml | 2 +- docs/listings/first_test/Scarb.toml | 2 +- docs/listings/hello_snforge/Scarb.toml | 2 +- docs/listings/hello_starknet/Scarb.toml | 2 +- docs/listings/hello_workspaces/Scarb.toml | 9 ++------- .../listings/hello_workspaces/crates/addition/Scarb.toml | 4 ++-- .../hello_workspaces/crates/fibonacci/Scarb.toml | 4 ++-- docs/listings/ignoring_example/Scarb.toml | 2 +- docs/listings/panicking_test/Scarb.toml | 2 +- docs/listings/should_panic_test/Scarb.toml | 2 +- docs/listings/testing_contract_internals/Scarb.toml | 2 +- docs/listings/testing_events/Scarb.toml | 2 +- docs/listings/testing_messages_to_l1/Scarb.toml | 2 +- .../testing_smart_contracts_handling_errors/Scarb.toml | 2 +- .../testing_smart_contracts_safe_dispatcher/Scarb.toml | 2 +- .../testing_smart_contracts_writing_tests/Scarb.toml | 2 +- 17 files changed, 20 insertions(+), 25 deletions(-) diff --git a/docs/listings/detailed_resources_example/Scarb.toml b/docs/listings/detailed_resources_example/Scarb.toml index 9f413181e6..7293a17409 100644 --- a/docs/listings/detailed_resources_example/Scarb.toml +++ b/docs/listings/detailed_resources_example/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/failing_example/Scarb.toml b/docs/listings/failing_example/Scarb.toml index 62dba01f83..9f13b97edf 100644 --- a/docs/listings/failing_example/Scarb.toml +++ b/docs/listings/failing_example/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/first_test/Scarb.toml b/docs/listings/first_test/Scarb.toml index a660442423..71c617a12f 100644 --- a/docs/listings/first_test/Scarb.toml +++ b/docs/listings/first_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_snforge/Scarb.toml b/docs/listings/hello_snforge/Scarb.toml index 9b8058134f..f6bf4be040 100644 --- a/docs/listings/hello_snforge/Scarb.toml +++ b/docs/listings/hello_snforge/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_starknet/Scarb.toml b/docs/listings/hello_starknet/Scarb.toml index 80f5592f09..d16f045931 100644 --- a/docs/listings/hello_starknet/Scarb.toml +++ b/docs/listings/hello_starknet/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml index b065fd03aa..7455e708a7 100644 --- a/docs/listings/hello_workspaces/Scarb.toml +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -8,12 +8,6 @@ test = "snforge" [workspace.tool.snforge] -[workspace.dependencies] -starknet = "2.7.0" - -[workspace.dev-dependencies] -snforge_std = { path = "../../snforge_std" } - [workspace.package] version = "0.1.0" @@ -31,9 +25,10 @@ snforge.workspace = true [dependencies] fibonacci = { path = "crates/fibonacci" } addition = { path = "crates/addition" } +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml index a88a9a7d28..1a6af2bec1 100644 --- a/docs/listings/hello_workspaces/crates/addition/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -4,10 +4,10 @@ version.workspace = true edition = "2023_10" [dependencies] -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml index 7b11acad0e..a1a104e612 100644 --- a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -11,10 +11,10 @@ snforge.workspace = true [dependencies] addition = { path = "../addition" } -starknet.workspace = true +starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/ignoring_example/Scarb.toml b/docs/listings/ignoring_example/Scarb.toml index db6dddc1be..a4610d0c54 100644 --- a/docs/listings/ignoring_example/Scarb.toml +++ b/docs/listings/ignoring_example/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/panicking_test/Scarb.toml b/docs/listings/panicking_test/Scarb.toml index 8ef56c114d..c4a93e45e9 100644 --- a/docs/listings/panicking_test/Scarb.toml +++ b/docs/listings/panicking_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/should_panic_test/Scarb.toml b/docs/listings/should_panic_test/Scarb.toml index a6e69166ac..d37fc33b9c 100644 --- a/docs/listings/should_panic_test/Scarb.toml +++ b/docs/listings/should_panic_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_contract_internals/Scarb.toml b/docs/listings/testing_contract_internals/Scarb.toml index 50cd30d7f1..6340a8fd2d 100644 --- a/docs/listings/testing_contract_internals/Scarb.toml +++ b/docs/listings/testing_contract_internals/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_events/Scarb.toml b/docs/listings/testing_events/Scarb.toml index 3123ffe196..52fb6b0922 100644 --- a/docs/listings/testing_events/Scarb.toml +++ b/docs/listings/testing_events/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_messages_to_l1/Scarb.toml b/docs/listings/testing_messages_to_l1/Scarb.toml index 671a4900bb..37b22a7bc7 100644 --- a/docs/listings/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/testing_messages_to_l1/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml index 2d03df110d..e3a69868f1 100644 --- a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml +++ b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml index be8d6507ee..54bc45326c 100644 --- a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml +++ b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml index d482893893..146d0a5116 100644 --- a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml +++ b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -sncast_std.workspace = { path = "../../snforge_std" } +snforge_std.workspace = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true From 58bac96e1022f07987eaa0bce76d2a1846889aaa Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 17:10:16 +0100 Subject: [PATCH 086/183] Add config to snippets in markdown files --- docs/src/getting-started/first-steps.md | 2 +- docs/src/starknet/account-import.md | 2 +- docs/src/starknet/index.md | 2 +- docs/src/testing/testing-workspaces.md | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/src/getting-started/first-steps.md b/docs/src/getting-started/first-steps.md index 9d4075cf23..8aa0231c48 100644 --- a/docs/src/getting-started/first-steps.md +++ b/docs/src/getting-started/first-steps.md @@ -73,7 +73,7 @@ snforge_std = "0.33.0" Make sure that the above version matches the installed `snforge` version. You can check the currently installed version with - + ```shell $ snforge --version ``` diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index cb46a503dd..31039fe0ae 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -87,7 +87,7 @@ $ sncast \ If you don't want to pass the private key in the command (because of safety aspect), you can skip `--private-key` flag. You will be prompted to enter the private key in interactive mode. - + ```shell $ sncast \ account import \ diff --git a/docs/src/starknet/index.md b/docs/src/starknet/index.md index 8f441eb2a7..3ddcc44ec0 100644 --- a/docs/src/starknet/index.md +++ b/docs/src/starknet/index.md @@ -12,7 +12,7 @@ Starknet Foundry `sncast` is a command line tool for performing Starknet RPC cal To use `sncast`, run the `sncast` command followed by a subcommand (see [available commands](../appendix/sncast.md)): - + ```shell $ sncast ``` diff --git a/docs/src/testing/testing-workspaces.md b/docs/src/testing/testing-workspaces.md index 460d1bdb91..63eefb8459 100644 --- a/docs/src/testing/testing-workspaces.md +++ b/docs/src/testing/testing-workspaces.md @@ -72,6 +72,7 @@ Failures: To select the specific package to test, pass a `--package package_name` (or `-p package_name` for short) flag. You can also run `snforge test` from the package directory to achieve the same effect. + ```shell $ snforge test --package addition ``` From a951882357144f0711329ccec46a4285a09f2d24 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 17:10:35 +0100 Subject: [PATCH 087/183] Refactor `extract_snippets_from_file` --- crates/docs/src/validation.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 08b805cb10..602ddfd1b7 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -114,8 +114,7 @@ pub fn extract_snippets_from_file( let output = caps.get(3).map(|m| m.as_str().to_string()); let config_str = caps .get(1) - .map(|m| m.as_str().to_string()) - .unwrap_or_else(String::new); + .map_or_else(String::new, |m| m.as_str().to_string()); let config = if config_str.is_empty() { SnippetConfig::default() From 538a7758166e022ca3d87fc410a52937cf9c7066 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 17:14:34 +0100 Subject: [PATCH 088/183] Remove unneeded changes while using `setup_package_with_file_patterns` --- crates/forge/tests/e2e/forking.rs | 8 ++++---- crates/forge/tests/e2e/io_operations.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/forge/tests/e2e/forking.rs b/crates/forge/tests/e2e/forking.rs index 633bbb77eb..2dc4a26882 100644 --- a/crates/forge/tests/e2e/forking.rs +++ b/crates/forge/tests/e2e/forking.rs @@ -8,7 +8,7 @@ use shared::test_utils::output_assert::assert_stdout_contains; #[test] fn without_cache() { - let temp = setup_package_with_file_patterns("tests/data/forking", BASE_FILE_PATTERNS); + let temp = setup_package_with_file_patterns("forking", BASE_FILE_PATTERNS); let output = test_runner(&temp) .arg("forking::tests::test_fork_simple") @@ -40,7 +40,7 @@ fn without_cache() { /// The test that passed when using data from network, should fail for fabricated data. fn with_cache() { let temp = setup_package_with_file_patterns( - "tests/data/forking", + "forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); @@ -75,7 +75,7 @@ fn with_cache() { #[test] fn with_clean_cache() { let temp = setup_package_with_file_patterns( - "tests/data/forking", + "forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); @@ -104,7 +104,7 @@ fn with_clean_cache() { #[test] fn printing_latest_block_number() { let temp = setup_package_with_file_patterns( - "tests/data/forking", + "forking", &[BASE_FILE_PATTERNS, &[&format!("{CACHE_DIR}/*.json")]].concat(), ); let node_rpc_url = node_rpc_url(); diff --git a/crates/forge/tests/e2e/io_operations.rs b/crates/forge/tests/e2e/io_operations.rs index a2d8187a26..af7394c16e 100644 --- a/crates/forge/tests/e2e/io_operations.rs +++ b/crates/forge/tests/e2e/io_operations.rs @@ -7,7 +7,7 @@ use shared::test_utils::output_assert::assert_stdout_contains; #[allow(clippy::too_many_lines)] fn file_reading() { let temp = setup_package_with_file_patterns( - "tests/data/file_reading", + "file_reading", &[BASE_FILE_PATTERNS, &["**/*.txt", "**/*.json"]].concat(), ); From 2a7ea512250f8ddc4ebe55baae30172f4fe86dd2 Mon Sep 17 00:00:00 2001 From: Franciszek Job <54181625+franciszekjob@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:15:33 +0100 Subject: [PATCH 089/183] Update crates/docs/src/validation.rs Co-authored-by: ddoktorski <45050160+ddoktorski@users.noreply.github.com> --- crates/docs/src/validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 602ddfd1b7..d87eddc221 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -178,7 +178,7 @@ pub fn get_parent_dir(levels_up: usize) -> PathBuf { pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &str) { assert!( condition, - "Found invalid {} snippet in the docs in at {}:{}:1\n{}", + "Found invalid {} snippet in the docs at {}:{}:1\n{}", snippet.snippet_type.as_str(), snippet.file_path, snippet.line_start, From 4d18e0aac80fddcc68c8d049781becd35b99da51 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 17:41:42 +0100 Subject: [PATCH 090/183] Trigger CI From e94a85b8ee6934880e9d5b37156345fa2dc925c7 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 18:00:18 +0100 Subject: [PATCH 091/183] Update manifests --- docs/listings/conditional_compilation/Scarb.toml | 6 +++--- docs/listings/direct_storage_access/Scarb.toml | 6 +++--- docs/listings/fork_testing/Scarb.toml | 6 +++--- docs/listings/fuzz_testing/Scarb.toml | 6 +++--- docs/listings/using_cheatcodes/Scarb.toml | 6 +++--- docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml | 6 +++--- docs/listings/using_cheatcodes_cheat_address/Scarb.toml | 6 +++--- docs/listings/using_cheatcodes_others/Scarb.toml | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/listings/conditional_compilation/Scarb.toml b/docs/listings/conditional_compilation/Scarb.toml index 7562310842..7c977ca409 100644 --- a/docs/listings/conditional_compilation/Scarb.toml +++ b/docs/listings/conditional_compilation/Scarb.toml @@ -8,11 +8,11 @@ default = ["enable_for_tests"] enable_for_tests = [] [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/direct_storage_access/Scarb.toml b/docs/listings/direct_storage_access/Scarb.toml index 4662e35f46..fc4ca66e93 100644 --- a/docs/listings/direct_storage_access/Scarb.toml +++ b/docs/listings/direct_storage_access/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/fork_testing/Scarb.toml b/docs/listings/fork_testing/Scarb.toml index 36eda9eda5..8e101f39b9 100644 --- a/docs/listings/fork_testing/Scarb.toml +++ b/docs/listings/fork_testing/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/fuzz_testing/Scarb.toml b/docs/listings/fuzz_testing/Scarb.toml index bd9e3c1248..edc13f9b64 100644 --- a/docs/listings/fuzz_testing/Scarb.toml +++ b/docs/listings/fuzz_testing/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.lib]] sierra = true diff --git a/docs/listings/using_cheatcodes/Scarb.toml b/docs/listings/using_cheatcodes/Scarb.toml index 29c011667a..445ce3cb48 100644 --- a/docs/listings/using_cheatcodes/Scarb.toml +++ b/docs/listings/using_cheatcodes/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml b/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml index ae4219aafe..b08b3448f0 100644 --- a/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml +++ b/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_cheat_address/Scarb.toml b/docs/listings/using_cheatcodes_cheat_address/Scarb.toml index bf870bebeb..927bedf2b6 100644 --- a/docs/listings/using_cheatcodes_cheat_address/Scarb.toml +++ b/docs/listings/using_cheatcodes_cheat_address/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_others/Scarb.toml b/docs/listings/using_cheatcodes_others/Scarb.toml index 918843648a..e3a04d9ee2 100644 --- a/docs/listings/using_cheatcodes_others/Scarb.toml +++ b/docs/listings/using_cheatcodes_others/Scarb.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -assert_macros.workspace = true +starknet = "2.7.0" +assert_macros = "0.1.0" [dev-dependencies] -snforge_std.workspace = true +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true From 393cc2922ea3be2006840c7abcd28b2f6a53cfad Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 22 Nov 2024 18:04:00 +0100 Subject: [PATCH 092/183] Update listings embeds --- .../conditional-compilation.md | 6 +++--- docs/src/snforge-advanced-features/fork-testing.md | 12 ++++++------ docs/src/snforge-advanced-features/fuzz-testing.md | 4 ++-- .../storage-cheatcodes.md | 8 ++++---- docs/src/starknet/script.md | 8 ++++---- docs/src/testing/contracts.md | 14 +++++++------- docs/src/testing/testing-contract-internals.md | 14 +++++++------- docs/src/testing/testing-events.md | 12 ++++++------ docs/src/testing/testing-messages-to-l1.md | 4 ++-- docs/src/testing/testing.md | 14 +++++++------- docs/src/testing/using-cheatcodes.md | 14 +++++++------- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/docs/src/snforge-advanced-features/conditional-compilation.md b/docs/src/snforge-advanced-features/conditional-compilation.md index 1120cf4f79..459298b1e5 100644 --- a/docs/src/snforge-advanced-features/conditional-compilation.md +++ b/docs/src/snforge-advanced-features/conditional-compilation.md @@ -16,7 +16,7 @@ Additionally, for utilizing features the `snforge test` command exposes the foll Firstly, define a contract in the `src` directory with a `#[cfg(feature: '')]` attribute: ```rust -{{#include ../../listings/snforge_advanced_features/crates/conditional_compilation/src/lib.cairo}} +{{#include ../../listings/conditional_compilation/src/lib.cairo}} ``` > 📝 **Note** @@ -27,7 +27,7 @@ Firstly, define a contract in the `src` directory with a `#[cfg(feature: ' ⚠️ **Warning** diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index fecce2ed10..d822d4dda0 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -221,7 +221,7 @@ For more details, see [init command](../appendix/sncast/script/init.md). This example shows how to call an already deployed contract. Please find full example with contract deployment [here](#full-example-with-contract-deployment). ```rust -{{#include ../../listings/sncast_overview/scripts/basic_example/src/basic_example.cairo}} +{{#include ../../listings/basic_example/src/basic_example.cairo}} ``` The script should be included in a Scarb package. The directory structure and config for this example looks like this: @@ -276,13 +276,13 @@ status: success This example script declares, deploys and interacts with an example `MapContract`: ```rust -{{#include ../../listings/sncast_overview/crates/map3/src/lib.cairo}} +{{#include ../../listings/map3/src/lib.cairo}} ``` We prepare a script: ```rust -{{#include ../../listings/sncast_overview/scripts/full_example/src/full_example.cairo}} +{{#include ../../listings/full_example/src/full_example.cairo}} ``` The script should be included in a Scarb package. The directory structure and config for this example looks like this: @@ -414,7 +414,7 @@ Script errors implement `Debug` trait, allowing the error to be printed to stdou ### Minimal example with `assert!` and `println!` ```rust -{{#include ../../listings/sncast_overview/scripts/error_handling/src/error_handling.cairo}} +{{#include ../../listings/error_handling/src/error_handling.cairo}} ``` More on deployment scripts errors [here](../appendix/sncast-library/errors.md). diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index d6e432c2ed..5b3433cc8b 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -19,7 +19,7 @@ writing smart contracts, you often want to test their interactions with the bloc Let's consider a simple smart contract with two methods. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_writing_tests/src/lib.cairo}} +{{#include ../../listings/testing_smart_contracts_writing_tests/src/lib.cairo}} ``` Note that the name after `mod` will be used as the contract name for testing purposes. @@ -29,7 +29,7 @@ Note that the name after `mod` will be used as the contract name for testing pur Let's write a test that will deploy the `HelloStarknet` contract and call some functions. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_writing_tests/tests/simple_contract.cairo}} +{{#include ../../listings/testing_smart_contracts_writing_tests/tests/simple_contract.cairo}} ``` > 📝 **Note** @@ -72,14 +72,14 @@ panicking. First, let's add a new, panicking function to our contract. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/src/lib.cairo}} +{{#include ../../listings/testing_smart_contracts_handling_errors/src/lib.cairo}} ``` If we called this function in a test, it would result in a failure. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/panic.cairo:second_half}} +{{#include ../../listings/testing_smart_contracts_handling_errors/tests/panic.cairo:first_half}} +{{#include ../../listings/testing_smart_contracts_handling_errors/tests/panic.cairo:second_half}} ``` ```shell @@ -116,7 +116,7 @@ but are available for testing purposes. They allow using the contract without automatically unwrapping the result, which allows to catch the error like shown below. ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo}} +{{#include ../../listings/testing_smart_contracts_safe_dispatcher/tests/safe_dispatcher.cairo}} ``` Now the test passes as expected. @@ -141,7 +141,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out Similarly, you can handle the panics which use `ByteArray` as an argument (like an `assert!` or `panic!` macro) ```rust -{{#include ../../listings/snforge_overview/crates/testing_smart_contracts_handling_errors/tests/handle_panic.cairo}} +{{#include ../../listings/testing_smart_contracts_handling_errors/tests/handle_panic.cairo}} ``` You also could skip the de-serialization of the `panic_data`, and not use `try_deserialize_bytearray_error`, but this way you can actually use assertions on the `ByteArray` that was used to panic. diff --git a/docs/src/testing/testing-contract-internals.md b/docs/src/testing/testing-contract-internals.md index 8bf3aff494..f653f49cf2 100644 --- a/docs/src/testing/testing-contract-internals.md +++ b/docs/src/testing/testing-contract-internals.md @@ -18,7 +18,7 @@ This is a function generated by the `#[starknet::contract]` macro. It can be used to test some functions which accept the state as an argument, see the example below: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/src/basic_example.cairo}} +{{#include ../../listings/testing_contract_internals/src/basic_example.cairo}} ``` This code contains some caveats: @@ -38,7 +38,7 @@ Example usages: Example for `cheat_block_number`, same can be implemented for `cheat_caller_address`/`cheat_block_timestamp`/`elect` etc. ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/tests/mocking_the_context_info.cairo}} +{{#include ../../listings/testing_contract_internals/tests/mocking_the_context_info.cairo}} ``` #### 2. Spying for events You can use both `starknet::emit_event_syscall`, and the spies will capture the events, @@ -47,17 +47,17 @@ emitted in a `#[test]` function, if you pass the `test_address()` as a spy param Given the emitting contract implementation: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/src/spying_for_events.cairo}} +{{#include ../../listings/testing_contract_internals/src/spying_for_events.cairo}} ``` You can implement this test: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/tests.cairo}} +{{#include ../../listings/testing_contract_internals/tests/spying_for_events/tests.cairo}} ``` You can also use the `starknet::emit_event_syscall` directly in the tests: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo}} +{{#include ../../listings/testing_contract_internals/tests/spying_for_events/syscall_tests.cairo}} ``` ## Using Library Calls With the Test State Context @@ -67,11 +67,11 @@ Using the above utilities, you can avoid deploying a mock contract, to test a `l For contract implementation: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/src/using_library_calls.cairo}} +{{#include ../../listings/testing_contract_internals/src/using_library_calls.cairo}} ``` We use the `SafeLibraryDispatcher` like this: ```rust -{{#include ../../listings/snforge_overview/crates/testing_contract_internals/tests/using_library_calls.cairo}} +{{#include ../../listings/testing_contract_internals/tests/using_library_calls.cairo}} ``` > ⚠️ **Warning** > diff --git a/docs/src/testing/testing-events.md b/docs/src/testing/testing-events.md index 31342fc6ca..37cf58dbcd 100644 --- a/docs/src/testing/testing-events.md +++ b/docs/src/testing/testing-events.md @@ -2,7 +2,7 @@ Examples are based on the following `SpyEventsChecker` contract implementation: ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/src/contract.cairo}} +{{#include ../../listings/testing_events/src/contract.cairo}} ``` ## Asserting emission with `assert_emitted` method @@ -11,7 +11,7 @@ This is the simpler way, in which you don't have to fetch the events explicitly. See the below code for reference: ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/tests/assert_emitted.cairo}} +{{#include ../../listings/testing_events/tests/assert_emitted.cairo}} ``` Let's go through the code: @@ -52,7 +52,7 @@ Simply call `get_events()` on your `EventSpy` and access `events` field on the Then, you can access the events and assert data by yourself. ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/tests/assert_manually.cairo}} +{{#include ../../listings/testing_events/tests/assert_manually.cairo}} ``` Let's go through important parts of the provided code: @@ -75,7 +75,7 @@ Sometimes, when you assert the events manually, you might not want to get all th a particular address. You can address that by using the method `emitted_by` on the `Events` structure. ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/tests/filter.cairo}} +{{#include ../../listings/testing_events/tests/filter.cairo}} ``` `events_from_first_address` has events emitted by the first contract only. @@ -89,13 +89,13 @@ They can also be asserted with `spy.assert_emitted` method. Let's extend our `SpyEventsChecker` with `emit_event_with_syscall` method: ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/src/syscall_dummy.cairo}} +{{#include ../../listings/testing_events/src/syscall_dummy.cairo}} ``` And add a test for it: ```rust -{{#include ../../listings/snforge_overview/crates/testing_events/tests/syscall.cairo}} +{{#include ../../listings/testing_events/tests/syscall.cairo}} ``` Using `Event` struct from the `snforge_std` library we can easily assert nonstandard events. diff --git a/docs/src/testing/testing-messages-to-l1.md b/docs/src/testing/testing-messages-to-l1.md index fe0c490bbb..74902deafb 100644 --- a/docs/src/testing/testing-messages-to-l1.md +++ b/docs/src/testing/testing-messages-to-l1.md @@ -34,11 +34,11 @@ With the spy ready to use, you can execute some code, and make the assertions: 1. Either with the spy directly by using `assert_sent`/`assert_not_sent` methods from `MessageToL1SpyAssertionsTrait` trait: ```rust -{{#include ../../listings/snforge_overview/crates/testing_messages_to_l1/tests/simple.cairo}} +{{#include ../../listings/testing_messages_to_l1/tests/simple.cairo}} ``` 2. Or use the messages' contents directly via `get_messages()` method of the `MessageToL1SpyTrait`: ```rust -{{#include ../../listings/snforge_overview/crates/testing_messages_to_l1/tests/detailed.cairo}} +{{#include ../../listings/testing_messages_to_l1/tests/detailed.cairo}} ``` diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index af813d285c..e4ad6fd7dd 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -8,7 +8,7 @@ should write as many unit tests as possible as these are faster than integration First, add the following code to the `src/lib.cairo` file: ```rust -{{#include ../../listings/snforge_overview/crates/first_test/src/lib.cairo}} +{{#include ../../listings/first_test/src/lib.cairo}} ``` It is a common practice to keep your unit tests in the same file as the tested code. @@ -39,8 +39,8 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out If your code panics, the test is considered failed. Here's an example of a failing test. ```rust -{{#include ../../listings/snforge_overview/crates/panicking_test/src/lib.cairo:first_half}} -{{#include ../../listings/snforge_overview/crates/panicking_test/src/lib.cairo:second_half}} +{{#include ../../listings/panicking_test/src/lib.cairo:first_half}} +{{#include ../../listings/panicking_test/src/lib.cairo:second_half}} ``` ```shell @@ -77,18 +77,18 @@ You can specify the expected failure message in three ways: 1. **With ByteArray**: ```rust -{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:byte_array}} +{{#include ../../listings/should_panic_test/src/lib.cairo:byte_array}} ``` With this format, the expected error message needs to be a substring of the actual error message. This is particularly useful when the error message includes dynamic data such as a hash or address. 2. **With felt** ```rust -{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:felt}} +{{#include ../../listings/should_panic_test/src/lib.cairo:felt}} ``` 3. **With tuple of felts**: ```rust -{{#include ../../listings/snforge_overview/crates/should_panic_test/src/lib.cairo:tuple}} +{{#include ../../listings/should_panic_test/src/lib.cairo:tuple}} ``` @@ -118,7 +118,7 @@ Sometimes you may have tests that you want to exclude during most runs of `snfor You can achieve it using `#[ignore]` - tests marked with this attribute will be skipped by default. ```rust -{{#include ../../listings/snforge_overview/crates/ignoring_example/src/lib.cairo}} +{{#include ../../listings/ignoring_example/src/lib.cairo}} ``` ```shell diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index eb48c3b976..1ce48ad934 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -23,7 +23,7 @@ using [cheatcodes](../appendix/cheatcodes.md). In this tutorial, we will be using the following Starknet contract: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/src/lib.cairo}} +{{#include ../../listings/using_cheatcodes/src/lib.cairo}} ``` ## Writing Tests @@ -31,7 +31,7 @@ In this tutorial, we will be using the following Starknet contract: We can try to create a test that will increase and verify the balance. ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes/tests/lib.cairo}} +{{#include ../../listings/using_cheatcodes/tests/lib.cairo}} ``` This test fails, which means that `increase_balance` method panics as we expected. @@ -71,7 +71,7 @@ address, so it passes our validation. ### Cheating an Address ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes_cheat_address/tests/lib.cairo}} +{{#include ../../listings/using_cheatcodes_cheat_address/tests/lib.cairo}} ``` The test will now pass without an error @@ -102,7 +102,7 @@ using [`stop_cheat_caller_address`](../appendix/cheatcodes/caller_address.md#sto We will demonstrate its behavior using `SafeDispatcher` to show when exactly the fail occurs: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes_cancelling_cheat/tests/lib.cairo}} +{{#include ../../listings/using_cheatcodes_cancelling_cheat/tests/lib.cairo}} ``` ```shell @@ -137,7 +137,7 @@ In case you want to cheat the caller address for all contracts, you can use the For more see [Cheating Globally](../appendix/cheatcodes/global.md). ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo}} +{{#include ../../listings/using_cheatcodes_others/tests/caller_address/proper_use_global.cairo}} ``` ### Cheating the Constructor @@ -149,7 +149,7 @@ Let's say, that you have a contract that saves the caller address (deployer) in To `cheat_caller_address` the constructor, you need to `start_cheat_caller_address` before it is invoked, with the right address. To achieve this, you need to precalculate the address of the contract by using the `precalculate_address` function of `ContractClassTrait` on the declared contract, and then use it in `start_cheat_caller_address` as an argument: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/cheat_constructor.cairo}} +{{#include ../../listings/using_cheatcodes_others/tests/cheat_constructor.cairo}} ``` ### Setting Cheatcode Span @@ -183,5 +183,5 @@ Of course the cheatcode can still be canceled before its `CheatSpan` goes down t To better understand the functionality of `CheatSpan`, here's a full example: ```rust -{{#include ../../listings/snforge_overview/crates/using_cheatcodes_others/tests/caller_address/span.cairo}} +{{#include ../../listings/using_cheatcodes_others/tests/caller_address/span.cairo}} ``` From db852eb0b08039e434b248cc23d339e78465835b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 24 Nov 2024 21:47:45 +0100 Subject: [PATCH 093/183] Fix failing tests --- crates/forge/tests/e2e/common/runner.rs | 10 +++++++++- docs/listings/hello_workspaces/Scarb.toml | 4 ++-- .../hello_workspaces/crates/addition/Scarb.toml | 2 +- .../hello_workspaces/crates/fibonacci/Scarb.toml | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index ba6963ff08..89e8337132 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -76,7 +76,15 @@ pub(crate) fn setup_package_with_file_patterns( .unwrap() .parse::() .unwrap(); - scarb_toml["dev-dependencies"]["snforge_std"]["path"] = value(snforge_std_path); + + let is_workspace = scarb_toml.get("workspace").is_some(); + + if is_workspace { + scarb_toml["workspace"]["dependencies"]["snforge_std"]["path"] = value(snforge_std_path); + } else { + scarb_toml["dev-dependencies"]["snforge_std"]["path"] = value(snforge_std_path); + } + scarb_toml["dependencies"]["starknet"] = value("2.4.0"); scarb_toml["dependencies"]["assert_macros"] = value(get_assert_macros_version().unwrap().to_string()); diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml index 7455e708a7..8e47bbc6f5 100644 --- a/docs/listings/hello_workspaces/Scarb.toml +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -27,8 +27,8 @@ fibonacci = { path = "crates/fibonacci" } addition = { path = "crates/addition" } starknet = "2.7.0" -[dev-dependencies] -snforge_std = { path = "../../snforge_std" } +[workspace.dependencies] +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml index 1a6af2bec1..d67f97584f 100644 --- a/docs/listings/hello_workspaces/crates/addition/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_10" starknet = "2.7.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml index a1a104e612..45378edf34 100644 --- a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -14,7 +14,7 @@ addition = { path = "../addition" } starknet = "2.7.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true From b97ae4b9f1a403eacc464f2072cb52c161f64696 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 24 Nov 2024 23:54:21 +0100 Subject: [PATCH 094/183] Rename package; Fix `should_panic` test --- docs/listings/basic_example/Scarb.toml | 9 +++++++-- .../Scarb.toml | 2 +- .../src/lib.cairo | 0 docs/src/testing/testing.md | 18 +++++++++--------- 4 files changed, 17 insertions(+), 12 deletions(-) rename docs/listings/{should_panic_test => should_panic_example}/Scarb.toml (88%) rename docs/listings/{should_panic_test => should_panic_example}/src/lib.cairo (100%) diff --git a/docs/listings/basic_example/Scarb.toml b/docs/listings/basic_example/Scarb.toml index b425f3ed72..e4e304f715 100644 --- a/docs/listings/basic_example/Scarb.toml +++ b/docs/listings/basic_example/Scarb.toml @@ -6,9 +6,14 @@ edition = "2024_07" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -snforge_std.workspace = true +starknet = "2.7.0" + +[dev-dependencies] +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } + +[[target.starknet-contract]] sncast_std.workspace = true -starknet.workspace = true [[target.lib]] sierra = true diff --git a/docs/listings/should_panic_test/Scarb.toml b/docs/listings/should_panic_example/Scarb.toml similarity index 88% rename from docs/listings/should_panic_test/Scarb.toml rename to docs/listings/should_panic_example/Scarb.toml index d37fc33b9c..15e997d4a4 100644 --- a/docs/listings/should_panic_test/Scarb.toml +++ b/docs/listings/should_panic_example/Scarb.toml @@ -1,5 +1,5 @@ [package] -name = "should_panic_test" +name = "should_panic_example" version = "0.1.0" edition = "2023_11" diff --git a/docs/listings/should_panic_test/src/lib.cairo b/docs/listings/should_panic_example/src/lib.cairo similarity index 100% rename from docs/listings/should_panic_test/src/lib.cairo rename to docs/listings/should_panic_example/src/lib.cairo diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index e4ad6fd7dd..957d3a06e3 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -77,18 +77,18 @@ You can specify the expected failure message in three ways: 1. **With ByteArray**: ```rust -{{#include ../../listings/should_panic_test/src/lib.cairo:byte_array}} +{{#include ../../listings/should_panic_example/src/lib.cairo:byte_array}} ``` With this format, the expected error message needs to be a substring of the actual error message. This is particularly useful when the error message includes dynamic data such as a hash or address. 2. **With felt** ```rust -{{#include ../../listings/should_panic_test/src/lib.cairo:felt}} +{{#include ../../listings/should_panic_example/src/lib.cairo:felt}} ``` 3. **With tuple of felts**: ```rust -{{#include ../../listings/should_panic_test/src/lib.cairo:tuple}} +{{#include ../../listings/should_panic_example/src/lib.cairo:tuple}} ``` @@ -100,13 +100,13 @@ $ snforge test Output: ```shell -Collected 5 test(s) from should_panic_test package +Collected 5 test(s) from should_panic_example package Running 5 test(s) from src/ -[PASS] should_panic_test::tests::should_panic_felt_matching (gas: ~1) -[PASS] should_panic_test::tests::should_panic_multiple_messages (gas: ~1) -[PASS] should_panic_test::tests::should_panic_exact (gas: ~1) -[PASS] should_panic_test::tests::should_panic_expected_is_substring (gas: ~1) -[PASS] should_panic_test::tests::should_panic_check_data (gas: ~1) +[PASS] should_panic_example::tests::should_panic_felt_matching (gas: ~1) +[PASS] should_panic_example::tests::should_panic_multiple_messages (gas: ~1) +[PASS] should_panic_example::tests::should_panic_exact (gas: ~1) +[PASS] should_panic_example::tests::should_panic_expected_is_substring (gas: ~1) +[PASS] should_panic_example::tests::should_panic_check_data (gas: ~1) Tests: 5 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out ```
From 97171b618d194e8dc80474e632960b77c6552ec7 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 00:18:58 +0100 Subject: [PATCH 095/183] Temporarily change `get_remote_url` --- crates/forge/tests/e2e/common/runner.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 89e8337132..b001ee7916 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -245,12 +245,7 @@ pub(crate) fn get_remote_url() -> String { .output_checked() .unwrap(); - String::from_utf8(output.stdout) - .unwrap() - .trim() - .strip_prefix("git@github.com:") - .unwrap() - .to_string() + String::from_utf8(output.stdout).unwrap().trim().to_string() } } From d6800830902a5bd40116f083d63b019b34a83421 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 00:31:27 +0100 Subject: [PATCH 096/183] Fix dependencies in listings manifests --- docs/listings/conditional_compilation/Scarb.toml | 2 +- docs/listings/detailed_resources_example/Scarb.toml | 2 +- docs/listings/direct_storage_access/Scarb.toml | 2 +- docs/listings/error_handling/Scarb.toml | 8 ++++---- docs/listings/failing_example/Scarb.toml | 2 +- docs/listings/first_test/Scarb.toml | 2 +- docs/listings/fork_testing/Scarb.toml | 2 +- docs/listings/full_example/Scarb.toml | 6 +++--- docs/listings/fuzz_testing/Scarb.toml | 2 +- docs/listings/get_nonce/Scarb.toml | 6 +++--- docs/listings/hello_snforge/Scarb.toml | 2 +- docs/listings/hello_starknet/Scarb.toml | 2 +- docs/listings/ignoring_example/Scarb.toml | 2 +- docs/listings/invoke/Scarb.toml | 6 +++--- docs/listings/map3/Scarb.toml | 4 ++-- docs/listings/panicking_test/Scarb.toml | 2 +- docs/listings/should_panic_example/Scarb.toml | 2 +- docs/listings/testing_contract_internals/Scarb.toml | 2 +- docs/listings/testing_events/Scarb.toml | 2 +- docs/listings/testing_messages_to_l1/Scarb.toml | 2 +- .../testing_smart_contracts_handling_errors/Scarb.toml | 2 +- .../testing_smart_contracts_safe_dispatcher/Scarb.toml | 2 +- .../testing_smart_contracts_writing_tests/Scarb.toml | 2 +- docs/listings/tx_status/Scarb.toml | 6 +++--- docs/listings/using_cheatcodes/Scarb.toml | 2 +- .../listings/using_cheatcodes_cancelling_cheat/Scarb.toml | 2 +- docs/listings/using_cheatcodes_cheat_address/Scarb.toml | 2 +- docs/listings/using_cheatcodes_others/Scarb.toml | 2 +- 28 files changed, 40 insertions(+), 40 deletions(-) diff --git a/docs/listings/conditional_compilation/Scarb.toml b/docs/listings/conditional_compilation/Scarb.toml index 7c977ca409..136ac8da96 100644 --- a/docs/listings/conditional_compilation/Scarb.toml +++ b/docs/listings/conditional_compilation/Scarb.toml @@ -12,7 +12,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/detailed_resources_example/Scarb.toml b/docs/listings/detailed_resources_example/Scarb.toml index 7293a17409..788a68ee9d 100644 --- a/docs/listings/detailed_resources_example/Scarb.toml +++ b/docs/listings/detailed_resources_example/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/direct_storage_access/Scarb.toml b/docs/listings/direct_storage_access/Scarb.toml index fc4ca66e93..b1f73067fa 100644 --- a/docs/listings/direct_storage_access/Scarb.toml +++ b/docs/listings/direct_storage_access/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/error_handling/Scarb.toml b/docs/listings/error_handling/Scarb.toml index b52b5904ba..a955fc9ac2 100644 --- a/docs/listings/error_handling/Scarb.toml +++ b/docs/listings/error_handling/Scarb.toml @@ -6,10 +6,10 @@ edition = "2024_07" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -snforge_std.workspace = true -sncast_std.workspace = true -starknet.workspace = true -assert_macros.workspace = true +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } +starknet.workspace = "2.7.0" +assert_macros = "0.1.0" [[target.lib]] sierra = true diff --git a/docs/listings/failing_example/Scarb.toml b/docs/listings/failing_example/Scarb.toml index 9f13b97edf..890df4147f 100644 --- a/docs/listings/failing_example/Scarb.toml +++ b/docs/listings/failing_example/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/first_test/Scarb.toml b/docs/listings/first_test/Scarb.toml index 71c617a12f..1b14dabb57 100644 --- a/docs/listings/first_test/Scarb.toml +++ b/docs/listings/first_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/fork_testing/Scarb.toml b/docs/listings/fork_testing/Scarb.toml index 8e101f39b9..7bc4b5d822 100644 --- a/docs/listings/fork_testing/Scarb.toml +++ b/docs/listings/fork_testing/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/full_example/Scarb.toml b/docs/listings/full_example/Scarb.toml index e4e6c65dee..5f8e8a5da7 100644 --- a/docs/listings/full_example/Scarb.toml +++ b/docs/listings/full_example/Scarb.toml @@ -6,9 +6,9 @@ edition = "2024_07" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -snforge_std.workspace = true -sncast_std.workspace = true -map3 = { path = "../../crates/map3" } +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } +map3 = { path = "../map3" } [[target.starknet-contract]] build-external-contracts = ["map3::MapContract"] diff --git a/docs/listings/fuzz_testing/Scarb.toml b/docs/listings/fuzz_testing/Scarb.toml index edc13f9b64..a0a0076d75 100644 --- a/docs/listings/fuzz_testing/Scarb.toml +++ b/docs/listings/fuzz_testing/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.lib]] sierra = true diff --git a/docs/listings/get_nonce/Scarb.toml b/docs/listings/get_nonce/Scarb.toml index d908abfca9..2f1d1a50fd 100644 --- a/docs/listings/get_nonce/Scarb.toml +++ b/docs/listings/get_nonce/Scarb.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -snforge_std.workspace = true -sncast_std.workspace = true +starknet.workspace = "2.7.0" +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_snforge/Scarb.toml b/docs/listings/hello_snforge/Scarb.toml index f6bf4be040..364c9066d0 100644 --- a/docs/listings/hello_snforge/Scarb.toml +++ b/docs/listings/hello_snforge/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_starknet/Scarb.toml b/docs/listings/hello_starknet/Scarb.toml index d16f045931..717985204b 100644 --- a/docs/listings/hello_starknet/Scarb.toml +++ b/docs/listings/hello_starknet/Scarb.toml @@ -9,7 +9,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/ignoring_example/Scarb.toml b/docs/listings/ignoring_example/Scarb.toml index a4610d0c54..6ce2d88b2d 100644 --- a/docs/listings/ignoring_example/Scarb.toml +++ b/docs/listings/ignoring_example/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/invoke/Scarb.toml b/docs/listings/invoke/Scarb.toml index 1936363e8c..55ed304196 100644 --- a/docs/listings/invoke/Scarb.toml +++ b/docs/listings/invoke/Scarb.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -snforge_std.workspace = true -sncast_std.workspace = true +starknet = "2.7.0" +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/map3/Scarb.toml b/docs/listings/map3/Scarb.toml index 4dec1caab6..0e4e7d558a 100644 --- a/docs/listings/map3/Scarb.toml +++ b/docs/listings/map3/Scarb.toml @@ -10,8 +10,8 @@ sierra = true sierra = false [dependencies] -snforge_std.workspace = true -starknet.workspace = true +snforge_std = { path = "../../../snforge_std" } +starknet = "2.7.0" [scripts] test = "snforge test" diff --git a/docs/listings/panicking_test/Scarb.toml b/docs/listings/panicking_test/Scarb.toml index c4a93e45e9..081895dade 100644 --- a/docs/listings/panicking_test/Scarb.toml +++ b/docs/listings/panicking_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/should_panic_example/Scarb.toml b/docs/listings/should_panic_example/Scarb.toml index 15e997d4a4..7980eeca8d 100644 --- a/docs/listings/should_panic_example/Scarb.toml +++ b/docs/listings/should_panic_example/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_contract_internals/Scarb.toml b/docs/listings/testing_contract_internals/Scarb.toml index 6340a8fd2d..05aab81c8a 100644 --- a/docs/listings/testing_contract_internals/Scarb.toml +++ b/docs/listings/testing_contract_internals/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_events/Scarb.toml b/docs/listings/testing_events/Scarb.toml index 52fb6b0922..bb14cc408c 100644 --- a/docs/listings/testing_events/Scarb.toml +++ b/docs/listings/testing_events/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_messages_to_l1/Scarb.toml b/docs/listings/testing_messages_to_l1/Scarb.toml index 37b22a7bc7..892751fe9f 100644 --- a/docs/listings/testing_messages_to_l1/Scarb.toml +++ b/docs/listings/testing_messages_to_l1/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml index e3a69868f1..90c0ebf9ad 100644 --- a/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml +++ b/docs/listings/testing_smart_contracts_handling_errors/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml index 54bc45326c..571443a88d 100644 --- a/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml +++ b/docs/listings/testing_smart_contracts_safe_dispatcher/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml index 146d0a5116..234185fba5 100644 --- a/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml +++ b/docs/listings/testing_smart_contracts_writing_tests/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/tx_status/Scarb.toml b/docs/listings/tx_status/Scarb.toml index 5a3a2a08ae..457e692acf 100644 --- a/docs/listings/tx_status/Scarb.toml +++ b/docs/listings/tx_status/Scarb.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -snforge_std.workspace = true -sncast_std.workspace = true +starknet = "2.7.0" +snforge_std = { path = "../../snforge_std" } +sncast_std = { path = "../../sncast_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes/Scarb.toml b/docs/listings/using_cheatcodes/Scarb.toml index 445ce3cb48..70ab8ea626 100644 --- a/docs/listings/using_cheatcodes/Scarb.toml +++ b/docs/listings/using_cheatcodes/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml b/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml index b08b3448f0..ec3efea5ea 100644 --- a/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml +++ b/docs/listings/using_cheatcodes_cancelling_cheat/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_cheat_address/Scarb.toml b/docs/listings/using_cheatcodes_cheat_address/Scarb.toml index 927bedf2b6..b75776b9b3 100644 --- a/docs/listings/using_cheatcodes_cheat_address/Scarb.toml +++ b/docs/listings/using_cheatcodes_cheat_address/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/using_cheatcodes_others/Scarb.toml b/docs/listings/using_cheatcodes_others/Scarb.toml index e3a04d9ee2..f9049e22b8 100644 --- a/docs/listings/using_cheatcodes_others/Scarb.toml +++ b/docs/listings/using_cheatcodes_others/Scarb.toml @@ -8,7 +8,7 @@ starknet = "2.7.0" assert_macros = "0.1.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true From 4c04d41b7d1456e1266575d355344d9d2c2af4e9 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 00:38:17 +0100 Subject: [PATCH 097/183] Fix dependencies in the rest of packages manifests --- docs/listings/basic_example/Scarb.toml | 2 +- docs/listings/panicking_test/Scarb.toml | 2 +- docs/listings/tx_status/Scarb.toml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/listings/basic_example/Scarb.toml b/docs/listings/basic_example/Scarb.toml index e4e304f715..0de0e3ff2b 100644 --- a/docs/listings/basic_example/Scarb.toml +++ b/docs/listings/basic_example/Scarb.toml @@ -13,7 +13,7 @@ snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] -sncast_std.workspace = true +sncast_std = { path = "../../../sncast_std" } [[target.lib]] sierra = true diff --git a/docs/listings/panicking_test/Scarb.toml b/docs/listings/panicking_test/Scarb.toml index 081895dade..ef03e9c5e4 100644 --- a/docs/listings/panicking_test/Scarb.toml +++ b/docs/listings/panicking_test/Scarb.toml @@ -7,7 +7,7 @@ edition = "2023_11" starknet = "2.7.0" [dev-dependencies] -snforge_std = { path = "../../snforge_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/tx_status/Scarb.toml b/docs/listings/tx_status/Scarb.toml index 457e692acf..1b98344e94 100644 --- a/docs/listings/tx_status/Scarb.toml +++ b/docs/listings/tx_status/Scarb.toml @@ -5,8 +5,8 @@ edition = "2023_11" [dependencies] starknet = "2.7.0" -snforge_std = { path = "../../snforge_std" } -sncast_std = { path = "../../sncast_std" } +snforge_std = { path = "../../../snforge_std" } +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true From 06f10ededb3401b51c700268ed504e8af4450cfd Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 00:45:58 +0100 Subject: [PATCH 098/183] Fix dependencies in the rest of packages manifests --- docs/listings/call/Scarb.toml | 4 ++-- docs/listings/declare/Scarb.toml | 4 ++-- docs/listings/deploy/Scarb.toml | 6 ++++-- docs/listings/error_handling/Scarb.toml | 2 +- docs/listings/get_nonce/Scarb.toml | 2 +- docs/listings/hello_workspaces/Scarb.toml | 9 ++++++--- .../hello_workspaces/crates/addition/Scarb.toml | 6 ++++-- .../hello_workspaces/crates/fibonacci/Scarb.toml | 12 ++++++++---- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/docs/listings/call/Scarb.toml b/docs/listings/call/Scarb.toml index 445f83833b..0b98573547 100644 --- a/docs/listings/call/Scarb.toml +++ b/docs/listings/call/Scarb.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -sncast_std.workspace = true +starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [[target.lib]] sierra = true diff --git a/docs/listings/declare/Scarb.toml b/docs/listings/declare/Scarb.toml index b7fbb9f0e9..171e0e23b4 100644 --- a/docs/listings/declare/Scarb.toml +++ b/docs/listings/declare/Scarb.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -sncast_std.workspace = true +starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/deploy/Scarb.toml b/docs/listings/deploy/Scarb.toml index 1ae2f99497..436061dac4 100644 --- a/docs/listings/deploy/Scarb.toml +++ b/docs/listings/deploy/Scarb.toml @@ -4,8 +4,10 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = true -sncast_std.workspace = true +starknetstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } +sncast_stdstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [[target.lib]] sierra = true diff --git a/docs/listings/error_handling/Scarb.toml b/docs/listings/error_handling/Scarb.toml index a955fc9ac2..5ef420704b 100644 --- a/docs/listings/error_handling/Scarb.toml +++ b/docs/listings/error_handling/Scarb.toml @@ -8,7 +8,7 @@ edition = "2024_07" [dependencies] snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } -starknet.workspace = "2.7.0" +starknet = "2.7.0" assert_macros = "0.1.0" [[target.lib]] diff --git a/docs/listings/get_nonce/Scarb.toml b/docs/listings/get_nonce/Scarb.toml index 2f1d1a50fd..9101a6c268 100644 --- a/docs/listings/get_nonce/Scarb.toml +++ b/docs/listings/get_nonce/Scarb.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknet.workspace = "2.7.0" +starknetstarknet = "2.7.0" snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml index 8e47bbc6f5..40081f42fe 100644 --- a/docs/listings/hello_workspaces/Scarb.toml +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -13,14 +13,17 @@ version = "0.1.0" [package] name = "hello_workspaces" -version.workspace = true +versionstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } edition = "2023_10" [scripts] -test.workspace = true +teststarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [tool] -snforge.workspace = true +snforgestarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [dependencies] fibonacci = { path = "crates/fibonacci" } diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml index d67f97584f..38843cb8d1 100644 --- a/docs/listings/hello_workspaces/crates/addition/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -1,13 +1,15 @@ [package] name = "addition" -version.workspace = true +versionstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } edition = "2023_10" [dependencies] starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +snforge_stdstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml index 45378edf34..0fbe2c960d 100644 --- a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -1,20 +1,24 @@ [package] name = "fibonacci" -version.workspace = true +versionstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } edition = "2023_10" [scripts] -test.workspace = true +teststarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [tool] -snforge.workspace = true +snforgestarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [dependencies] addition = { path = "../addition" } starknet = "2.7.0" [dev-dependencies] -snforge_std.workspace = true +snforge_stdstarknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true From 36164d0229bb68a53ea7fd2511b836451c8d7dff Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 00:54:14 +0100 Subject: [PATCH 099/183] Fix dependencies in the rest of packages manifests --- docs/listings/basic_example/Scarb.toml | 2 -- docs/listings/deploy/Scarb.toml | 7 ++++--- docs/listings/get_nonce/Scarb.toml | 2 +- docs/listings/hello_workspaces/crates/addition/Scarb.toml | 4 ++-- docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/listings/basic_example/Scarb.toml b/docs/listings/basic_example/Scarb.toml index 0de0e3ff2b..f95a2f82ac 100644 --- a/docs/listings/basic_example/Scarb.toml +++ b/docs/listings/basic_example/Scarb.toml @@ -7,8 +7,6 @@ edition = "2024_07" [dependencies] starknet = "2.7.0" - -[dev-dependencies] snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } diff --git a/docs/listings/deploy/Scarb.toml b/docs/listings/deploy/Scarb.toml index 436061dac4..0a87b3ab07 100644 --- a/docs/listings/deploy/Scarb.toml +++ b/docs/listings/deploy/Scarb.toml @@ -4,11 +4,12 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknetstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } -sncast_stdstarknet = "2.7.0" +starknet = "2.7.0" sncast_std = { path = "../../../sncast_std" } +[dev-dependencies] +snforge_std = { path = "../../../snforge_std" } + [[target.lib]] sierra = true diff --git a/docs/listings/get_nonce/Scarb.toml b/docs/listings/get_nonce/Scarb.toml index 9101a6c268..3050533742 100644 --- a/docs/listings/get_nonce/Scarb.toml +++ b/docs/listings/get_nonce/Scarb.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2023_11" [dependencies] -starknetstarknet = "2.7.0" +starknet = "2.7.0" snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml index 38843cb8d1..e040464271 100644 --- a/docs/listings/hello_workspaces/crates/addition/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -6,10 +6,10 @@ edition = "2023_10" [dependencies] starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [dev-dependencies] -snforge_stdstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml index 0fbe2c960d..2fa2b47a01 100644 --- a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -15,10 +15,10 @@ sncast_std = { path = "../../../sncast_std" } [dependencies] addition = { path = "../addition" } starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [dev-dependencies] snforge_stdstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } [[target.starknet-contract]] sierra = true From 8424c57f3f828f1bfd99ce5d4741d277d89f3ed8 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 01:06:45 +0100 Subject: [PATCH 100/183] Fix manifests in `hello_workspaces` package --- docs/listings/hello_workspaces/Scarb.toml | 9 +++------ .../hello_workspaces/crates/addition/Scarb.toml | 6 ++---- .../hello_workspaces/crates/fibonacci/Scarb.toml | 12 ++++-------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/docs/listings/hello_workspaces/Scarb.toml b/docs/listings/hello_workspaces/Scarb.toml index 40081f42fe..8e47bbc6f5 100644 --- a/docs/listings/hello_workspaces/Scarb.toml +++ b/docs/listings/hello_workspaces/Scarb.toml @@ -13,17 +13,14 @@ version = "0.1.0" [package] name = "hello_workspaces" -versionstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +version.workspace = true edition = "2023_10" [scripts] -teststarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +test.workspace = true [tool] -snforgestarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +snforge.workspace = true [dependencies] fibonacci = { path = "crates/fibonacci" } diff --git a/docs/listings/hello_workspaces/crates/addition/Scarb.toml b/docs/listings/hello_workspaces/crates/addition/Scarb.toml index e040464271..d67f97584f 100644 --- a/docs/listings/hello_workspaces/crates/addition/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/addition/Scarb.toml @@ -1,15 +1,13 @@ [package] name = "addition" -versionstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +version.workspace = true edition = "2023_10" [dependencies] starknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } [dev-dependencies] -snforge_std = { path = "../../../snforge_std" } +snforge_std.workspace = true [[target.starknet-contract]] sierra = true diff --git a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml index 2fa2b47a01..45378edf34 100644 --- a/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml +++ b/docs/listings/hello_workspaces/crates/fibonacci/Scarb.toml @@ -1,24 +1,20 @@ [package] name = "fibonacci" -versionstarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +version.workspace = true edition = "2023_10" [scripts] -teststarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +test.workspace = true [tool] -snforgestarknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } +snforge.workspace = true [dependencies] addition = { path = "../addition" } starknet = "2.7.0" -sncast_std = { path = "../../../sncast_std" } [dev-dependencies] -snforge_stdstarknet = "2.7.0" +snforge_std.workspace = true [[target.starknet-contract]] sierra = true From 40461a2890dff6cec4155a15acb41986b4a03ec3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 01:33:32 +0100 Subject: [PATCH 101/183] Reorder capture groups --- crates/docs/src/validation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index d87eddc221..6620818b18 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -109,12 +109,12 @@ pub fn extract_snippets_from_file( .get_re() .captures_iter(&content) .filter_map(|caps| { - let command_match = caps.get(2)?; let match_start = caps.get(0)?.start(); - let output = caps.get(3).map(|m| m.as_str().to_string()); let config_str = caps .get(1) .map_or_else(String::new, |m| m.as_str().to_string()); + let command_match = caps.get(2)?; + let output = caps.get(3).map(|m| m.as_str().to_string()); let config = if config_str.is_empty() { SnippetConfig::default() From 5b3b26f12ca3b33a5e068022f3bd74a082483629 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 01:48:10 +0100 Subject: [PATCH 102/183] Add comment to `SnippetType.get_re()` --- crates/docs/src/validation.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 6620818b18..5b0116d7af 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -28,6 +28,18 @@ impl SnippetType { #[must_use] pub fn get_re(&self) -> Regex { + // The regex pattern is used to match the snippet, its config and the output. Example: + // + // ```shell + // $ + // ``` + //
+ // Output: + // ```shell + // + // ``` + //
+ let escaped_command = regex::escape(self.as_str()); let pattern = format!( r"(?ms)^(?:\n)?```shell\n\$ ({escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?" From 98217c18deaa60d22bd8a85856b96b47a2a07e4c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 02:01:00 +0100 Subject: [PATCH 103/183] Restructure `docs` crate --- crates/docs/src/lib.rs | 5 + crates/docs/src/snippet.rs | 102 ++++++++++++ crates/docs/src/utils.rs | 41 +++++ crates/docs/src/validation.rs | 147 +----------------- .../tests/e2e/docs_snippets_validation.rs | 7 +- .../sncast/tests/docs_snippets/validation.rs | 10 +- 6 files changed, 162 insertions(+), 150 deletions(-) create mode 100644 crates/docs/src/snippet.rs create mode 100644 crates/docs/src/utils.rs diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index 1506b851ef..684d3b527e 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -1,2 +1,7 @@ #[cfg(feature = "testing")] +pub mod snippet; +#[cfg(feature = "testing")] pub mod validation; + +#[cfg(feature = "testing")] +pub mod utils; diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs new file mode 100644 index 0000000000..9490ee1d83 --- /dev/null +++ b/crates/docs/src/snippet.rs @@ -0,0 +1,102 @@ +use regex::Regex; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug)] +pub struct SnippetType(String); + +impl SnippetType { + #[must_use] + pub fn forge() -> Self { + SnippetType("snforge".to_string()) + } + + #[must_use] + pub fn sncast() -> Self { + SnippetType("sncast".to_string()) + } + + #[must_use] + pub fn as_str(&self) -> &str { + &self.0 + } + + #[must_use] + pub fn get_re(&self) -> Regex { + // The regex pattern is used to match the snippet, its config and the output. Example: + // + // ```shell + // $ + // ``` + //
+ // Output: + // ```shell + // + // ``` + //
+ + let escaped_command = regex::escape(self.as_str()); + let pattern = format!( + r"(?ms)^(?:\n)?```shell\n\$ ({escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?" + ); + + Regex::new(&pattern).unwrap() + } +} + +#[derive(Debug, Deserialize, Serialize, Default)] +pub struct SnippetConfig { + pub ignored: Option, + pub package_name: Option, +} + +impl SnippetConfig { + pub fn from_json(json_str: &str) -> Result { + serde_json::from_str(json_str) + } + + fn default() -> Self { + SnippetConfig { + ignored: None, + package_name: None, + } + } +} + +#[derive(Debug)] +pub struct Snippet { + pub command: String, + pub output: Option, + pub file_path: String, + pub line_start: usize, + pub snippet_type: SnippetType, + pub config: SnippetConfig, +} + +impl Snippet { + pub fn to_command_args(&self) -> Vec { + let cleaned_command = self + .command + .lines() + .map(str::trim_end) + .collect::>() + .join(" ") + .replace(" \\", ""); + + shell_words::split(&cleaned_command) + .expect("Failed to parse snippet string") + .into_iter() + .map(|arg| arg.trim().to_string()) + .collect() + } + + #[must_use] + pub fn capture_package_from_output(&self) -> Option { + let re = + Regex::new(r"Collected \d+ test\(s\) from ([a-zA-Z_][a-zA-Z0-9_]*) package").unwrap(); + + re.captures_iter(self.output.as_ref()?) + .filter_map(|caps| caps.get(1)) + .last() + .map(|m| m.as_str().to_string()) + } +} diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs new file mode 100644 index 0000000000..81b46f019e --- /dev/null +++ b/crates/docs/src/utils.rs @@ -0,0 +1,41 @@ +use std::{env, path::PathBuf}; + +use crate::snippet::Snippet; + +#[must_use] +pub fn get_parent_dir(levels_up: usize) -> PathBuf { + let mut dir = env::current_dir().expect("Failed to get the current directory"); + + for _ in 0..levels_up { + dir = dir + .parent() + .expect("Failed to navigate to parent directory") + .to_owned(); + } + + dir +} + +pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &str) { + assert!( + condition, + "Found invalid {} snippet in the docs at {}:{}:1\n{}", + snippet.snippet_type.as_str(), + snippet.file_path, + snippet.line_start, + err_message + ); +} + +pub fn print_success_message(snippets_len: usize, tool_name: &str) { + println!("Successfully validated {snippets_len} {tool_name} docs snippets"); +} + +pub fn print_skipped_snippet_message(snippet: &Snippet) { + println!( + "Skipped validation of {} snippet in the docs in file: {} at line {}", + snippet.snippet_type.as_str(), + snippet.file_path, + snippet.line_start, + ); +} diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 5b0116d7af..8ae47da1c3 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -1,111 +1,8 @@ -use regex::Regex; -use serde::{Deserialize, Serialize}; -use std::{ - env, fs, io, - path::{Path, PathBuf}, -}; +use std::{fs, io, path::Path}; -const EXTENSION: Option<&str> = Some("md"); - -#[derive(Clone, Debug)] -pub struct SnippetType(String); - -impl SnippetType { - #[must_use] - pub fn forge() -> Self { - SnippetType("snforge".to_string()) - } - - #[must_use] - pub fn sncast() -> Self { - SnippetType("sncast".to_string()) - } - - #[must_use] - pub fn as_str(&self) -> &str { - &self.0 - } - - #[must_use] - pub fn get_re(&self) -> Regex { - // The regex pattern is used to match the snippet, its config and the output. Example: - // - // ```shell - // $ - // ``` - //
- // Output: - // ```shell - // - // ``` - //
- - let escaped_command = regex::escape(self.as_str()); - let pattern = format!( - r"(?ms)^(?:\n)?```shell\n\$ ({escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?" - ); - - Regex::new(&pattern).unwrap() - } -} - -#[derive(Debug, Deserialize, Serialize, Default)] -pub struct SnippetConfig { - pub ignored: Option, - pub package_name: Option, -} - -impl SnippetConfig { - pub fn from_json(json_str: &str) -> Result { - serde_json::from_str(json_str) - } - - fn default() -> Self { - SnippetConfig { - ignored: None, - package_name: None, - } - } -} +use crate::snippet::{Snippet, SnippetConfig, SnippetType}; -#[derive(Debug)] -pub struct Snippet { - pub command: String, - pub output: Option, - pub file_path: String, - pub line_start: usize, - pub snippet_type: SnippetType, - pub config: SnippetConfig, -} - -impl Snippet { - pub fn to_command_args(&self) -> Vec { - let cleaned_command = self - .command - .lines() - .map(str::trim_end) - .collect::>() - .join(" ") - .replace(" \\", ""); - - shell_words::split(&cleaned_command) - .expect("Failed to parse snippet string") - .into_iter() - .map(|arg| arg.trim().to_string()) - .collect() - } - - #[must_use] - pub fn capture_package_from_output(&self) -> Option { - let re = - Regex::new(r"Collected \d+ test\(s\) from ([a-zA-Z_][a-zA-Z0-9_]*) package").unwrap(); - - re.captures_iter(self.output.as_ref()?) - .filter_map(|caps| caps.get(1)) - .last() - .map(|m| m.as_str().to_string()) - } -} +const EXTENSION: Option<&str> = Some("md"); pub fn extract_snippets_from_file( file_path: &Path, @@ -172,41 +69,3 @@ pub fn extract_snippets_from_directory( Ok(all_snippets) } - -#[must_use] -pub fn get_parent_dir(levels_up: usize) -> PathBuf { - let mut dir = env::current_dir().expect("Failed to get the current directory"); - - for _ in 0..levels_up { - dir = dir - .parent() - .expect("Failed to navigate to parent directory") - .to_owned(); - } - - dir -} - -pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &str) { - assert!( - condition, - "Found invalid {} snippet in the docs at {}:{}:1\n{}", - snippet.snippet_type.as_str(), - snippet.file_path, - snippet.line_start, - err_message - ); -} - -pub fn print_success_message(snippets_len: usize, tool_name: &str) { - println!("Successfully validated {snippets_len} {tool_name} docs snippets"); -} - -pub fn print_skipped_snippet_message(snippet: &Snippet) { - println!( - "Skipped validation of {} snippet in the docs in file: {} at line {}", - snippet.snippet_type.as_str(), - snippet.file_path, - snippet.line_start, - ); -} diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a5fdfdc03c..f4061141b8 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,8 +1,9 @@ use clap::Parser; -use docs::validation::{ - assert_valid_snippet, extract_snippets_from_directory, get_parent_dir, - print_skipped_snippet_message, print_success_message, SnippetType, +use docs::snippet::SnippetType; +use docs::utils::{ + assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, }; +use docs::validation::extract_snippets_from_directory; use forge::Cli; use shared::test_utils::output_assert::assert_stdout_contains; diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 9c5444db56..4d6d5f1cd5 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,7 +1,11 @@ -use docs::validation::{ - assert_valid_snippet, extract_snippets_from_directory, extract_snippets_from_file, - get_parent_dir, print_skipped_snippet_message, print_success_message, Snippet, SnippetType, +use std::fs; + +use configuration::CONFIG_FILENAME; +use docs::snippet::{Snippet, SnippetType}; +use docs::utils::{ + assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, }; +use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; use tempfile::tempdir; use crate::helpers::runner::runner; From b0a1130ab318b779178ee0c3350635895e684023 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 02:02:43 +0100 Subject: [PATCH 104/183] Remove default `SnippetConfig` --- crates/docs/src/snippet.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 9490ee1d83..100627e3ae 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -53,13 +53,6 @@ impl SnippetConfig { pub fn from_json(json_str: &str) -> Result { serde_json::from_str(json_str) } - - fn default() -> Self { - SnippetConfig { - ignored: None, - package_name: None, - } - } } #[derive(Debug)] From ce93644b3266520cfcacbed9bac5bdb1f7da3b70 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 02:06:31 +0100 Subject: [PATCH 105/183] Remove unneeded import --- crates/sncast/tests/docs_snippets/validation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 4d6d5f1cd5..5cfec9069f 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,5 @@ use std::fs; -use configuration::CONFIG_FILENAME; use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, From 30a8ca5ff08e1c372a308ccf6ecd80771d3fc2f1 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 02:09:48 +0100 Subject: [PATCH 106/183] Remove unused import --- crates/sncast/tests/docs_snippets/validation.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 5cfec9069f..67b8d263b3 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,5 +1,3 @@ -use std::fs; - use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, From b9ab20a2f1eaa8bf8bd05f4888f8617378c40cee Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 10:53:10 +0100 Subject: [PATCH 107/183] Fix docs snippets test for `--exit-first` flag --- docs/src/testing/running-tests.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index 15d2dde9c1..c99d38a7a8 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -92,12 +92,11 @@ Running 3 test(s) from tests/ Failure data: 0x6661696c696e6720636865636b ('failing check') -[PASS] failing_example_tests::test_abc (gas: ~1) -[PASS] failing_example_tests::test_xyz (gas: ~1) -Tests: 2 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out Failures: failing_example_tests::test_failing + +Tests: 0 passed, 1 failed, 2 skipped, 0 ignored, 0 filtered out ```

From 815e1fcc299c87bee8fd74f006c5c1e038f62218 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 13:52:44 +0100 Subject: [PATCH 108/183] Update docs --- docs/src/testing/running-tests.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index c99d38a7a8..f638b61839 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -26,8 +26,6 @@ Tests: 3 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out You can pass a filter string after the `snforge test` command to filter tests. By default, any test with an [absolute module tree path](https://book.cairo-lang.org/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree) matching the filter will be run. -You're tests may differ, note that we changed the default tests generated by `snforge init` for 3 custom tests: `calling`, `calling_another`, and `executing` just for the sake of this example. - ```shell $ snforge test calling ``` From 7517ddb22e93c59dc162921a6990955125f3d726 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 14:08:31 +0100 Subject: [PATCH 109/183] Update docs --- docs/listings/panicking_test/src/lib.cairo | 6 ------ docs/src/testing/testing.md | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/listings/panicking_test/src/lib.cairo b/docs/listings/panicking_test/src/lib.cairo index b105f93712..eea1bbbdfe 100644 --- a/docs/listings/panicking_test/src/lib.cairo +++ b/docs/listings/panicking_test/src/lib.cairo @@ -1,4 +1,3 @@ -//ANCHOR:first_half fn panicking_function() { let mut data = array![]; data.append('panic message'); @@ -10,13 +9,8 @@ mod tests { use super::panicking_function; #[test] - //ANCHOR_END:first_half - //ANCHOR:second_half fn failing() { panicking_function(); assert(2 == 2, '2 == 2'); } } -//ANCHOR_END:second_half - - diff --git a/docs/src/testing/testing.md b/docs/src/testing/testing.md index 957d3a06e3..18d93484a0 100644 --- a/docs/src/testing/testing.md +++ b/docs/src/testing/testing.md @@ -39,8 +39,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, 0 filtered out If your code panics, the test is considered failed. Here's an example of a failing test. ```rust -{{#include ../../listings/panicking_test/src/lib.cairo:first_half}} -{{#include ../../listings/panicking_test/src/lib.cairo:second_half}} +{{#include ../../listings/panicking_test/src/lib.cairo}} ``` ```shell From d434dbe2adc72fa209f4999622fbe15bf361e2b4 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:07:30 +0100 Subject: [PATCH 110/183] Update `SnippetType.get_re()` description --- crates/docs/src/snippet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 100627e3ae..dda1d902e4 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -25,12 +25,12 @@ impl SnippetType { // The regex pattern is used to match the snippet, its config and the output. Example: // // ```shell - // $ + // $ snforge or sncast command with args... // ``` //
// Output: // ```shell - // + // Output of the command... // ``` //
From 7bc535a5f1f3b90c31f9930415ed00b51a500827 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:34:09 +0100 Subject: [PATCH 111/183] Change `scarb check` to `scarb test` in verification script --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 89a0d7aa97..6f5f4245c3 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb check); done +for d in ./docs/listings/*; do (cd "$d" && scarb test); done From ebd68fc15198e92c7c97335bb89c000d94e47fd0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:45:32 +0100 Subject: [PATCH 112/183] Fix building mdbook --- docs/src/appendix/sncast-library/call.md | 2 +- docs/src/appendix/sncast-library/declare.md | 2 +- docs/src/appendix/sncast-library/deploy.md | 2 +- docs/src/appendix/sncast-library/get_nonce.md | 2 +- docs/src/appendix/sncast-library/invoke.md | 2 +- docs/src/appendix/sncast-library/tx_status.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/src/appendix/sncast-library/call.md b/docs/src/appendix/sncast-library/call.md index f943e458da..3e76894fe3 100644 --- a/docs/src/appendix/sncast-library/call.md +++ b/docs/src/appendix/sncast-library/call.md @@ -11,7 +11,7 @@ Calls a contract and returns `CallResult`. - `calldata` - inputs to the function to be called. ```rust -{{#include ../../../listings/sncast_library/scripts/call/src/lib.cairo}} +{{#include ../../../listings/call/src/lib.cairo}} ``` Structure used by the command: diff --git a/docs/src/appendix/sncast-library/declare.md b/docs/src/appendix/sncast-library/declare.md index 8165a69b2d..f75510507d 100644 --- a/docs/src/appendix/sncast-library/declare.md +++ b/docs/src/appendix/sncast-library/declare.md @@ -9,7 +9,7 @@ Declares a contract and returns `DeclareResult`. - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust -{{#include ../../../listings/sncast_library/scripts/declare/src/lib.cairo}} +{{#include ../../../listings/declare/src/lib.cairo}} ``` ## Returned Type diff --git a/docs/src/appendix/sncast-library/deploy.md b/docs/src/appendix/sncast-library/deploy.md index 326d7de9fd..e503218118 100644 --- a/docs/src/appendix/sncast-library/deploy.md +++ b/docs/src/appendix/sncast-library/deploy.md @@ -46,5 +46,5 @@ pub struct StrkFeeSettings { - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust -{{#include ../../../listings/sncast_library/scripts/deploy/src/lib.cairo}} +{{#include ../../../listings/deploy/src/lib.cairo}} ``` diff --git a/docs/src/appendix/sncast-library/get_nonce.md b/docs/src/appendix/sncast-library/get_nonce.md index 3261250bca..2ad4b84559 100644 --- a/docs/src/appendix/sncast-library/get_nonce.md +++ b/docs/src/appendix/sncast-library/get_nonce.md @@ -7,5 +7,5 @@ Gets nonce of an account for a given block tag (`pending` or `latest`) and retur - `block_tag` - block tag name, one of `pending` or `latest`. ```rust -{{#include ../../../listings/sncast_library/scripts/get_nonce/src/lib.cairo}} +{{#include ../../../listings/get_nonce/src/lib.cairo}} ``` diff --git a/docs/src/appendix/sncast-library/invoke.md b/docs/src/appendix/sncast-library/invoke.md index 8cd5c0a121..db964a11a0 100644 --- a/docs/src/appendix/sncast-library/invoke.md +++ b/docs/src/appendix/sncast-library/invoke.md @@ -17,7 +17,7 @@ Invokes a contract and returns `InvokeResult`. - `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically. ```rust -{{#include ../../../listings/sncast_library/scripts/invoke/src/lib.cairo}} +{{#include ../../../listings/invoke/src/lib.cairo}} ``` Structures used by the command: diff --git a/docs/src/appendix/sncast-library/tx_status.md b/docs/src/appendix/sncast-library/tx_status.md index f00842679b..83536455b1 100644 --- a/docs/src/appendix/sncast-library/tx_status.md +++ b/docs/src/appendix/sncast-library/tx_status.md @@ -7,7 +7,7 @@ Gets the status of a transaction using its hash and returns `TxStatusResult`. - `transaction_hash` - hash of the transaction ```rust -{{#include ../../../listings/sncast_library/scripts/tx_status/src/lib.cairo}} +{{#include ../../../listings/tx_status/src/lib.cairo}} ``` Structures used by the command: From ebdc770e7c954b9be632dbbfd2854386f73b2b9c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:50:13 +0100 Subject: [PATCH 113/183] Use `runner` instead of `test_runner` --- crates/forge/tests/e2e/docs_snippets_validation.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index f4061141b8..4727927cf0 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -7,7 +7,7 @@ use docs::validation::extract_snippets_from_directory; use forge::Cli; use shared::test_utils::output_assert::assert_stdout_contains; -use super::common::runner::{setup_package, test_runner}; +use super::common::runner::{runner, setup_package}; #[test] fn test_docs_snippets() { @@ -40,9 +40,6 @@ fn test_docs_snippets() { // Remove "snforge" from the args args.remove(0); - // Remove "test" from the args - args.retain(|element| element != &"test"); - if let Some(snippet_output) = &snippet.output { let package_name = snippet .config @@ -52,7 +49,7 @@ fn test_docs_snippets() { .expect("Cannot find package name in command output or snippet config"); let temp = setup_package(&package_name); - let output = test_runner(&temp).args(args).assert(); + let output = runner(&temp).args(args).assert(); assert_stdout_contains(output, snippet_output); } From c12935be60f7cff677dc5b8b358141f582ee8f53 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:51:54 +0100 Subject: [PATCH 114/183] Inline `is_package_from_docs_listings` --- crates/forge/tests/e2e/common/runner.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index b001ee7916..940403d3ef 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -33,20 +33,16 @@ pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand { pub(crate) static BASE_FILE_PATTERNS: &[&str] = &["**/*.cairo", "**/*.toml"]; -fn is_package_from_docs_listings(package: &str) -> bool { - fs::read_dir("../../docs/listings") - .unwrap() - .map(|entry| entry.unwrap().file_name().into_string().unwrap()) - .any(|entry| entry == package) -} - pub(crate) fn setup_package_with_file_patterns( package_name: &str, file_patterns: &[&str], ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - let is_from_docs_listings = is_package_from_docs_listings(package_name); + let is_from_docs_listings = fs::read_dir("../../docs/listings") + .unwrap() + .map(|entry| entry.unwrap().file_name().into_string().unwrap()) + .any(|entry| entry == package_name); let package_path = if is_from_docs_listings { format!("../../docs/listings/{package_name}",) From cb0fe80b2493bed19ef96e527cf53fb2c8790fe9 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:55:13 +0100 Subject: [PATCH 115/183] Rename `get_parent_dir` to `get_nth_ancestor` --- crates/docs/src/utils.rs | 2 +- crates/forge/tests/e2e/docs_snippets_validation.rs | 4 ++-- crates/sncast/tests/docs_snippets/validation.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 81b46f019e..9b5b3bcfaa 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -3,7 +3,7 @@ use std::{env, path::PathBuf}; use crate::snippet::Snippet; #[must_use] -pub fn get_parent_dir(levels_up: usize) -> PathBuf { +pub fn get_nth_ancestor(levels_up: usize) -> PathBuf { let mut dir = env::current_dir().expect("Failed to get the current directory"); for _ in 0..levels_up { diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 4727927cf0..a385d1c06a 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,7 +1,7 @@ use clap::Parser; use docs::snippet::SnippetType; use docs::utils::{ - assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, + assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, }; use docs::validation::extract_snippets_from_directory; use forge::Cli; @@ -11,7 +11,7 @@ use super::common::runner::{runner, setup_package}; #[test] fn test_docs_snippets() { - let root_dir = get_parent_dir(2); + let root_dir = get_nth_ancestor(2); let docs_dir = root_dir.join("docs/src"); let snippet_type = SnippetType::forge(); diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 67b8d263b3..362cd07e7e 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,6 @@ use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ - assert_valid_snippet, get_parent_dir, print_skipped_snippet_message, print_success_message, + assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, }; use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; use tempfile::tempdir; @@ -11,7 +11,7 @@ use crate::helpers::runner::runner; fn test_docs_snippets() { let tempdir = tempdir().expect("Unable to create a temporary directory"); - let root_dir_path = get_parent_dir(2); + let root_dir_path = get_nth_ancestor(2); let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); From 3f9adf1951bc54494fe1aedd6c9f101c3d1ab321 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 16:57:14 +0100 Subject: [PATCH 116/183] Remove `SnippetConfig::from_json` --- crates/docs/src/snippet.rs | 6 ------ crates/docs/src/validation.rs | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index dda1d902e4..82fef1e0d0 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -49,12 +49,6 @@ pub struct SnippetConfig { pub package_name: Option, } -impl SnippetConfig { - pub fn from_json(json_str: &str) -> Result { - serde_json::from_str(json_str) - } -} - #[derive(Debug)] pub struct Snippet { pub command: String, diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 8ae47da1c3..848e4861ae 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -28,7 +28,7 @@ pub fn extract_snippets_from_file( let config = if config_str.is_empty() { SnippetConfig::default() } else { - SnippetConfig::from_json(&config_str).expect("Failed to parse snippet config") + serde_json::from_str(&config_str).expect("Failed to parse snippet config") }; Some(Snippet { From 800fcfd8c64e88f804ce0f2052c5b8bd6268713a Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:04:57 +0100 Subject: [PATCH 117/183] Use `trim` in `Snippet.to_command_args` --- crates/docs/src/snippet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 82fef1e0d0..7e63eff1e0 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -64,7 +64,7 @@ impl Snippet { let cleaned_command = self .command .lines() - .map(str::trim_end) + .map(str::trim) .collect::>() .join(" ") .replace(" \\", ""); From 75360e0a0eced938b3c79819c6e0c01f08166953 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:25:49 +0100 Subject: [PATCH 118/183] Used named captures in regex --- crates/docs/src/snippet.rs | 2 +- crates/docs/src/validation.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 7e63eff1e0..c7caefc258 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -36,7 +36,7 @@ impl SnippetType { let escaped_command = regex::escape(self.as_str()); let pattern = format!( - r"(?ms)^(?:\n)?```shell\n\$ ({escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n([\s\S]+?)\n```[\s]*<\/details>)?" + r"(?ms)^(?:\n)?```shell\n\$ (?P{escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?" ); Regex::new(&pattern).unwrap() diff --git a/crates/docs/src/validation.rs b/crates/docs/src/validation.rs index 848e4861ae..70605570a6 100644 --- a/crates/docs/src/validation.rs +++ b/crates/docs/src/validation.rs @@ -20,10 +20,10 @@ pub fn extract_snippets_from_file( .filter_map(|caps| { let match_start = caps.get(0)?.start(); let config_str = caps - .get(1) + .name("config") .map_or_else(String::new, |m| m.as_str().to_string()); - let command_match = caps.get(2)?; - let output = caps.get(3).map(|m| m.as_str().to_string()); + let command_match = caps.name("command")?; + let output = caps.name("output").map(|m| m.as_str().to_string()); let config = if config_str.is_empty() { SnippetConfig::default() From d9f11bf26f3ef0836cbca1749c102c2d94ec3529 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:37:00 +0100 Subject: [PATCH 119/183] Refactor `setup_package_with_file_patterns` --- crates/forge/tests/e2e/common/runner.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 940403d3ef..49a4293d95 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -39,15 +39,19 @@ pub(crate) fn setup_package_with_file_patterns( ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - let is_from_docs_listings = fs::read_dir("../../docs/listings") - .unwrap() - .map(|entry| entry.unwrap().file_name().into_string().unwrap()) - .any(|entry| entry == package_name); + let listings_path = fs::canonicalize("../../docs/listings") + .expect("Failed to canonicalize the 'docs/listings' path"); + + let package_full_path = PathBuf::from("../../docs/listings").join(package_name); + let canonical_package_path = fs::canonicalize(&package_full_path) + .unwrap_or_else(|_| panic!("Failed to canonicalize the path for package: {package_name}")); + + let is_from_docs_listings = canonical_package_path.starts_with(&listings_path); let package_path = if is_from_docs_listings { - format!("../../docs/listings/{package_name}",) + format!("{}/{}", listings_path.display(), package_name) } else { - format!("tests/data/{package_name}",) + format!("tests/data/{package_name}") }; let package_path = Utf8PathBuf::from_str(&package_path) From a92325fbac952dc0e8977868c9326a9c9c2c7ac1 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:38:56 +0100 Subject: [PATCH 120/183] Remove `trim` from `Snippet.to_command_args` --- crates/docs/src/snippet.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index c7caefc258..a744e31776 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -64,7 +64,6 @@ impl Snippet { let cleaned_command = self .command .lines() - .map(str::trim) .collect::>() .join(" ") .replace(" \\", ""); From 451bb67bb0afdb2ae80f2d7444e83b14bfa0dab3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:43:55 +0100 Subject: [PATCH 121/183] Revert "Refactor `setup_package_with_file_patterns`" This reverts commit d9f11bf26f3ef0836cbca1749c102c2d94ec3529. --- crates/forge/tests/e2e/common/runner.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 49a4293d95..940403d3ef 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -39,19 +39,15 @@ pub(crate) fn setup_package_with_file_patterns( ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - let listings_path = fs::canonicalize("../../docs/listings") - .expect("Failed to canonicalize the 'docs/listings' path"); - - let package_full_path = PathBuf::from("../../docs/listings").join(package_name); - let canonical_package_path = fs::canonicalize(&package_full_path) - .unwrap_or_else(|_| panic!("Failed to canonicalize the path for package: {package_name}")); - - let is_from_docs_listings = canonical_package_path.starts_with(&listings_path); + let is_from_docs_listings = fs::read_dir("../../docs/listings") + .unwrap() + .map(|entry| entry.unwrap().file_name().into_string().unwrap()) + .any(|entry| entry == package_name); let package_path = if is_from_docs_listings { - format!("{}/{}", listings_path.display(), package_name) + format!("../../docs/listings/{package_name}",) } else { - format!("tests/data/{package_name}") + format!("tests/data/{package_name}",) }; let package_path = Utf8PathBuf::from_str(&package_path) From 4692dfd799e22ace3732e44a0ffaae5669e9ca33 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 25 Nov 2024 17:46:45 +0100 Subject: [PATCH 122/183] Fix linting --- crates/docs/src/snippet.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index a744e31776..2b03f74534 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -60,6 +60,7 @@ pub struct Snippet { } impl Snippet { + #[must_use] pub fn to_command_args(&self) -> Vec { let cleaned_command = self .command From 9b58f516bae5826938398904bcf55a06c25664ac Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 12:46:51 +0100 Subject: [PATCH 123/183] Ingore snforge snippet with `--exit-first` flag --- docs/src/testing/running-tests.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/testing/running-tests.md b/docs/src/testing/running-tests.md index f638b61839..0138f8f88a 100644 --- a/docs/src/testing/running-tests.md +++ b/docs/src/testing/running-tests.md @@ -75,6 +75,7 @@ Tests: 1 passed, 0 failed, 0 skipped, 0 ignored, other filtered out To stop the test execution after first failed test, you can pass an `--exit-first` flag along with `snforge test` command. + ```shell $ snforge test --exit-first ``` From 8ed2e929f72f9ce978ed5c39e68327217c7d3d91 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 13:34:10 +0100 Subject: [PATCH 124/183] Fix failing cast `test_docs_snippets` --- docs/src/starknet/invoke.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 370e4ef1e3..10bd551526 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -24,9 +24,9 @@ $ sncast \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "add" \ --fee-token eth \ - --arguments 'pokemons::model::PokemonData {'\ + --arguments 'pokemons::model::PokemonData {'\ 'name: "Magmar",'\ -'element: pokemons::model::Element::Fire'\ +'element: pokemons::model::Element::Fire'\ '}' ``` From 624277ceea676e818a017d620dd843fc0c392617 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 14:52:17 +0100 Subject: [PATCH 125/183] Fix docs snippets test for backtrace --- docs/src/snforge-advanced-features/backtrace.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/src/snforge-advanced-features/backtrace.md b/docs/src/snforge-advanced-features/backtrace.md index 4819dbc227..6075567d94 100644 --- a/docs/src/snforge-advanced-features/backtrace.md +++ b/docs/src/snforge-advanced-features/backtrace.md @@ -34,7 +34,7 @@ this: - + ```shell $ snforge test ``` @@ -55,7 +55,9 @@ To enable backtraces, simply set the `SNFORGE_BACKTRACE=1` environment variable When enabled, the backtrace will display the call tree of the execution, including the specific line numbers in the contracts where the errors occurred. Here's an example of what you might see: - + + + ```shell $ SNFORGE_BACKTRACE=1 snforge test ``` From d85ae00965b87f8228c1269e62f067864245c947 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 15:43:37 +0100 Subject: [PATCH 126/183] Update manigest for `basic_example` package --- docs/listings/basic_example/Scarb.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/listings/basic_example/Scarb.toml b/docs/listings/basic_example/Scarb.toml index f95a2f82ac..c637765bb1 100644 --- a/docs/listings/basic_example/Scarb.toml +++ b/docs/listings/basic_example/Scarb.toml @@ -10,9 +10,6 @@ starknet = "2.7.0" snforge_std = { path = "../../../snforge_std" } sncast_std = { path = "../../../sncast_std" } -[[target.starknet-contract]] -sncast_std = { path = "../../../sncast_std" } - [[target.lib]] sierra = true From c375d4496143492f0b85d08f790e3d875e4b120d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 17:20:11 +0100 Subject: [PATCH 127/183] Add missing `snforge_std` --- docs/listings/call/Scarb.toml | 1 + docs/listings/declare/Scarb.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/listings/call/Scarb.toml b/docs/listings/call/Scarb.toml index 0b98573547..d3a1355702 100644 --- a/docs/listings/call/Scarb.toml +++ b/docs/listings/call/Scarb.toml @@ -6,6 +6,7 @@ edition = "2023_11" [dependencies] starknet = "2.7.0" sncast_std = { path = "../../../sncast_std" } +snforge_std = { path = "../../../snforge_std" } [[target.lib]] sierra = true diff --git a/docs/listings/declare/Scarb.toml b/docs/listings/declare/Scarb.toml index 171e0e23b4..caba58eb23 100644 --- a/docs/listings/declare/Scarb.toml +++ b/docs/listings/declare/Scarb.toml @@ -6,6 +6,7 @@ edition = "2023_11" [dependencies] starknet = "2.7.0" sncast_std = { path = "../../../sncast_std" } +snforge_std = { path = "../../../snforge_std" } [[target.starknet-contract]] sierra = true From fbb63588abaabd28c6fa892b20c330e273edad93 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 17:22:11 +0100 Subject: [PATCH 128/183] Use `scarb check` instead of `scarb test` --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 6f5f4245c3..89a0d7aa97 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb test); done +for d in ./docs/listings/*; do (cd "$d" && scarb check); done From 5cf8560ee70799d02aa87980ce1c488521ca0349 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 17:53:55 +0100 Subject: [PATCH 129/183] Fix CI --- scripts/verify_cairo_listings.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 89a0d7aa97..58a4b3ec4d 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,8 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb check); done +# TODO: ATM there is a bug in Scarb - .so library isn't getting build, so we need to build it manually +# Should be removed once the bug is fixed +cargo build --release --manifest-path ./crates/snforge-scarb-plugin/Cargo.toml + +for d in ./docs/listings/*; do (cd "$d" && scarb test); done From 8cd610deac576f158d8c8fdd97857c3af2c51206 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 18:15:33 +0100 Subject: [PATCH 130/183] Use `scarb check` instead of `scarb test` --- scripts/verify_cairo_listings.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 58a4b3ec4d..f5234b4920 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,8 +1,8 @@ #!/bin/bash set -e -# TODO: ATM there is a bug in Scarb - .so library isn't getting build, so we need to build it manually +# TODO(#): ATM there is a bug in Scarb - .so library isn't getting build, so we need to build it manually # Should be removed once the bug is fixed cargo build --release --manifest-path ./crates/snforge-scarb-plugin/Cargo.toml -for d in ./docs/listings/*; do (cd "$d" && scarb test); done +for d in ./docs/listings/*; do (cd "$d" && scarb check); done From 5fa2ee9962dbd01077ce70b799531cac5158c41d Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 18:22:23 +0100 Subject: [PATCH 131/183] Update todo --- scripts/verify_cairo_listings.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index f5234b4920..d9a019dff2 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,8 +1,7 @@ #!/bin/bash set -e -# TODO(#): ATM there is a bug in Scarb - .so library isn't getting build, so we need to build it manually -# Should be removed once the bug is fixed +# TODO(#2718) cargo build --release --manifest-path ./crates/snforge-scarb-plugin/Cargo.toml for d in ./docs/listings/*; do (cd "$d" && scarb check); done From 8217109b14fc050c4f9110f81a85d39b6269e4cc Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 18:41:16 +0100 Subject: [PATCH 132/183] Update cairlo listings verification script --- scripts/verify_cairo_listings.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index ef99cacb05..c8769d7bfa 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -2,6 +2,4 @@ set -xe # TODO(#2718) -cargo build --release --manifest-path ./crates/snforge-scarb-plugin/Cargo.toml - for d in ./docs/listings/*; do (cd "$d" && scarb check); done From a1314de1ced7ee1ad3bae6c73fb9894bdbcd2d9b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 18:52:27 +0100 Subject: [PATCH 133/183] Use `scarb build` instead of `scarb test` --- scripts/verify_cairo_listings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_cairo_listings.sh b/scripts/verify_cairo_listings.sh index 6f5f4245c3..197a775d76 100755 --- a/scripts/verify_cairo_listings.sh +++ b/scripts/verify_cairo_listings.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -for d in ./docs/listings/*; do (cd "$d" && scarb test); done +for d in ./docs/listings/*; do (cd "$d" && scarb build); done From 879b52fb3e332d02d9a74663052f66a05f91aae5 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 26 Nov 2024 19:21:23 +0100 Subject: [PATCH 134/183] Remove inlining of `is_package_from_docs_listings` --- crates/forge/tests/e2e/common/runner.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index 940403d3ef..b001ee7916 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -33,16 +33,20 @@ pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand { pub(crate) static BASE_FILE_PATTERNS: &[&str] = &["**/*.cairo", "**/*.toml"]; +fn is_package_from_docs_listings(package: &str) -> bool { + fs::read_dir("../../docs/listings") + .unwrap() + .map(|entry| entry.unwrap().file_name().into_string().unwrap()) + .any(|entry| entry == package) +} + pub(crate) fn setup_package_with_file_patterns( package_name: &str, file_patterns: &[&str], ) -> TempDir { let temp = tempdir_with_tool_versions().unwrap(); - let is_from_docs_listings = fs::read_dir("../../docs/listings") - .unwrap() - .map(|entry| entry.unwrap().file_name().into_string().unwrap()) - .any(|entry| entry == package_name); + let is_from_docs_listings = is_package_from_docs_listings(package_name); let package_path = if is_from_docs_listings { format!("../../docs/listings/{package_name}",) From 5e8bb023e67328e3ae5c56376f3090c4deec70c8 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 27 Nov 2024 09:14:29 +0100 Subject: [PATCH 135/183] Refactor `is_package_from_docs_listings` --- crates/forge/tests/e2e/common/runner.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/forge/tests/e2e/common/runner.rs b/crates/forge/tests/e2e/common/runner.rs index b001ee7916..bc248916b1 100644 --- a/crates/forge/tests/e2e/common/runner.rs +++ b/crates/forge/tests/e2e/common/runner.rs @@ -34,10 +34,8 @@ pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand { pub(crate) static BASE_FILE_PATTERNS: &[&str] = &["**/*.cairo", "**/*.toml"]; fn is_package_from_docs_listings(package: &str) -> bool { - fs::read_dir("../../docs/listings") - .unwrap() - .map(|entry| entry.unwrap().file_name().into_string().unwrap()) - .any(|entry| entry == package) + let package_path = Path::new("../../docs/listings").join(package); + fs::canonicalize(&package_path).is_ok() } pub(crate) fn setup_package_with_file_patterns( From f6e407c2e1bab64f4e32b8c835e69370057c818e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 27 Nov 2024 10:30:36 +0100 Subject: [PATCH 136/183] Remove unneeded `.gitignore` files --- docs/listings/detailed_resources_example/.gitignore | 2 -- docs/listings/failing_example/.gitignore | 2 -- docs/listings/hello_snforge/.gitignore | 2 -- docs/listings/hello_starknet/.gitignore | 2 -- 4 files changed, 8 deletions(-) delete mode 100644 docs/listings/detailed_resources_example/.gitignore delete mode 100644 docs/listings/failing_example/.gitignore delete mode 100644 docs/listings/hello_snforge/.gitignore delete mode 100644 docs/listings/hello_starknet/.gitignore diff --git a/docs/listings/detailed_resources_example/.gitignore b/docs/listings/detailed_resources_example/.gitignore deleted file mode 100644 index 73aa31e608..0000000000 --- a/docs/listings/detailed_resources_example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.snfoundry_cache/ diff --git a/docs/listings/failing_example/.gitignore b/docs/listings/failing_example/.gitignore deleted file mode 100644 index 73aa31e608..0000000000 --- a/docs/listings/failing_example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.snfoundry_cache/ diff --git a/docs/listings/hello_snforge/.gitignore b/docs/listings/hello_snforge/.gitignore deleted file mode 100644 index 73aa31e608..0000000000 --- a/docs/listings/hello_snforge/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.snfoundry_cache/ diff --git a/docs/listings/hello_starknet/.gitignore b/docs/listings/hello_starknet/.gitignore deleted file mode 100644 index 73aa31e608..0000000000 --- a/docs/listings/hello_starknet/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.snfoundry_cache/ From 15e8ed36a5229b9b8a6fb9040a55abda09170c95 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 28 Nov 2024 12:37:17 +0100 Subject: [PATCH 137/183] Fix embed path --- docs/src/snforge-advanced-features/storage-cheatcodes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/snforge-advanced-features/storage-cheatcodes.md b/docs/src/snforge-advanced-features/storage-cheatcodes.md index d82a2d9e41..a18ceb02a0 100644 --- a/docs/src/snforge-advanced-features/storage-cheatcodes.md +++ b/docs/src/snforge-advanced-features/storage-cheatcodes.md @@ -54,5 +54,5 @@ And perform a test checking `load` and `store` behavior in context of those stru This example uses `storage_address_from_base` with entry's of the storage variable. ```rust -{{#include ../../listings/snforge_advanced_features/crates/direct_storage_access/tests/using_storage_address_from_base.cairo}} +{{#include ../../listings/direct_storage_access/tests/using_storage_address_from_base.cairo}} ``` \ No newline at end of file From 744e083bfbd5b40669d8aec7165988ef1e224734 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 28 Nov 2024 16:56:23 +0100 Subject: [PATCH 138/183] Fix sncast command in docs --- docs/src/starknet/verify.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 07ab134cf9..edf09ece93 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -29,7 +29,8 @@ $ sncast \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ --contract-name SimpleBalance \ --verifier walnut \ - --network sepolia + --network sepolia \ + --fee-token strk ```
From 3a7c2860a6dec9c1fcc4ca59ca8ba2cb3066ac90 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 00:15:12 +0100 Subject: [PATCH 139/183] Fix sncast docs commands --- crates/sncast/README.md | 75 ++++++++++++-------- docs/src/projects/configuration.md | 12 ++-- docs/src/starknet/account-import.md | 10 +-- docs/src/starknet/account.md | 14 ++-- docs/src/starknet/call.md | 4 +- docs/src/starknet/calldata-transformation.md | 25 ++++--- docs/src/starknet/declare.md | 11 +-- docs/src/starknet/deploy.md | 22 +++--- docs/src/starknet/invoke.md | 9 +-- docs/src/starknet/sncast-overview.md | 11 +-- docs/src/starknet/verify.md | 6 +- 11 files changed, 117 insertions(+), 82 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index d7dda0a8cc..41bf3b112c 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -31,10 +31,12 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract + ```shell -$ sncast --account myuser \ +$ sncast --account user0 \ declare \ - --contract-name SimpleBalance + --contract-name HelloStarknet \ + --fee-token strk ```
@@ -42,8 +44,8 @@ $ sncast --account myuser \ ```shell command: Declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: [..] +transaction_hash: [..] ```

@@ -52,7 +54,8 @@ With arguments taken from `snfoundry.toml` file (default profile name): ```shell $ sncast declare \ - --contract-name SimpleBalance + --contract-name HellloStarknet \ + --fee-token strk ```
@@ -60,8 +63,8 @@ $ sncast declare \ ```shell command: Declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 +transaction_hash: [..] ```

@@ -69,10 +72,12 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Deploy a contract + ```shell -$ sncast --account myuser \ - deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ - --url http://127.0.0.1:5050/rpc \ +$ sncast --account user0 \ + deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --url http://127.0.0.1:5055 \ + --fee-token strk ```
@@ -80,16 +85,20 @@ $ sncast --account myuser \ ```shell command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: 2545627361586725870760320986020069125077312730415714481413957911720773997114 +transaction_hash: [..] ```

With arguments taken from `snfoundry.toml` file (default profile name): + ```shell -$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +$ sncast deploy \ +--class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ +--fee-token strk + ```
@@ -97,8 +106,8 @@ $ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2 ```shell command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: 2545627361586725870760320986020069125077312730415714481413957911720773997114 +transaction_hash: [..] ```

@@ -106,13 +115,16 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract + ```shell $ sncast \ - --account example_user \ + --account user0 \ invoke \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc \ + --fee-token strk ```
@@ -128,11 +140,14 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast invoke \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc \ + --fee-token strk ```
@@ -147,12 +162,14 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Call a contract + ```shell $ sncast \ call \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc ```
@@ -168,11 +185,13 @@ response: [0x0] With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast call \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc ```
diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index cf857d4840..8967b25b0e 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -49,12 +49,12 @@ defined in the profile. > Not all parameters have to be present in the configuration - you can choose to include only some of them and supply > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. + ```shell $ sncast --profile myprofile \ call \ - --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ - --function get \ - --arguments '0' \ + --contract-address 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ + --function get_balance \ --block-id latest ``` @@ -87,11 +87,11 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. + ```shell $ sncast call \ - --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ - --function get \ - --arguments '0' \ + --contract-address 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ + --function get_balance \ --block-id latest ``` diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 31039fe0ae..1f75b5a437 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -74,7 +74,7 @@ To import an account into the file holding the accounts info (`~/.starknet_accou ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_123 \ --address 0x1 \ --private-key 0x2 \ @@ -91,7 +91,7 @@ If you don't want to pass the private key in the command (because of safety aspe ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_123 \ --address 0x1 \ --type oz @@ -113,7 +113,7 @@ To import Argent account, set the `--type` flag to `argent`. ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_argent \ --address 0x1 \ --private-key 0x2 \ @@ -127,7 +127,7 @@ To import Braavos account, set the `--type` flag to `braavos`. ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_braavos \ --address 0x1 \ --private-key 0x2 \ @@ -141,7 +141,7 @@ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_oz \ --address 0x1 \ --private-key 0x2 \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 517e30e62a..8ef770616a 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -25,7 +25,7 @@ Do the following to start interacting with the Starknet: ```shell $ sncast \ account create \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name some-name ``` @@ -62,7 +62,7 @@ You can do it both by sending tokens from another starknet account or by bridgin ```shell $ sncast \ account deploy \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name some-name \ --fee-token strk \ --max-fee 9999999999999 @@ -96,7 +96,7 @@ To import an account to the `default accounts file`, use the `account import` co ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name my_imported_account \ --address 0x3a0bcb72428d8056cc7c2bbe5168ddfc844db2737dda3b4c67ff057691177e1 \ --private-key 0x2 \ @@ -149,7 +149,7 @@ with `--class-hash` flag: $ sncast \ account create \ --name some-name \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6 --type oz ``` @@ -161,7 +161,7 @@ Instead of random generation, salt can be specified with `--salt`. ```shell $ sncast \ account create \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name some-name \ --salt 0x1 ``` @@ -187,12 +187,13 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > 💡 **Info** > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. + ```shell $ sncast \ --keystore keystore.json \ --account account.json \ declare \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-name my_contract \ --fee-token eth ``` @@ -201,6 +202,7 @@ $ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. + ```shell $ sncast \ --keystore my_key.json \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 541c297f5e..d16293cbe3 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -19,7 +19,7 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ```shell $ sncast \ call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "balance_of" \ --arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f' @@ -44,7 +44,7 @@ You can call a contract at the specific block by passing `--block-id` argument. ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "balance_of" \ --arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f' \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 52c8aea376..90f8e4b3e7 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -52,10 +52,11 @@ pub mod DataTransformerContract { A default form of calldata passed to commands requiring it is a series of hex-encoded felts: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ --calldata 0x10 0x3 0x0 \ --block-id latest @@ -78,10 +79,11 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ --arguments '0x10, 3, data_stransformer_contract::Enum::One' \ --block-id latest @@ -123,10 +125,11 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function complex_fn \ --arguments \ 'array![array![1, 2], array![3, 4, 5], array![6]],'\ @@ -146,10 +149,11 @@ $ sncast call \ Alternatively, you can continue the single quote for multiple lines. + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function complex_fn \ --arguments 'array![array![1, 2], array![3, 4, 5], array![6]], 12, @@ -168,10 +172,11 @@ true, 2. `nested_struct_fn` - struct nesting: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function nested_struct_fn \ --arguments \ 'data_transformer_contract::NestedStructWithField {'\ diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 8cecbaa5e5..5cdc95f990 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -17,12 +17,13 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: + ```shell -$ sncast --account myuser \ +$ sncast --account user0 \ declare \ - --url http://127.0.0.1:5050/rpc \ + --url http://127.0.0.1:5055 \ --fee-token strk \ - --contract-name SimpleBalance + --contract-name HelloStarknet ```
@@ -30,8 +31,8 @@ $ sncast --account myuser \ ```shell command: declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 +transaction_hash: [..] To see declaration details, visit: class: https://starkscan.co/search/0x8448a68b5e... diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index d4b19f8260..8e29646938 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -14,13 +14,14 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: + ```shell $ sncast \ - --account myuser \ + --account user0 \ deploy \ - --url http://127.0.0.1:5050/rpc \ + --url http://127.0.0.1:5055/rpc \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 ```
@@ -57,6 +58,7 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. + ```shell $ sncast deploy \ --fee-token strk \ @@ -88,10 +90,11 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. + ```shell $ sncast deploy \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --salt 0x123 ``` @@ -100,8 +103,8 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303bc -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: 0x4500ae3e6429dc6dbac43a1ce92a5da24f1c87d49ad78610f71015dd3f6c61a +transaction_hash: [..] To see deployment details, visit: contract: https://starkscan.co/search/0x301316d47a... @@ -115,10 +118,11 @@ transaction: https://starkscan.co/search/0x64a62a0002... Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. + ```shell $ sncast deploy \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --unique ``` @@ -127,8 +131,8 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303aa -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] Details: contract: https://starkscan.co/search/0x301316d47a... diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 10bd551526..95916dfd20 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -18,9 +18,9 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ```shell $ sncast \ - --account example_user \ + --account user0 \ invoke \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "add" \ --fee-token eth \ @@ -53,11 +53,12 @@ transaction: https://sepolia.starkscan.co/tx/0x504f830428d0fcf462b4b814e2f67e12d Not every function accepts parameters. Here is how to call it. + ```shell $ sncast invoke \ --fee-token strk \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "function_without_params" + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "get_balance" ```
diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 95602ff2ca..4e7475953b 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -29,9 +29,10 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "pokemon" \ --arguments '"Charizard"' \ @@ -80,12 +81,14 @@ Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appe Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. + ```shell -$ sncast --account myuser \ +$ sncast --account user0 \ --wait \ deploy \ - --url http://127.0.0.1:5050 \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a + --url http://127.0.0.1:5055 \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --fee-token strk ```
diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index edf09ece93..b466812c5d 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -23,14 +23,14 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: + ```shell $ sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ - --contract-name SimpleBalance \ + --contract-name HelloStarknet \ --verifier walnut \ - --network sepolia \ - --fee-token strk + --network sepolia ```
From a30be73ff7da04ff1ed2fd0f3334c69abbc6fe84 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 09:38:25 +0100 Subject: [PATCH 140/183] Change printing tx hash in `wait_for_tx` --- crates/sncast/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sncast/src/lib.rs b/crates/sncast/src/lib.rs index 181d3558dc..f5c17041f6 100644 --- a/crates/sncast/src/lib.rs +++ b/crates/sncast/src/lib.rs @@ -560,7 +560,7 @@ pub async fn wait_for_tx( tx_hash: Felt, wait_params: ValidatedWaitParams, ) -> Result<&str, WaitForTransactionError> { - println!("Transaction hash = {tx_hash:#x}"); + println!("Transaction hash: {tx_hash:#x}"); let retries = wait_params.get_retries(); for i in (1..retries).rev() { From 0fb04b12c838d213e31aadbac6f3382002726d30 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 09:41:46 +0100 Subject: [PATCH 141/183] Use `LazyLock` for regex; Add `ignore_output` field in `SnippetConfig` --- crates/docs/src/snippet.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 2b03f74534..5a77c667fc 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -1,6 +1,16 @@ +use std::sync::LazyLock; + use regex::Regex; use serde::{Deserialize, Serialize}; +static RE_SNCAST: LazyLock = LazyLock::new(|| { + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psncast .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for normalizing loop function names") +}); + +static RE_SNFORGE: LazyLock = LazyLock::new(|| { + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psnforge .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for normalizing loop function names") +}); + #[derive(Clone, Debug)] pub struct SnippetType(String); @@ -21,7 +31,7 @@ impl SnippetType { } #[must_use] - pub fn get_re(&self) -> Regex { + pub fn get_re(&self) -> &'static Regex { // The regex pattern is used to match the snippet, its config and the output. Example: // // ```shell @@ -34,12 +44,12 @@ impl SnippetType { // ``` //
- let escaped_command = regex::escape(self.as_str()); - let pattern = format!( - r"(?ms)^(?:\n)?```shell\n\$ (?P{escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?" - ); - - Regex::new(&pattern).unwrap() + // Regex::new(&pattern).unwrap() + match self.as_str() { + "snforge" => &RE_SNFORGE, + "sncast" => &RE_SNCAST, + _ => panic!("Regex for snippet type {} not found", self.as_str()), + } } } @@ -47,6 +57,8 @@ impl SnippetType { pub struct SnippetConfig { pub ignored: Option, pub package_name: Option, + pub contract_name: Option, + pub ignore_output: Option, } #[derive(Debug)] From 48bd8c1a0396db28a66ebd12cb0ec9b60c008249 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 11:42:50 +0100 Subject: [PATCH 142/183] Add `sncast_example` package --- docs/listings/sncast_example/Scarb.toml | 18 +++++++ docs/listings/sncast_example/snfoundry.toml | 9 ++++ .../src/data_transformer_contract.cairo | 41 ++++++++++++++++ .../sncast_example/src/hello_starknet.cairo | 30 ++++++++++++ docs/listings/sncast_example/src/lib.cairo | 2 + .../sncast_example/tests/test_contract.cairo | 47 +++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 docs/listings/sncast_example/Scarb.toml create mode 100644 docs/listings/sncast_example/snfoundry.toml create mode 100644 docs/listings/sncast_example/src/data_transformer_contract.cairo create mode 100644 docs/listings/sncast_example/src/hello_starknet.cairo create mode 100644 docs/listings/sncast_example/src/lib.cairo create mode 100644 docs/listings/sncast_example/tests/test_contract.cairo diff --git a/docs/listings/sncast_example/Scarb.toml b/docs/listings/sncast_example/Scarb.toml new file mode 100644 index 0000000000..717985204b --- /dev/null +++ b/docs/listings/sncast_example/Scarb.toml @@ -0,0 +1,18 @@ +[package] +name = "hello_starknet" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet = "2.7.0" + +[dev-dependencies] +snforge_std = { path = "../../../snforge_std" } + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/sncast_example/snfoundry.toml b/docs/listings/sncast_example/snfoundry.toml new file mode 100644 index 0000000000..f27e809db1 --- /dev/null +++ b/docs/listings/sncast_example/snfoundry.toml @@ -0,0 +1,9 @@ +[sncast.default] +account = "user0" +accounts-file = "accounts.json" +url = "http://127.0.0.1:5055" + +[sncast.myprofile] +account = "user0" +accounts-file = "accounts.json" +url = "http://127.0.0.1:5055" \ No newline at end of file diff --git a/docs/listings/sncast_example/src/data_transformer_contract.cairo b/docs/listings/sncast_example/src/data_transformer_contract.cairo new file mode 100644 index 0000000000..01950b44c1 --- /dev/null +++ b/docs/listings/sncast_example/src/data_transformer_contract.cairo @@ -0,0 +1,41 @@ +#[derive(Drop)] +pub struct SimpleStruct { + a: felt252 +} + +#[derive(Drop)] +pub struct NestedStructWithField { + a: SimpleStruct, + b: felt252 +} + +#[derive(Drop)] +pub enum Enum { + One: (), + Two: u128, + Three: NestedStructWithField +} + + +#[starknet::contract] +pub mod DataTransformerContract { + use super::{NestedStructWithField, Enum}; + + #[storage] + struct Storage {} + + fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) {} + + fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) {} + + fn complex_fn( + self: ContractState, + arr: Array>, + one: u8, + two: i8, + three: ByteArray, + four: (felt252, u32), + five: bool, + six: u256 + ) {} +} diff --git a/docs/listings/sncast_example/src/hello_starknet.cairo b/docs/listings/sncast_example/src/hello_starknet.cairo new file mode 100644 index 0000000000..678747e70b --- /dev/null +++ b/docs/listings/sncast_example/src/hello_starknet.cairo @@ -0,0 +1,30 @@ +#[starknet::interface] +pub trait IHelloStarknet { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; + fn sum_numbers(ref self: TContractState, a: felt252, b: felt252, c: felt252) -> felt252; +} + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + + fn sum_numbers(ref self: ContractState, a: felt252, b: felt252, c: felt252) -> felt252 { + a + b + c + } + } +} diff --git a/docs/listings/sncast_example/src/lib.cairo b/docs/listings/sncast_example/src/lib.cairo new file mode 100644 index 0000000000..5a25ad9f3a --- /dev/null +++ b/docs/listings/sncast_example/src/lib.cairo @@ -0,0 +1,2 @@ +pub mod hello_starknet; +pub mod data_transformer_contract; diff --git a/docs/listings/sncast_example/tests/test_contract.cairo b/docs/listings/sncast_example/tests/test_contract.cairo new file mode 100644 index 0000000000..583fd4558f --- /dev/null +++ b/docs/listings/sncast_example/tests/test_contract.cairo @@ -0,0 +1,47 @@ +use starknet::ContractAddress; + +use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; + +use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcher; +use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcherTrait; +use hello_starknet::hello_starknet::IHelloStarknetDispatcher; +use hello_starknet::hello_starknet::IHelloStarknetDispatcherTrait; + +fn deploy_contract(name: ByteArray) -> ContractAddress { + let contract = declare(name).unwrap().contract_class(); + let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + contract_address +} + +#[test] +fn test_increase_balance() { + let contract_address = deploy_contract("HelloStarknet"); + + let dispatcher = IHelloStarknetDispatcher { contract_address }; + + let balance_before = dispatcher.get_balance(); + assert(balance_before == 0, 'Invalid balance'); + + dispatcher.increase_balance(42); + + let balance_after = dispatcher.get_balance(); + assert(balance_after == 42, 'Invalid balance'); +} + +#[test] +#[feature("safe_dispatcher")] +fn test_cannot_increase_balance_with_zero_value() { + let contract_address = deploy_contract("HelloStarknet"); + + let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; + + let balance_before = safe_dispatcher.get_balance().unwrap(); + assert(balance_before == 0, 'Invalid balance'); + + match safe_dispatcher.increase_balance(0) { + Result::Ok(_) => core::panic_with_felt252('Should have panicked'), + Result::Err(panic_data) => { + assert(*panic_data.at(0) == 'Amount cannot be 0', *panic_data.at(0)); + } + }; +} From f0e5fd99a2ce6b8901ecaaa2b7f7cfae2df8a210 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 12:54:57 +0100 Subject: [PATCH 143/183] Fixes and adjustments to docs snippets --- crates/sncast/README.md | 10 +++---- docs/src/projects/configuration.md | 2 +- docs/src/starknet/account.md | 21 +++++++------- docs/src/starknet/calldata-transformation.md | 5 ++-- docs/src/starknet/declare.md | 10 +++---- docs/src/starknet/deploy.md | 30 ++++++++++---------- docs/src/starknet/invoke.md | 10 ++++--- docs/src/starknet/multicall.md | 4 +-- docs/src/starknet/script.md | 5 ++++ docs/src/starknet/show_config.md | 10 +++---- docs/src/starknet/sncast-overview.md | 12 ++++---- docs/src/starknet/verify.md | 2 +- 12 files changed, 64 insertions(+), 57 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 41bf3b112c..5812460e16 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -63,7 +63,7 @@ $ sncast declare \ ```shell command: Declare -class_hash: 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 +class_hash: [..] transaction_hash: [..] ```
@@ -85,7 +85,7 @@ $ sncast --account user0 \ ```shell command: Deploy -contract_address: 2545627361586725870760320986020069125077312730415714481413957911720773997114 +contract_address: [..] transaction_hash: [..] ```
@@ -106,7 +106,7 @@ $ sncast deploy \ ```shell command: Deploy -contract_address: 2545627361586725870760320986020069125077312730415714481413957911720773997114 +contract_address: [..] transaction_hash: [..] ```
@@ -132,7 +132,7 @@ $ sncast \ ```shell command: Invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +transaction_hash: [..] ```

@@ -155,7 +155,7 @@ $ sncast invoke \ ```shell command: Invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +transaction_hash: [..] ```

diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 8967b25b0e..9b7f00263f 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -100,7 +100,7 @@ $ sncast call \ ```shell command: call -response: [0x1, 0x23, 0x4] +response: [0x0] ```

diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 8ef770616a..5cc61e2661 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -26,7 +26,7 @@ Do the following to start interacting with the Starknet: $ sncast \ account create \ --url http://127.0.0.1:5055 \ - --name some-name + --name new_account ```
@@ -35,12 +35,12 @@ $ sncast \ ```shell command: account create add_profile: --add-profile flag was not set. No profile added to snfoundry.toml -address: 0x34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b -max_fee: 180527346330500 +address: [..] +max_fee: [..] message: Account successfully created. Prefund generated address with at least STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand. To see account creation details, visit: -account: https://starkscan.co/search/contract/34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b +account: [..] ```

@@ -59,11 +59,12 @@ You can do it both by sending tokens from another starknet account or by bridgin >![image](images/starknet-faucet-sepolia.png) #### Deploy account with the `sncast account deploy` command + ```shell $ sncast \ account deploy \ --url http://127.0.0.1:5055 \ - --name some-name \ + --name new_account \ --fee-token strk \ --max-fee 9999999999999 ``` @@ -73,10 +74,10 @@ $ sncast \ ```shell command: account deploy -transaction_hash: 0x20b20896ce63371ef015d66b4dd89bf18c5510a840b4a85a43a983caa6e2579 +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/search/0x20b20896ce... +transaction: [..] ```

@@ -133,7 +134,7 @@ Delete an account from `accounts-file` and its associated Scarb profile. If you ```shell $ sncast account delete \ - --name some-name \ + --name new_account \ --network alpha-sepolia ``` @@ -148,7 +149,7 @@ with `--class-hash` flag: ```shell $ sncast \ account create \ - --name some-name \ + --name new_account_2 \ --url http://127.0.0.1:5055 \ --class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6 --type oz @@ -162,7 +163,7 @@ Instead of random generation, salt can be specified with `--salt`. $ sncast \ account create \ --url http://127.0.0.1:5055 \ - --name some-name \ + --name another_account_3 \ --salt 0x1 ``` diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 90f8e4b3e7..56421776ea 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -79,13 +79,14 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: - + + ```shell $ sncast call \ --url http://127.0.0.1:5055 \ --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ - --arguments '0x10, 3, data_stransformer_contract::Enum::One' \ + --arguments '0x10, 3, data_transformer_contract::Enum::One' \ --block-id latest ``` diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 5cdc95f990..c132c71e43 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -17,11 +17,11 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: - + ```shell $ sncast --account user0 \ declare \ - --url http://127.0.0.1:5055 \ + --url http://127.0.0.1:5055 \ --fee-token strk \ --contract-name HelloStarknet ``` @@ -31,12 +31,12 @@ $ sncast --account user0 \ ```shell command: declare -class_hash: 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 +class_hash: [..] transaction_hash: [..] To see declaration details, visit: -class: https://starkscan.co/search/0x8448a68b5e... -transaction: https://starkscan.co/search/0x7ad0d6e449... +class: [..] +transaction: [..] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 8e29646938..cd57e1cec4 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -28,13 +28,13 @@ $ sncast \ Output: ```shell -command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +command: deploy +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: [..] +transaction: [..] ```

@@ -58,12 +58,12 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. - + ```shell $ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ - --constructor-calldata 0x1 0x1 0x0 + --constructor-calldata 0x1 0x2 0x3 ```
@@ -71,12 +71,12 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: [..] +transaction: [..] ```

@@ -107,8 +107,8 @@ contract_address: 0x4500ae3e6429dc6dbac43a1ce92a5da24f1c87d49ad78610f71015dd3f6c transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: [..] +transaction: [..] ```

@@ -135,7 +135,7 @@ contract_address: [..] transaction_hash: [..] Details: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: [..] +transaction: [..] ```
diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 95916dfd20..6619f06bd0 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -16,6 +16,8 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example + + ```shell $ sncast \ --account user0 \ @@ -35,10 +37,10 @@ $ sncast \ ```shell command: invoke -transaction_hash: 0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313 +transaction_hash: [..] To see invocation details, visit: -transaction: https://sepolia.starkscan.co/tx/0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313 +transaction: [..] ```

@@ -66,9 +68,9 @@ $ sncast invoke \ ```shell command: invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/tx/0x7ad0d6e449... +transaction: [..] ```
diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 2134d927d0..f14313c0b0 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -55,10 +55,10 @@ $ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-t ```shell command: multicall -transaction_hash: 0x38fb8a0432f71bf2dae746a1b4f159a75a862e253002b48599c9611fa271dcb +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/tx/0x38fb8a0432... +transaction: [..] ```

diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index d822d4dda0..824b703873 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -255,6 +255,8 @@ sncast_std = "0.33.0" To run the script, do: + + ```shell $ sncast \ script run my_script @@ -333,6 +335,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: + ```shell $ sncast \ --account example_user \ @@ -360,6 +363,7 @@ status: success As [an idempotency](#state-file) feature is turned on by default, executing the same script once again ends with a success and only `call` functions are being executed (as they do not change the network state): + ```shell $ sncast \ --account example_user \ @@ -384,6 +388,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already deployed): + ```shell $ sncast \ --account example_user \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index c51664b7fb..9110159822 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -15,9 +15,8 @@ replace any subcommand (and its parameters) with `show-config` and it will show ```shell $ sncast \ - --account user1 \ - show-config \ - --url http://127.0.0.1:5050 + --account user0 \ + show-config ```
@@ -25,10 +24,9 @@ $ sncast \ ```shell command: show-config -account: user1 +account: user0 chain_id: alpha-sepolia -keystore: ../keystore -rpc_url: http://127.0.0.1:5050/rpc +rpc_url: http://127.0.0.1:5055 ```

\ No newline at end of file diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 4e7475953b..6b2ab191a8 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -81,7 +81,7 @@ Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appe Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. - + ```shell $ sncast --account user0 \ --wait \ @@ -95,7 +95,7 @@ $ sncast --account user0 \ Output: ```shell -Transaction hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 +Transaction hash: [..] Waiting for transaction to be received. Retries left: 11 Waiting for transaction to be received. Retries left: 10 Waiting for transaction to be received. Retries left: 9 @@ -108,12 +108,12 @@ Received transaction. Status: Pending Received transaction. Status: Pending Received transaction. Status: Pending command: deploy -contract_address: 0x1d91599ec661e97fdcbb10c642a1c4f920986f1a7a9659d157d0db09baaa29e -transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x1d91599ec6... -transaction: https://starkscan.co/search/0x3062310a1e... +contract: [..] +transaction: [..] ```

diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index b466812c5d..3491e456bd 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -23,7 +23,7 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: - + ```shell $ sncast \ verify \ From 8c9bda7d8a37a4113ebeeed7ec793fbb8a54e58b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 12:55:20 +0100 Subject: [PATCH 144/183] Add example contract with constructor --- .../sncast_example/src/constructor_contract.cairo | 11 +++++++++++ docs/listings/sncast_example/src/lib.cairo | 1 + 2 files changed, 12 insertions(+) create mode 100644 docs/listings/sncast_example/src/constructor_contract.cairo diff --git a/docs/listings/sncast_example/src/constructor_contract.cairo b/docs/listings/sncast_example/src/constructor_contract.cairo new file mode 100644 index 0000000000..bf3c4198a0 --- /dev/null +++ b/docs/listings/sncast_example/src/constructor_contract.cairo @@ -0,0 +1,11 @@ +#[starknet::contract] +pub mod ConstructorContract { + + #[storage] + struct Storage {} + + #[constructor] + fn constructor(ref self: ContractState, x: felt252, y: felt252, z: felt252) { + + } +} diff --git a/docs/listings/sncast_example/src/lib.cairo b/docs/listings/sncast_example/src/lib.cairo index 5a25ad9f3a..3bae48b43f 100644 --- a/docs/listings/sncast_example/src/lib.cairo +++ b/docs/listings/sncast_example/src/lib.cairo @@ -1,2 +1,3 @@ pub mod hello_starknet; pub mod data_transformer_contract; +pub mod constructor_contract; \ No newline at end of file From 7a294ea8fe605890aca1b3d64bd7624107661048 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 16:12:15 +0100 Subject: [PATCH 145/183] Fix snippet for `tx-status` command --- docs/src/starknet/tx-status.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 8dee638a90..aa6ba7b27a 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -16,7 +16,7 @@ You can track the details about the execution and finality status of a transacti $ sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ - --url http://127.0.0.1:5050 + --url https://starknet-sepolia.public.blastapi.io ```
@@ -25,6 +25,6 @@ $ sncast \ ```shell command: tx-status execution_status: Succeeded -finality_status: AcceptedOnL2 +finality_status: AcceptedOnL1 ```
From 19576ab37177fdfb95e4db9ec79b6e152a442495 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 17:56:58 +0100 Subject: [PATCH 146/183] Further fixes of sncast docs snippets --- crates/sncast/README.md | 23 +++++++++++------ docs/src/starknet/deploy.md | 2 +- docs/src/starknet/fees-and-versions.md | 8 +++--- docs/src/starknet/multicall.md | 34 ++++++++++++++++++-------- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 5812460e16..39df068a6f 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -31,7 +31,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract - + ```shell $ sncast --account user0 \ declare \ @@ -52,9 +52,10 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast declare \ - --contract-name HellloStarknet \ + --contract-name HelloStarknet \ --fee-token strk ``` @@ -72,7 +73,7 @@ transaction_hash: [..] ### Deploy a contract - + ```shell $ sncast --account user0 \ deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ @@ -93,7 +94,7 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast deploy \ --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ @@ -131,8 +132,11 @@ $ sncast \ Output: ```shell -command: Invoke +command: invoke transaction_hash: [..] + +To see invocation details, visit: +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -154,8 +158,11 @@ $ sncast invoke \ Output: ```shell -command: Invoke +command: invoke transaction_hash: [..] + +To see invocation details, visit: +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -177,7 +184,7 @@ $ sncast \ ```shell command: call -response: [0x0] +response: [0x6] ```

@@ -199,7 +206,7 @@ $ sncast call \ ```shell command: call -response: [0x0] +response: [0x6] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index cd57e1cec4..07da62873d 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -103,7 +103,7 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x4500ae3e6429dc6dbac43a1ce92a5da24f1c87d49ad78610f71015dd3f6c61a +contract_address: [..] transaction_hash: [..] To see deployment details, visit: diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 918ec8374c..2587abedb8 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -27,7 +27,7 @@ When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --fee-token strk \ --max-fee 9999999999999 ``` @@ -35,7 +35,7 @@ or set `--version` to `v3`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --version v3 \ --max-fee 9999999999999 ``` @@ -44,7 +44,7 @@ In case of paying in ETH, same rules apply. You need to set either `--fee-token` ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --fee-token eth \ --max-fee 9999999999999 ``` @@ -53,7 +53,7 @@ or set `--version` to `v1`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --version v1 \ --max-fee 9999999999999 ``` diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index f14313c0b0..8d4bb1d20a 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -46,8 +46,10 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > 📝 **Note** > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. + + ```shell -$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +$ sncast multicall run --path multicall_example.toml --fee-token strk ```
@@ -81,14 +83,8 @@ $ sncast multicall new ./template.toml Output: ```shell -Multicall template successfully saved in ./template.toml -``` -
-
- -Resulting in output: -```toml -[[call]] +command: multicall new +content: [[call]] call_type = "deploy" class_hash = "" inputs = [] @@ -100,7 +96,11 @@ call_type = "invoke" contract_address = "" function = "" inputs = [] + +path: ./template.toml ``` +
+
> ⚠️ **Warning** > Trying to pass any existing file as an output for `multicall new` will result in error, as the command doesn't overwrite by default. @@ -117,6 +117,20 @@ $ sncast multicall new ./template.toml --overwrite Output: ```shell -Multicall template successfully saved in ./new_multicall_template.toml +command: multicall new +content: [[call]] +call_type = "deploy" +class_hash = "" +inputs = [] +id = "" +unique = false + +[[call]] +call_type = "invoke" +contract_address = "" +function = "" +inputs = [] + +path: ./template.toml ```
From 82530bdf21c619ef30f6daf7f8072e1b3ff1d5cf Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 17:57:24 +0100 Subject: [PATCH 147/183] Add `sncast_std` dependency to `sncast_example` --- docs/listings/sncast_example/Scarb.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/listings/sncast_example/Scarb.toml b/docs/listings/sncast_example/Scarb.toml index 717985204b..1a51433a8a 100644 --- a/docs/listings/sncast_example/Scarb.toml +++ b/docs/listings/sncast_example/Scarb.toml @@ -7,6 +7,7 @@ edition = "2023_11" [dependencies] starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } [dev-dependencies] snforge_std = { path = "../../../snforge_std" } From 77d32cac34d7db9cf66e31f0c8ac8b55b0c62963 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:01:02 +0100 Subject: [PATCH 148/183] Add `update_scarb_toml_dependencies` to utils --- crates/docs/src/utils.rs | 46 +++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 9b5b3bcfaa..f3a99053b9 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -1,6 +1,8 @@ -use std::{env, path::PathBuf}; - use crate::snippet::Snippet; +use camino::Utf8PathBuf; +use std::{env, fs, path::PathBuf, str::FromStr}; +use tempfile::TempDir; +use toml_edit::{value, DocumentMut}; #[must_use] pub fn get_nth_ancestor(levels_up: usize) -> PathBuf { @@ -27,15 +29,49 @@ pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &st ); } -pub fn print_success_message(snippets_len: usize, tool_name: &str) { - println!("Successfully validated {snippets_len} {tool_name} docs snippets"); +pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { + let validated_snippets_count = snippets + .iter() + .filter(|snippet| !snippet.config.ignored.unwrap_or(false)) // Filter out ignored snippets + .count(); + let ignored_snippets_count = snippets.len() - validated_snippets_count; + println!("Finished validation of {tool_name} docs snippets\nValidated: {validated_snippets_count}, Ignored: {ignored_snippets_count}"); } pub fn print_skipped_snippet_message(snippet: &Snippet) { println!( - "Skipped validation of {} snippet in the docs in file: {} at line {}", + "Ignoring {} docs snippet, file: {} :{}:1\n", snippet.snippet_type.as_str(), snippet.file_path, snippet.line_start, ); } + +pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box> { + let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std") + .unwrap() + .canonicalize_utf8() + .unwrap() + .to_string() + .replace('\\', "/"); + + let sncast_std_path = Utf8PathBuf::from_str("../../sncast_std") + .unwrap() + .canonicalize_utf8() + .unwrap() + .to_string() + .replace('\\', "/"); + + let scarb_toml_path = temp.path().join("Scarb.toml"); + let mut scarb_toml = fs::read_to_string(&scarb_toml_path) + .unwrap() + .parse::() + .unwrap(); + + scarb_toml["dependencies"]["sncast_std"]["path"] = value(&sncast_std_path); + scarb_toml["dev-dependencies"]["snforge_std"]["path"] = value(&snforge_std_path); + + fs::write(&scarb_toml_path, scarb_toml.to_string())?; + + Ok(()) +} From 3686cb6526166b33038224741398006788719aa3 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:02:03 +0100 Subject: [PATCH 149/183] Remove new line when printing in `print_skipped_snippet_message` --- crates/docs/src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index f3a99053b9..a1c93b3dae 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -40,7 +40,7 @@ pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { pub fn print_skipped_snippet_message(snippet: &Snippet) { println!( - "Ignoring {} docs snippet, file: {} :{}:1\n", + "Ignoring {} docs snippet, file: {} :{}:1", snippet.snippet_type.as_str(), snippet.file_path, snippet.line_start, From 178e2d85d011c3a94638d8ceba2780d5f039076b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:02:38 +0100 Subject: [PATCH 150/183] Improve sncast commands validation logic --- .../sncast/tests/docs_snippets/validation.rs | 182 ++++++++++++++++-- 1 file changed, 169 insertions(+), 13 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 362cd07e7e..b803c7b2f2 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,17 +1,147 @@ +use std::collections::HashMap; +use std::fs; + +use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ - assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, + get_nth_ancestor, print_skipped_snippet_message, print_success_message, + update_scarb_toml_dependencies, }; use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; -use tempfile::tempdir; +use regex::Regex; +use shared::test_utils::output_assert::{assert_stdout_contains, AsOutput}; +use tempfile::TempDir; +use crate::helpers::constants::URL; +use crate::helpers::fixtures::copy_directory_to_tempdir; use crate::helpers::runner::runner; +struct Contract { + class_hash: String, + contract_address: String, +} + +fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { + // Default account from starknet-devnet-rs + let accounts = r#" + { + "alpha-sepolia": { + "user0": { + "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", + "deployed": true, + "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", + "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", + "type": "open_zeppelin" + } + } + } + "#; + + let accounts_path = temp.path().join("accounts.json"); + fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); + + Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") +} + +fn declare_and_deploy_contract( + contract_name: &str, + accounts_file: &str, + temp: &TempDir, +) -> Contract { + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "user0", + "declare", + "--url", + URL, + "--contract-name", + contract_name, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + let re_class_hash = Regex::new(r"class_hash:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let class_hash = re_class_hash + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("class_hash not found in the output"); + + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "user0", + "deploy", + "--url", + URL, + "--class-hash", + class_hash, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let re_contract_address = Regex::new(r"contract_address:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + + let contract_address = re_contract_address + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("contract_address not found in the output"); + + Contract { + class_hash: class_hash.to_string(), + contract_address: contract_address.to_string(), + } +} + +fn setup_contracts_map( + accounts_json_path: &Utf8PathBuf, + tempdir: &TempDir, +) -> HashMap { + let mut contracts: HashMap = HashMap::new(); + let contract_names = [ + "HelloStarknet", + "DataTransformerContract", + "ConstructorContract", + ]; + + for contract_name in &contract_names { + let contract = + declare_and_deploy_contract(contract_name, accounts_json_path.as_str(), tempdir); + contracts.insert((*contract_name).to_string(), contract); + } + + contracts +} + +fn swap_next_element<'a>(args: &mut [&'a str], target: &str, new_value: &'a str) { + if let Some(index) = args.iter().position(|&x| x == target) { + if index + 1 < args.len() { + args[index + 1] = new_value; + } + } +} + +fn is_command(args: &[&str], commands: &[&str]) -> bool { + commands.iter().any(|&cmd| args.contains(&cmd)) +} + #[test] fn test_docs_snippets() { - let tempdir = tempdir().expect("Unable to create a temporary directory"); - - let root_dir_path = get_nth_ancestor(2); + let root_dir_path: std::path::PathBuf = get_nth_ancestor(2); let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); @@ -28,25 +158,51 @@ fn test_docs_snippets() { .chain(readme_snippets) .collect::>(); + let sncast_example_dir = + Utf8PathBuf::from_path_buf(root_dir_path.join("docs/listings/sncast_example")) + .expect("Invalid UTF-8 path"); + let tempdir = copy_directory_to_tempdir(&sncast_example_dir); + + let accounts_json_path = prepare_accounts_file(&tempdir); + + update_scarb_toml_dependencies(&tempdir).unwrap(); + + let contracts = setup_contracts_map(&accounts_json_path, &tempdir); + for snippet in &snippets { + if snippet.config.ignored.unwrap_or(false) { + print_skipped_snippet_message(snippet); + continue; + } + let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); // remove "sncast" from the args args.remove(0); - if snippet.config.ignored.unwrap_or(false) { - print_skipped_snippet_message(snippet); - continue; + args.insert(0, "--accounts-file"); + args.insert(1, accounts_json_path.as_str()); + + if let Some(contract_name) = &snippet.config.contract_name { + let contract = contracts.get(contract_name).expect("Contract not found"); + + // In case of invoke/call/verify, we need to replace contract-address in snippet's args with the one from prepared contract + if is_command(&args, &["invoke", "call", "verify"]) { + swap_next_element(&mut args, "--contract-address", &contract.contract_address); + // In case of deploy, we need to replace class-hash in snippet's args with the one from prepared contract + } else if is_command(&args, &["deploy"]) { + swap_next_element(&mut args, "--class-hash", &contract.class_hash); + } } let snapbox = runner(&args).current_dir(tempdir.path()); - let output = snapbox.output().expect("Failed to execute the command"); - let exit_code = output.status.code().unwrap_or_default(); - let stderr = String::from_utf8_lossy(&output.stderr); + let output = snapbox.assert().success(); - assert_valid_snippet(exit_code != 2, snippet, &stderr); + if snippet.output.is_some() && !snippet.config.ignore_output.unwrap_or(false) { + assert_stdout_contains(output, snippet.output.as_ref().unwrap()); + } } - print_success_message(snippets.len(), snippet_type.as_str()); + print_success_message(&snippets, snippet_type.as_str()); } From 74058a5bc9804fe5ddb02141260389ca8dffd54a Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:02:47 +0100 Subject: [PATCH 151/183] Update dependencies --- Cargo.lock | 3 +++ crates/docs/Cargo.toml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 63cec86a7f..6300a1c96c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1893,10 +1893,13 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" name = "docs" version = "0.34.0" dependencies = [ + "camino", "regex", "serde", "serde_json", "shell-words", + "tempfile", + "toml_edit", "walkdir", ] diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index 41e8b672b1..bd24e1877d 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -11,6 +11,9 @@ shell-words = "1.1.0" walkdir.workspace = true serde.workspace = true serde_json.workspace = true +toml_edit.workspace = true +camino.workspace = true +tempfile.workspace = true [features] testing = [] From 443ebcf0cd11800372d48f9799f18b7da18475cf Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:03:03 +0100 Subject: [PATCH 152/183] Adjust `test_docs_snippets` in forge --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a385d1c06a..1fb1666f89 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -55,5 +55,5 @@ fn test_docs_snippets() { } } - print_success_message(snippets.len(), snippet_type.as_str()); + print_success_message(&snippets, snippet_type.as_str()); } From d25c233ddf87f706bad72c2b29e5f888bf0afa0c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:08:22 +0100 Subject: [PATCH 153/183] Rename `ignore_output` to `ignored_output` --- crates/docs/src/snippet.rs | 2 +- crates/sncast/tests/docs_snippets/validation.rs | 2 +- docs/src/starknet/invoke.md | 2 +- docs/src/starknet/multicall.md | 2 +- docs/src/starknet/script.md | 8 ++++---- docs/src/starknet/sncast-overview.md | 2 +- docs/src/starknet/verify.md | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 5a77c667fc..535f054f9e 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -58,7 +58,7 @@ pub struct SnippetConfig { pub ignored: Option, pub package_name: Option, pub contract_name: Option, - pub ignore_output: Option, + pub ignored_output: Option, } #[derive(Debug)] diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index b803c7b2f2..aa2e2977cc 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -199,7 +199,7 @@ fn test_docs_snippets() { let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.assert().success(); - if snippet.output.is_some() && !snippet.config.ignore_output.unwrap_or(false) { + if snippet.output.is_some() && !snippet.config.ignored_output.unwrap_or(false) { assert_stdout_contains(output, snippet.output.as_ref().unwrap()); } } diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 6619f06bd0..8a6de0cdf1 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -17,7 +17,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example - + ```shell $ sncast \ --account user0 \ diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 8d4bb1d20a..25b043cdad 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -47,7 +47,7 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. - + ```shell $ sncast multicall run --path multicall_example.toml --fee-token strk ``` diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 824b703873..06b800e33c 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -256,7 +256,7 @@ sncast_std = "0.33.0" To run the script, do: - + ```shell $ sncast \ script run my_script @@ -335,7 +335,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: - + ```shell $ sncast \ --account example_user \ @@ -363,7 +363,7 @@ status: success As [an idempotency](#state-file) feature is turned on by default, executing the same script once again ends with a success and only `call` functions are being executed (as they do not change the network state): - + ```shell $ sncast \ --account example_user \ @@ -388,7 +388,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already deployed): - + ```shell $ sncast \ --account example_user \ diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 6b2ab191a8..d2718788aa 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -81,7 +81,7 @@ Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appe Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. - + ```shell $ sncast --account user0 \ --wait \ diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 3491e456bd..4cd116d831 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -23,7 +23,7 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: - + ```shell $ sncast \ verify \ From 8d9e5a376a4abacd1878d98399483f55e61a35c9 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:21:53 +0100 Subject: [PATCH 154/183] Code refactor and cleanup --- crates/docs/src/utils.rs | 25 +++++------ .../sncast/tests/docs_snippets/validation.rs | 44 ++++--------------- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index a1c93b3dae..34b82889f2 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -32,9 +32,10 @@ pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &st pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { let validated_snippets_count = snippets .iter() - .filter(|snippet| !snippet.config.ignored.unwrap_or(false)) // Filter out ignored snippets + .filter(|snippet| !snippet.config.ignored.unwrap_or(false)) .count(); let ignored_snippets_count = snippets.len() - validated_snippets_count; + println!("Finished validation of {tool_name} docs snippets\nValidated: {validated_snippets_count}, Ignored: {ignored_snippets_count}"); } @@ -47,22 +48,18 @@ pub fn print_skipped_snippet_message(snippet: &Snippet) { ); } -pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box> { - let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std") - .unwrap() - .canonicalize_utf8() - .unwrap() +fn get_canonical_path(relative_path: &str) -> Result> { + Ok(Utf8PathBuf::from_str(relative_path)? + .canonicalize_utf8()? .to_string() - .replace('\\', "/"); - - let sncast_std_path = Utf8PathBuf::from_str("../../sncast_std") - .unwrap() - .canonicalize_utf8() - .unwrap() - .to_string() - .replace('\\', "/"); + .replace('\\', "/")) +} +pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box> { + let snforge_std_path = get_canonical_path("../../snforge_std")?; + let sncast_std_path = get_canonical_path("../../sncast_std")?; let scarb_toml_path = temp.path().join("Scarb.toml"); + let mut scarb_toml = fs::read_to_string(&scarb_toml_path) .unwrap() .parse::() diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index aa2e2977cc..c30d45c89b 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::fs; +use std::str::FromStr; use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; @@ -10,6 +10,7 @@ use docs::utils::{ use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; use regex::Regex; use shared::test_utils::output_assert::{assert_stdout_contains, AsOutput}; +use sncast::helpers::constants::DEFAULT_ACCOUNTS_FILE; use tempfile::TempDir; use crate::helpers::constants::URL; @@ -21,28 +22,6 @@ struct Contract { contract_address: String, } -fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { - // Default account from starknet-devnet-rs - let accounts = r#" - { - "alpha-sepolia": { - "user0": { - "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", - "deployed": true, - "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", - "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", - "type": "open_zeppelin" - } - } - } - "#; - - let accounts_path = temp.path().join("accounts.json"); - fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); - - Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") -} - fn declare_and_deploy_contract( contract_name: &str, accounts_file: &str, @@ -107,10 +86,7 @@ fn declare_and_deploy_contract( } } -fn setup_contracts_map( - accounts_json_path: &Utf8PathBuf, - tempdir: &TempDir, -) -> HashMap { +fn setup_contracts_map(tempdir: &TempDir) -> HashMap { let mut contracts: HashMap = HashMap::new(); let contract_names = [ "HelloStarknet", @@ -118,6 +94,7 @@ fn setup_contracts_map( "ConstructorContract", ]; + let accounts_json_path = Utf8PathBuf::from_str(DEFAULT_ACCOUNTS_FILE).unwrap(); for contract_name in &contract_names { let contract = declare_and_deploy_contract(contract_name, accounts_json_path.as_str(), tempdir); @@ -163,11 +140,9 @@ fn test_docs_snippets() { .expect("Invalid UTF-8 path"); let tempdir = copy_directory_to_tempdir(&sncast_example_dir); - let accounts_json_path = prepare_accounts_file(&tempdir); - update_scarb_toml_dependencies(&tempdir).unwrap(); - let contracts = setup_contracts_map(&accounts_json_path, &tempdir); + let contracts = setup_contracts_map(&tempdir); for snippet in &snippets { if snippet.config.ignored.unwrap_or(false) { @@ -181,16 +156,15 @@ fn test_docs_snippets() { // remove "sncast" from the args args.remove(0); - args.insert(0, "--accounts-file"); - args.insert(1, accounts_json_path.as_str()); - if let Some(contract_name) = &snippet.config.contract_name { let contract = contracts.get(contract_name).expect("Contract not found"); - // In case of invoke/call/verify, we need to replace contract-address in snippet's args with the one from prepared contract + // In case of invoke/call/verify, we need to replace contract address insnippet's + // args with prepared contract's address if is_command(&args, &["invoke", "call", "verify"]) { swap_next_element(&mut args, "--contract-address", &contract.contract_address); - // In case of deploy, we need to replace class-hash in snippet's args with the one from prepared contract + // Similarly for deploy, we need to replace class-hash in snippet's + // args with prepared contract's class-hash } else if is_command(&args, &["deploy"]) { swap_next_element(&mut args, "--class-hash", &contract.class_hash); } From 88e0a6dd8748e9b46dd705eced512b5619ab3f0e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:29:38 +0100 Subject: [PATCH 155/183] Minor adjustments to snippets outputs --- docs/src/starknet/account.md | 2 +- docs/src/starknet/declare.md | 4 ++-- docs/src/starknet/deploy.md | 12 ++++++------ docs/src/starknet/invoke.md | 4 ++-- docs/src/starknet/show_config.md | 2 +- docs/src/starknet/sncast-overview.md | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 5cc61e2661..1215fa73ab 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -40,7 +40,7 @@ max_fee: [..] message: Account successfully created. Prefund generated address with at least STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand. To see account creation details, visit: -account: [..] +account: https://starkscan.co/search/contract/[..] ```

diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index c132c71e43..8fae0789df 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -35,8 +35,8 @@ class_hash: [..] transaction_hash: [..] To see declaration details, visit: -class: [..] -transaction: [..] +class: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 07da62873d..e4e5d2d1b1 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -33,8 +33,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: [..] -transaction: [..] +contract: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

@@ -75,8 +75,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: [..] -transaction: [..] +contract: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

@@ -107,8 +107,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: [..] -transaction: [..] +contract: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 8a6de0cdf1..33ffa50f21 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -40,7 +40,7 @@ command: invoke transaction_hash: [..] To see invocation details, visit: -transaction: [..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -71,6 +71,6 @@ command: invoke transaction_hash: [..] To see invocation details, visit: -transaction: [..] +transaction: https://sepolia.starkscan.co/tx/[..] ```
diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index 9110159822..3f24db162c 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -26,7 +26,7 @@ $ sncast \ command: show-config account: user0 chain_id: alpha-sepolia -rpc_url: http://127.0.0.1:5055 +rpc_url: http://127.0.0.1:5055/rpc ```

\ No newline at end of file diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index d2718788aa..11b1f138be 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -112,8 +112,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: [..] -transaction: [..] +contract: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

From 32535d9cd3cc80cc2f5d19d4e2a8545890c8bee9 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 18:37:36 +0100 Subject: [PATCH 156/183] Fix scarb formatting --- .../listings/sncast_example/src/constructor_contract.cairo | 7 ++----- docs/listings/sncast_example/src/lib.cairo | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/listings/sncast_example/src/constructor_contract.cairo b/docs/listings/sncast_example/src/constructor_contract.cairo index bf3c4198a0..dc6fd6d810 100644 --- a/docs/listings/sncast_example/src/constructor_contract.cairo +++ b/docs/listings/sncast_example/src/constructor_contract.cairo @@ -1,11 +1,8 @@ #[starknet::contract] pub mod ConstructorContract { - #[storage] struct Storage {} - #[constructor] - fn constructor(ref self: ContractState, x: felt252, y: felt252, z: felt252) { - - } + #[constructor] + fn constructor(ref self: ContractState, x: felt252, y: felt252, z: felt252) {} } diff --git a/docs/listings/sncast_example/src/lib.cairo b/docs/listings/sncast_example/src/lib.cairo index 3bae48b43f..7918344a71 100644 --- a/docs/listings/sncast_example/src/lib.cairo +++ b/docs/listings/sncast_example/src/lib.cairo @@ -1,3 +1,3 @@ pub mod hello_starknet; pub mod data_transformer_contract; -pub mod constructor_contract; \ No newline at end of file +pub mod constructor_contract; From 47116650306a62186fafc761d9b98e9a367ebcb0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 19:57:10 +0100 Subject: [PATCH 157/183] Fix failing tests --- crates/docs/src/utils.rs | 4 +- .../sncast/tests/docs_snippets/validation.rs | 39 ++++++++++++++++--- docs/listings/sncast_example/snfoundry.toml | 4 +- docs/src/starknet/account.md | 2 +- docs/src/starknet/deploy.md | 12 +++--- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 34b82889f2..1cb5f7fc41 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -41,14 +41,14 @@ pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { pub fn print_skipped_snippet_message(snippet: &Snippet) { println!( - "Ignoring {} docs snippet, file: {} :{}:1", + "Ignoring {} docs snippet, file: {}:{}:1", snippet.snippet_type.as_str(), snippet.file_path, snippet.line_start, ); } -fn get_canonical_path(relative_path: &str) -> Result> { +pub fn get_canonical_path(relative_path: &str) -> Result> { Ok(Utf8PathBuf::from_str(relative_path)? .canonicalize_utf8()? .to_string() diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index c30d45c89b..9224305fa9 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::str::FromStr; +use std::fs; use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; @@ -10,7 +10,6 @@ use docs::utils::{ use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; use regex::Regex; use shared::test_utils::output_assert::{assert_stdout_contains, AsOutput}; -use sncast::helpers::constants::DEFAULT_ACCOUNTS_FILE; use tempfile::TempDir; use crate::helpers::constants::URL; @@ -22,6 +21,28 @@ struct Contract { contract_address: String, } +fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { + // Account from predeployed accounts in starknet-devnet-rs + let accounts = r#" + { + "alpha-sepolia": { + "user0": { + "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", + "deployed": true, + "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", + "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", + "type": "open_zeppelin" + } + } + } + "#; + + let accounts_path = temp.path().join("accounts.json"); + fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); + + Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") +} + fn declare_and_deploy_contract( contract_name: &str, accounts_file: &str, @@ -86,7 +107,10 @@ fn declare_and_deploy_contract( } } -fn setup_contracts_map(tempdir: &TempDir) -> HashMap { +fn setup_contracts_map( + tempdir: &TempDir, + account_json_path: &Utf8PathBuf, +) -> HashMap { let mut contracts: HashMap = HashMap::new(); let contract_names = [ "HelloStarknet", @@ -94,10 +118,9 @@ fn setup_contracts_map(tempdir: &TempDir) -> HashMap { "ConstructorContract", ]; - let accounts_json_path = Utf8PathBuf::from_str(DEFAULT_ACCOUNTS_FILE).unwrap(); for contract_name in &contract_names { let contract = - declare_and_deploy_contract(contract_name, accounts_json_path.as_str(), tempdir); + declare_and_deploy_contract(contract_name, account_json_path.as_str(), tempdir); contracts.insert((*contract_name).to_string(), contract); } @@ -139,10 +162,11 @@ fn test_docs_snippets() { Utf8PathBuf::from_path_buf(root_dir_path.join("docs/listings/sncast_example")) .expect("Invalid UTF-8 path"); let tempdir = copy_directory_to_tempdir(&sncast_example_dir); + let accounts_json_path = prepare_accounts_file(&tempdir); update_scarb_toml_dependencies(&tempdir).unwrap(); - let contracts = setup_contracts_map(&tempdir); + let contracts = setup_contracts_map(&tempdir, &accounts_json_path); for snippet in &snippets { if snippet.config.ignored.unwrap_or(false) { @@ -156,6 +180,9 @@ fn test_docs_snippets() { // remove "sncast" from the args args.remove(0); + args.insert(0, "--accounts-file"); + args.insert(1, accounts_json_path.as_str()); + if let Some(contract_name) = &snippet.config.contract_name { let contract = contracts.get(contract_name).expect("Contract not found"); diff --git a/docs/listings/sncast_example/snfoundry.toml b/docs/listings/sncast_example/snfoundry.toml index f27e809db1..3a71b60787 100644 --- a/docs/listings/sncast_example/snfoundry.toml +++ b/docs/listings/sncast_example/snfoundry.toml @@ -1,9 +1,9 @@ [sncast.default] account = "user0" accounts-file = "accounts.json" -url = "http://127.0.0.1:5055" +url = "http://127.0.0.1:5055/rpc" [sncast.myprofile] account = "user0" accounts-file = "accounts.json" -url = "http://127.0.0.1:5055" \ No newline at end of file +url = "http://127.0.0.1:5055/rpc" \ No newline at end of file diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 1215fa73ab..76b2008ead 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -40,7 +40,7 @@ max_fee: [..] message: Account successfully created. Prefund generated address with at least STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand. To see account creation details, visit: -account: https://starkscan.co/search/contract/[..] +account: https://sepolia.starkscan.co/contract/[..] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index e4e5d2d1b1..cee1b0d614 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -33,8 +33,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/[..] -transaction: https://starkscan.co/search/[..] +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -75,8 +75,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/[..] -transaction: https://starkscan.co/search/[..] +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -107,8 +107,8 @@ contract_address: [..] transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/[..] -transaction: https://starkscan.co/search/[..] +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

From b844f2d5193d69a88214e619617d63e86ff4378c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 20:09:39 +0100 Subject: [PATCH 158/183] Rename util functions --- crates/docs/src/utils.rs | 4 ++-- crates/forge/tests/e2e/docs_snippets_validation.rs | 7 ++++--- crates/sncast/tests/docs_snippets/validation.rs | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 1cb5f7fc41..2601680b02 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -29,7 +29,7 @@ pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &st ); } -pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { +pub fn print_snippets_validation_summary(snippets: &[Snippet], tool_name: &str) { let validated_snippets_count = snippets .iter() .filter(|snippet| !snippet.config.ignored.unwrap_or(false)) @@ -39,7 +39,7 @@ pub fn print_success_message(snippets: &[Snippet], tool_name: &str) { println!("Finished validation of {tool_name} docs snippets\nValidated: {validated_snippets_count}, Ignored: {ignored_snippets_count}"); } -pub fn print_skipped_snippet_message(snippet: &Snippet) { +pub fn print_ignored_snippet_message(snippet: &Snippet) { println!( "Ignoring {} docs snippet, file: {}:{}:1", snippet.snippet_type.as_str(), diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 1fb1666f89..130140f714 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,7 +1,8 @@ use clap::Parser; use docs::snippet::SnippetType; use docs::utils::{ - assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, + assert_valid_snippet, get_nth_ancestor, print_ignored_snippet_message, + print_snippets_validation_summary, }; use docs::validation::extract_snippets_from_directory; use forge::Cli; @@ -24,7 +25,7 @@ fn test_docs_snippets() { let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); if snippet.config.ignored.unwrap_or(false) { - print_skipped_snippet_message(snippet); + print_ignored_snippet_message(snippet); continue; } @@ -55,5 +56,5 @@ fn test_docs_snippets() { } } - print_success_message(&snippets, snippet_type.as_str()); + print_snippets_validation_summary(&snippets, snippet_type.as_str()); } diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 9224305fa9..3f8aab3d22 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -4,7 +4,7 @@ use std::fs; use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ - get_nth_ancestor, print_skipped_snippet_message, print_success_message, + get_nth_ancestor, print_ignored_snippet_message, print_snippets_validation_summary, update_scarb_toml_dependencies, }; use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; @@ -170,7 +170,7 @@ fn test_docs_snippets() { for snippet in &snippets { if snippet.config.ignored.unwrap_or(false) { - print_skipped_snippet_message(snippet); + print_ignored_snippet_message(snippet); continue; } @@ -205,5 +205,5 @@ fn test_docs_snippets() { } } - print_success_message(&snippets, snippet_type.as_str()); + print_snippets_validation_summary(&snippets, snippet_type.as_str()); } From 7343dfd51a645511fc358d99d5afeadfff519aa9 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 20:15:35 +0100 Subject: [PATCH 159/183] Fix newline --- docs/listings/sncast_example/snfoundry.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/listings/sncast_example/snfoundry.toml b/docs/listings/sncast_example/snfoundry.toml index 3a71b60787..402f14a63e 100644 --- a/docs/listings/sncast_example/snfoundry.toml +++ b/docs/listings/sncast_example/snfoundry.toml @@ -6,4 +6,4 @@ url = "http://127.0.0.1:5055/rpc" [sncast.myprofile] account = "user0" accounts-file = "accounts.json" -url = "http://127.0.0.1:5055/rpc" \ No newline at end of file +url = "http://127.0.0.1:5055/rpc" From 0dadcae88d711d601d8168186db4958111d22197 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 20:39:05 +0100 Subject: [PATCH 160/183] Adjust urls in snippets outputs --- docs/src/starknet/account.md | 2 +- docs/src/starknet/deploy.md | 4 ++-- docs/src/starknet/multicall.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 76b2008ead..c1ba0892d6 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -77,7 +77,7 @@ command: account deploy transaction_hash: [..] To see invocation details, visit: -transaction: [..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index cee1b0d614..98049df90b 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -135,7 +135,7 @@ contract_address: [..] transaction_hash: [..] Details: -contract: [..] -transaction: [..] +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```
diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 25b043cdad..c365ee16d2 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -60,7 +60,7 @@ command: multicall transaction_hash: [..] To see invocation details, visit: -transaction: [..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

From a4e2d91fef9eec0dda8f19052bcdd23741a3c2ac Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Fri, 29 Nov 2024 20:39:18 +0100 Subject: [PATCH 161/183] Fix failing `test_run_script_display_debug_traits` --- crates/sncast/tests/e2e/script/general.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/sncast/tests/e2e/script/general.rs b/crates/sncast/tests/e2e/script/general.rs index 5b82923645..637205b53b 100644 --- a/crates/sncast/tests/e2e/script/general.rs +++ b/crates/sncast/tests/e2e/script/general.rs @@ -238,13 +238,13 @@ async fn test_run_script_display_debug_traits() { test declare_nonce: [..] debug declare_nonce: [..] - Transaction hash = 0x[..] + Transaction hash: 0x[..] declare_result: class_hash: [..], transaction_hash: [..] debug declare_result: DeclareResult::Success(DeclareTransactionResult { class_hash: [..], transaction_hash: [..] }) - Transaction hash = 0x[..] + Transaction hash: 0x[..] deploy_result: contract_address: [..], transaction_hash: [..] debug deploy_result: DeployResult { contract_address: [..], transaction_hash: [..] } - Transaction hash = 0x[..] + Transaction hash: 0x[..] invoke_result: [..] debug invoke_result: InvokeResult { transaction_hash: [..] } call_result: [2] From 08430728a392355f255ab94924277ed9595a2292 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sat, 30 Nov 2024 23:01:24 +0100 Subject: [PATCH 162/183] Code cleanup --- crates/docs/src/snippet.rs | 5 ++--- crates/forge/tests/e2e/docs_snippets_validation.rs | 6 +++--- crates/sncast/tests/docs_snippets/validation.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 535f054f9e..fcb0bf7bbe 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -33,7 +33,7 @@ impl SnippetType { #[must_use] pub fn get_re(&self) -> &'static Regex { // The regex pattern is used to match the snippet, its config and the output. Example: - // + // // ```shell // $ snforge or sncast command with args... // ``` @@ -44,11 +44,10 @@ impl SnippetType { // ``` //
- // Regex::new(&pattern).unwrap() match self.as_str() { "snforge" => &RE_SNFORGE, "sncast" => &RE_SNCAST, - _ => panic!("Regex for snippet type {} not found", self.as_str()), + _ => panic!("Regex for {} not found", self.as_str()), } } } diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index 130140f714..bd147c3922 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -21,14 +21,14 @@ fn test_docs_snippets() { .expect("Failed to extract command snippets"); for snippet in &snippets { - let args = snippet.to_command_args(); - let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); - if snippet.config.ignored.unwrap_or(false) { print_ignored_snippet_message(snippet); continue; } + let args = snippet.to_command_args(); + let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); + let parse_result = Cli::try_parse_from(args.clone()); let err_message = if let Err(err) = &parse_result { err.to_string() diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 3f8aab3d22..565e7603c6 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -141,7 +141,7 @@ fn is_command(args: &[&str], commands: &[&str]) -> bool { #[test] fn test_docs_snippets() { - let root_dir_path: std::path::PathBuf = get_nth_ancestor(2); + let root_dir_path = get_nth_ancestor(2); let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); From 00fd1dd6e36ded4359708faa819cfb930cd1c98e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sat, 30 Nov 2024 23:41:15 +0100 Subject: [PATCH 163/183] Add todos --- crates/sncast/README.md | 4 ++++ docs/src/starknet/account.md | 3 +++ 2 files changed, 7 insertions(+) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 39df068a6f..70498255d3 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -31,6 +31,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract + ```shell $ sncast --account user0 \ @@ -52,6 +53,7 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast declare \ @@ -73,6 +75,7 @@ transaction_hash: [..] ### Deploy a contract + ```shell $ sncast --account user0 \ @@ -94,6 +97,7 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast deploy \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index c1ba0892d6..b9312f2710 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -59,6 +59,7 @@ You can do it both by sending tokens from another starknet account or by bridgin >![image](images/starknet-faucet-sepolia.png) #### Deploy account with the `sncast account deploy` command + ```shell $ sncast \ @@ -188,6 +189,7 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > 💡 **Info** > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. + ```shell $ sncast \ @@ -203,6 +205,7 @@ $ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. + ```shell $ sncast \ From 221d53bd86f8eb3a2992498e7b4b4961eeb7ad84 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 00:42:59 +0100 Subject: [PATCH 164/183] Update data transformer contract --- .../src/data_transformer_contract.cairo | 54 +++++++++++++------ .../sncast_example/tests/test_contract.cairo | 14 ++++- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/docs/listings/sncast_example/src/data_transformer_contract.cairo b/docs/listings/sncast_example/src/data_transformer_contract.cairo index 01950b44c1..794dedda3d 100644 --- a/docs/listings/sncast_example/src/data_transformer_contract.cairo +++ b/docs/listings/sncast_example/src/data_transformer_contract.cairo @@ -1,35 +1,27 @@ -#[derive(Drop)] +#[derive(Serde, Drop)] pub struct SimpleStruct { a: felt252 } -#[derive(Drop)] +#[derive(Serde, Drop)] pub struct NestedStructWithField { a: SimpleStruct, b: felt252 } -#[derive(Drop)] +#[derive(Serde, Drop)] pub enum Enum { One: (), Two: u128, Three: NestedStructWithField } - -#[starknet::contract] -pub mod DataTransformerContract { - use super::{NestedStructWithField, Enum}; - - #[storage] - struct Storage {} - - fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) {} - - fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) {} - +#[starknet::interface] +pub trait IDataTransformerContract { + fn tuple_fn(self: @TContractState, a: (felt252, u8, Enum)); + fn nested_struct_fn(self: @TContractState, a: NestedStructWithField); fn complex_fn( - self: ContractState, + self: @TContractState, arr: Array>, one: u8, two: i8, @@ -37,5 +29,33 @@ pub mod DataTransformerContract { four: (felt252, u32), five: bool, six: u256 - ) {} + ); +} + + +#[starknet::contract] +pub mod DataTransformerContract { + use super::{NestedStructWithField, Enum}; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + impl DataTransformerContractImpl of super::IDataTransformerContract { + fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) {} + + fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) {} + + fn complex_fn( + self: @ContractState, + arr: Array>, + one: u8, + two: i8, + three: ByteArray, + four: (felt252, u32), + five: bool, + six: u256 + ) {} + } + } diff --git a/docs/listings/sncast_example/tests/test_contract.cairo b/docs/listings/sncast_example/tests/test_contract.cairo index 583fd4558f..93c3edf9b7 100644 --- a/docs/listings/sncast_example/tests/test_contract.cairo +++ b/docs/listings/sncast_example/tests/test_contract.cairo @@ -6,7 +6,10 @@ use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcher; use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcherTrait; use hello_starknet::hello_starknet::IHelloStarknetDispatcher; use hello_starknet::hello_starknet::IHelloStarknetDispatcherTrait; - +use hello_starknet::data_transformer_contract::DataTransformerContractSafeDispatcher; +use hello_starknet::data_transformer_contract::DataTransformerContractSafeDispatcherTrait; +use hello_starknet::data_transformer_contract::DataTransformerContractDispatcher; +use hello_starknet::data_transformer_contract::DataTransformerContractDispatcherTrait; fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); @@ -45,3 +48,12 @@ fn test_cannot_increase_balance_with_zero_value() { } }; } + +#[test] +fn test_increase_balance() { + let contract_address = deploy_contract("DataTransformerContract"); + + let dispatcher = DataTransformerContractDispatcher { contract_address }; + + dispatcher.complex_fn(); +} \ No newline at end of file From 1d25d80ed58939e9f7dee1e002ac12d5c79a3964 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 00:43:34 +0100 Subject: [PATCH 165/183] Unignore data transformer snippets --- docs/src/starknet/calldata-transformation.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 56421776ea..c6e9e79730 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -80,7 +80,7 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: - + ```shell $ sncast call \ --url http://127.0.0.1:5055 \ @@ -126,7 +126,7 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: - + ```shell $ sncast call \ --url http://127.0.0.1:5055 \ @@ -150,7 +150,7 @@ $ sncast call \ Alternatively, you can continue the single quote for multiple lines. - + ```shell $ sncast call \ --url http://127.0.0.1:5055 \ @@ -173,7 +173,7 @@ true, 2. `nested_struct_fn` - struct nesting: - + ```shell $ sncast call \ --url http://127.0.0.1:5055 \ From 2c09097e37d0437bd1b9bb6c89cfa7b16ec5d17e Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 13:34:49 +0100 Subject: [PATCH 166/183] Rename `sncast_example` to `hello_sncast` --- crates/sncast/README.md | 20 +++---- .../sncast/tests/docs_snippets/validation.rs | 8 +-- .../Scarb.toml | 2 +- .../snfoundry.toml | 0 .../src/constructor_contract.cairo | 0 .../src/data_transformer_contract.cairo | 0 .../src/hello_sncast.cairo} | 6 +- .../src/lib.cairo | 2 +- .../sncast_example/tests/test_contract.cairo | 59 ------------------- docs/src/projects/configuration.md | 4 +- docs/src/starknet/calldata-transformation.md | 7 +-- docs/src/starknet/declare.md | 4 +- docs/src/starknet/deploy.md | 6 +- docs/src/starknet/invoke.md | 2 +- docs/src/starknet/sncast-overview.md | 2 +- docs/src/starknet/verify.md | 4 +- 16 files changed, 33 insertions(+), 93 deletions(-) rename docs/listings/{sncast_example => hello_sncast}/Scarb.toml (94%) rename docs/listings/{sncast_example => hello_sncast}/snfoundry.toml (100%) rename docs/listings/{sncast_example => hello_sncast}/src/constructor_contract.cairo (100%) rename docs/listings/{sncast_example => hello_sncast}/src/data_transformer_contract.cairo (100%) rename docs/listings/{sncast_example/src/hello_starknet.cairo => hello_sncast/src/hello_sncast.cairo} (85%) rename docs/listings/{sncast_example => hello_sncast}/src/lib.cairo (73%) delete mode 100644 docs/listings/sncast_example/tests/test_contract.cairo diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 70498255d3..6bf04be2f1 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,11 +32,11 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract - + ```shell $ sncast --account user0 \ declare \ - --contract-name HelloStarknet \ + --contract-name HelloSncast \ --fee-token strk ``` @@ -54,10 +54,10 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast declare \ - --contract-name HelloStarknet \ + --contract-name HelloSncast \ --fee-token strk ``` @@ -76,7 +76,7 @@ transaction_hash: [..] ### Deploy a contract - + ```shell $ sncast --account user0 \ deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ @@ -98,7 +98,7 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast deploy \ --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ @@ -120,7 +120,7 @@ transaction_hash: [..] ### Invoke a contract - + ```shell $ sncast \ --account user0 \ @@ -148,7 +148,7 @@ transaction: https://sepolia.starkscan.co/tx/[..] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast invoke \ --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ @@ -173,7 +173,7 @@ transaction: https://sepolia.starkscan.co/tx/[..] ### Call a contract - + ```shell $ sncast \ call \ @@ -196,7 +196,7 @@ response: [0x6] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast call \ --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 565e7603c6..46031b2e3b 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -113,7 +113,7 @@ fn setup_contracts_map( ) -> HashMap { let mut contracts: HashMap = HashMap::new(); let contract_names = [ - "HelloStarknet", + "HelloSncast", "DataTransformerContract", "ConstructorContract", ]; @@ -158,10 +158,10 @@ fn test_docs_snippets() { .chain(readme_snippets) .collect::>(); - let sncast_example_dir = - Utf8PathBuf::from_path_buf(root_dir_path.join("docs/listings/sncast_example")) + let hello_sncast_dir = + Utf8PathBuf::from_path_buf(root_dir_path.join("docs/listings/hello_sncast")) .expect("Invalid UTF-8 path"); - let tempdir = copy_directory_to_tempdir(&sncast_example_dir); + let tempdir = copy_directory_to_tempdir(&hello_sncast_dir); let accounts_json_path = prepare_accounts_file(&tempdir); update_scarb_toml_dependencies(&tempdir).unwrap(); diff --git a/docs/listings/sncast_example/Scarb.toml b/docs/listings/hello_sncast/Scarb.toml similarity index 94% rename from docs/listings/sncast_example/Scarb.toml rename to docs/listings/hello_sncast/Scarb.toml index 1a51433a8a..b76dc6a713 100644 --- a/docs/listings/sncast_example/Scarb.toml +++ b/docs/listings/hello_sncast/Scarb.toml @@ -1,5 +1,5 @@ [package] -name = "hello_starknet" +name = "hello_sncast" version = "0.1.0" edition = "2023_11" diff --git a/docs/listings/sncast_example/snfoundry.toml b/docs/listings/hello_sncast/snfoundry.toml similarity index 100% rename from docs/listings/sncast_example/snfoundry.toml rename to docs/listings/hello_sncast/snfoundry.toml diff --git a/docs/listings/sncast_example/src/constructor_contract.cairo b/docs/listings/hello_sncast/src/constructor_contract.cairo similarity index 100% rename from docs/listings/sncast_example/src/constructor_contract.cairo rename to docs/listings/hello_sncast/src/constructor_contract.cairo diff --git a/docs/listings/sncast_example/src/data_transformer_contract.cairo b/docs/listings/hello_sncast/src/data_transformer_contract.cairo similarity index 100% rename from docs/listings/sncast_example/src/data_transformer_contract.cairo rename to docs/listings/hello_sncast/src/data_transformer_contract.cairo diff --git a/docs/listings/sncast_example/src/hello_starknet.cairo b/docs/listings/hello_sncast/src/hello_sncast.cairo similarity index 85% rename from docs/listings/sncast_example/src/hello_starknet.cairo rename to docs/listings/hello_sncast/src/hello_sncast.cairo index 678747e70b..45772b6e65 100644 --- a/docs/listings/sncast_example/src/hello_starknet.cairo +++ b/docs/listings/hello_sncast/src/hello_sncast.cairo @@ -1,19 +1,19 @@ #[starknet::interface] -pub trait IHelloStarknet { +pub trait IHelloSncast { fn increase_balance(ref self: TContractState, amount: felt252); fn get_balance(self: @TContractState) -> felt252; fn sum_numbers(ref self: TContractState, a: felt252, b: felt252, c: felt252) -> felt252; } #[starknet::contract] -mod HelloStarknet { +mod HelloSncast { #[storage] struct Storage { balance: felt252, } #[abi(embed_v0)] - impl HelloStarknetImpl of super::IHelloStarknet { + impl HelloSncastImpl of super::IHelloSncast { fn increase_balance(ref self: ContractState, amount: felt252) { assert(amount != 0, 'Amount cannot be 0'); self.balance.write(self.balance.read() + amount); diff --git a/docs/listings/sncast_example/src/lib.cairo b/docs/listings/hello_sncast/src/lib.cairo similarity index 73% rename from docs/listings/sncast_example/src/lib.cairo rename to docs/listings/hello_sncast/src/lib.cairo index 7918344a71..b282cbfd57 100644 --- a/docs/listings/sncast_example/src/lib.cairo +++ b/docs/listings/hello_sncast/src/lib.cairo @@ -1,3 +1,3 @@ -pub mod hello_starknet; +pub mod hello_sncast; pub mod data_transformer_contract; pub mod constructor_contract; diff --git a/docs/listings/sncast_example/tests/test_contract.cairo b/docs/listings/sncast_example/tests/test_contract.cairo deleted file mode 100644 index 93c3edf9b7..0000000000 --- a/docs/listings/sncast_example/tests/test_contract.cairo +++ /dev/null @@ -1,59 +0,0 @@ -use starknet::ContractAddress; - -use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; - -use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcher; -use hello_starknet::hello_starknet::IHelloStarknetSafeDispatcherTrait; -use hello_starknet::hello_starknet::IHelloStarknetDispatcher; -use hello_starknet::hello_starknet::IHelloStarknetDispatcherTrait; -use hello_starknet::data_transformer_contract::DataTransformerContractSafeDispatcher; -use hello_starknet::data_transformer_contract::DataTransformerContractSafeDispatcherTrait; -use hello_starknet::data_transformer_contract::DataTransformerContractDispatcher; -use hello_starknet::data_transformer_contract::DataTransformerContractDispatcherTrait; -fn deploy_contract(name: ByteArray) -> ContractAddress { - let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - contract_address -} - -#[test] -fn test_increase_balance() { - let contract_address = deploy_contract("HelloStarknet"); - - let dispatcher = IHelloStarknetDispatcher { contract_address }; - - let balance_before = dispatcher.get_balance(); - assert(balance_before == 0, 'Invalid balance'); - - dispatcher.increase_balance(42); - - let balance_after = dispatcher.get_balance(); - assert(balance_after == 42, 'Invalid balance'); -} - -#[test] -#[feature("safe_dispatcher")] -fn test_cannot_increase_balance_with_zero_value() { - let contract_address = deploy_contract("HelloStarknet"); - - let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; - - let balance_before = safe_dispatcher.get_balance().unwrap(); - assert(balance_before == 0, 'Invalid balance'); - - match safe_dispatcher.increase_balance(0) { - Result::Ok(_) => core::panic_with_felt252('Should have panicked'), - Result::Err(panic_data) => { - assert(*panic_data.at(0) == 'Amount cannot be 0', *panic_data.at(0)); - } - }; -} - -#[test] -fn test_increase_balance() { - let contract_address = deploy_contract("DataTransformerContract"); - - let dispatcher = DataTransformerContractDispatcher { contract_address }; - - dispatcher.complex_fn(); -} \ No newline at end of file diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 9b7f00263f..b808213c35 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -49,7 +49,7 @@ defined in the profile. > Not all parameters have to be present in the configuration - you can choose to include only some of them and supply > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. - + ```shell $ sncast --profile myprofile \ call \ @@ -87,7 +87,7 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. - + ```shell $ sncast call \ --contract-address 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index c6e9e79730..1981785cf4 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -79,14 +79,13 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: - ```shell $ sncast call \ --url http://127.0.0.1:5055 \ --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ - --arguments '0x10, 3, data_transformer_contract::Enum::One' \ + --arguments '(0x10, 3, hello_sncast::data_transformer_contract::Enum::One)' \ --block-id latest ``` @@ -180,8 +179,8 @@ $ sncast call \ --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function nested_struct_fn \ --arguments \ -'data_transformer_contract::NestedStructWithField {'\ -' a: data_transformer_contract::SimpleStruct { a: 10 },'\ +'hello_sncast::data_transformer_contract::NestedStructWithField {'\ +' a: hello_sncast::data_transformer_contract::SimpleStruct { a: 10 },'\ ' b: 12'\ '}'\ --block-id latest diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 8fae0789df..4746d216cd 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -17,13 +17,13 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: - + ```shell $ sncast --account user0 \ declare \ --url http://127.0.0.1:5055 \ --fee-token strk \ - --contract-name HelloStarknet + --contract-name HelloSncast ```
diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index 98049df90b..ddffcc6c07 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -14,7 +14,7 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: - + ```shell $ sncast \ --account user0 \ @@ -90,7 +90,7 @@ transaction: https://sepolia.starkscan.co/tx/[..] Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. - + ```shell $ sncast deploy \ --fee-token strk \ @@ -118,7 +118,7 @@ transaction: https://sepolia.starkscan.co/tx/[..] Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. - + ```shell $ sncast deploy \ --fee-token strk \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 33ffa50f21..d04e81a951 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -55,7 +55,7 @@ transaction: https://sepolia.starkscan.co/tx/[..] Not every function accepts parameters. Here is how to call it. - + ```shell $ sncast invoke \ --fee-token strk \ diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 11b1f138be..f6ab798dff 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -81,7 +81,7 @@ Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appe Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. - + ```shell $ sncast --account user0 \ --wait \ diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 4cd116d831..8de44190a3 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -23,12 +23,12 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: - + ```shell $ sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ - --contract-name HelloStarknet \ + --contract-name HelloSncast \ --verifier walnut \ --network sepolia ``` From 4902f7572272cb542ba73b551a96b334548b4a06 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 13:57:36 +0100 Subject: [PATCH 167/183] Add todos --- docs/src/starknet/declare.md | 1 + docs/src/starknet/invoke.md | 2 +- docs/src/starknet/sncast-overview.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 4746d216cd..a3990bedf5 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -17,6 +17,7 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: + ```shell $ sncast --account user0 \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index d04e81a951..f8356cb5a2 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -16,7 +16,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example - + ```shell $ sncast \ diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index f6ab798dff..796957e17e 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -29,6 +29,7 @@ You can, however, overwrite their values by supplying them as flags directly to Let's use `sncast` to call a contract's function: + ```shell $ sncast call \ From b4562b7638e2be21a2fce8b46bddaa6a85db8ad2 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 14:06:04 +0100 Subject: [PATCH 168/183] Embed `DataTransformerContract` code --- docs/src/starknet/calldata-transformation.md | 41 +------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 1981785cf4..e060f8766a 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -8,46 +8,7 @@ It's declared on Sepolia network with class hash `0x02a9b456118a86070a8c116c41b0 It has a few methods accepting different types and items defined in its namespace: ```rust -// data_transformer_contract/src/lib.cairo - -pub struct SimpleStruct { - a: felt252 -} - -pub struct NestedStructWithField { - a: SimpleStruct, - b: felt252 -} - -pub enum Enum { - One: (), - Two: u128, - Three: NestedStructWithField -} - -#[starknet::contract] -pub mod DataTransformerContract { - /* ... */ - - use super::*; - - fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) { ... } - - fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) { ... } - - fn complex_fn( - self: @ContractState, - arr: Array>, - one: u8, - two: i16, - three: ByteArray, - four: (felt252, u32), - five: bool, - six: u256 - ) { - ... - } -} +{{#include ../../listings/hello_sncast/src/data_transformer_contract.cairo}} ``` A default form of calldata passed to commands requiring it is a series of hex-encoded felts: From a8532bb4db83f0c7e17f7888c95c093bc532a684 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 14:15:52 +0100 Subject: [PATCH 169/183] Fix scarb formatting --- docs/listings/hello_sncast/src/data_transformer_contract.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/listings/hello_sncast/src/data_transformer_contract.cairo b/docs/listings/hello_sncast/src/data_transformer_contract.cairo index 794dedda3d..aa5bf49624 100644 --- a/docs/listings/hello_sncast/src/data_transformer_contract.cairo +++ b/docs/listings/hello_sncast/src/data_transformer_contract.cairo @@ -57,5 +57,4 @@ pub mod DataTransformerContract { six: u256 ) {} } - } From 8705e4d57df996427057203e965231b6853ab731 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 15:14:27 +0100 Subject: [PATCH 170/183] Update logic of getting contract name --- crates/sncast/README.md | 4 ++-- crates/sncast/tests/docs_snippets/validation.rs | 13 +++++++++++-- docs/src/starknet/declare.md | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 6bf04be2f1..601de2baa5 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -32,7 +32,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract - + ```shell $ sncast --account user0 \ declare \ @@ -54,7 +54,7 @@ transaction_hash: [..] With arguments taken from `snfoundry.toml` file (default profile name): - + ```shell $ sncast declare \ --contract-name HelloSncast \ diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 46031b2e3b..62e3311360 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -135,6 +135,11 @@ fn swap_next_element<'a>(args: &mut [&'a str], target: &str, new_value: &'a str) } } +fn get_contract_name_from_args(args: &[&str]) -> Option { + let index = args.iter().position(|&x| x == "--contract-name")?; + args.get(index + 1).copied().map(String::from) +} + fn is_command(args: &[&str], commands: &[&str]) -> bool { commands.iter().any(|&cmd| args.contains(&cmd)) } @@ -183,8 +188,12 @@ fn test_docs_snippets() { args.insert(0, "--accounts-file"); args.insert(1, accounts_json_path.as_str()); - if let Some(contract_name) = &snippet.config.contract_name { - let contract = contracts.get(contract_name).expect("Contract not found"); + if let Some(contract_name) = + get_contract_name_from_args(&args).or_else(|| snippet.config.contract_name.clone()) + { + let contract = contracts + .get(contract_name.as_str()) + .unwrap_or_else(|| panic!("Contract {contract_name} not found")); // In case of invoke/call/verify, we need to replace contract address insnippet's // args with prepared contract's address diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index a3990bedf5..cf297917cb 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -18,7 +18,7 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: - + ```shell $ sncast --account user0 \ declare \ From 345b86cb94987c3f4d7cf3c8989f9ae3db269877 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Sun, 1 Dec 2024 18:20:13 +0100 Subject: [PATCH 171/183] Add todo --- docs/src/starknet/account.md | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index b9312f2710..2f09421bc6 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -108,23 +108,36 @@ $ sncast \ ### [`account list`](../appendix/sncast/account/list.md) List all accounts saved in `accounts file`, grouped based on the networks they are defined on. + + ```shell $ sncast account list ``` +
+Output: + +```shell +Available accounts (at [..]): +- new_account: + network: alpha-sepolia + public key: [..] + address: [..] + salt: [..] + class hash: [..] + deployed: false + legacy: false + type: OpenZeppelin + +- user0: + network: alpha-sepolia + public key: 0x48234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac + address: 0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d + deployed: true + type: OpenZeppelin ``` -Available accounts (at /Users//.starknet_accounts/starknet_open_zeppelin_accounts.json): -- user0 -public key: 0x2f91ed13f8f0f7d39b942c80bfcd3d0967809d99e0cc083606cbe59033d2b39 -network: alpha-sepolia -address: 0x4f5f24ceaae64434fa2bc2befd08976b51cf8f6a5d8257f7ec3616f61de263a -type: OpenZeppelin -deployed: false -legacy: false - -- user1 -[...] -``` +
+
You can specify a custom location for the accounts file with the `--accounts-file` or `-f` flag. There is also possibility to show private keys with the `--display-private-keys` or `-p` flag. From 2ab3b69a7177cfc1059587934a6e29693c8ce7b0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 2 Dec 2024 19:01:06 +0100 Subject: [PATCH 172/183] Update regex err messages --- crates/docs/src/snippet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index fcb0bf7bbe..c1e4f12de2 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -4,11 +4,11 @@ use regex::Regex; use serde::{Deserialize, Serialize}; static RE_SNCAST: LazyLock = LazyLock::new(|| { - Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psncast .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for normalizing loop function names") + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psncast .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for sncast snippet") }); static RE_SNFORGE: LazyLock = LazyLock::new(|| { - Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psnforge .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for normalizing loop function names") + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psnforge .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for snforge snippet") }); #[derive(Clone, Debug)] From c821fb9a8b4b3e6f83695884e2c945bab54e3074 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 3 Dec 2024 11:55:22 +0100 Subject: [PATCH 173/183] Update function visibility --- crates/docs/src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 2601680b02..fdd3e5ad63 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -48,7 +48,7 @@ pub fn print_ignored_snippet_message(snippet: &Snippet) { ); } -pub fn get_canonical_path(relative_path: &str) -> Result> { +fn get_canonical_path(relative_path: &str) -> Result> { Ok(Utf8PathBuf::from_str(relative_path)? .canonicalize_utf8()? .to_string() From 84b49b2b5c53016ef2ad33ff05a5b3a99726843c Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 10:54:43 +0100 Subject: [PATCH 174/183] Update todo --- docs/src/starknet/script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index 06b800e33c..02e266e927 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -255,7 +255,7 @@ sncast_std = "0.33.0" To run the script, do: - + ```shell $ sncast \ From 5fa190f5c76289e6277273a6847a7ff115aefd50 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 10:55:11 +0100 Subject: [PATCH 175/183] Fix typo --- crates/sncast/tests/docs_snippets/validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 62e3311360..791aef94de 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -195,7 +195,7 @@ fn test_docs_snippets() { .get(contract_name.as_str()) .unwrap_or_else(|| panic!("Contract {contract_name} not found")); - // In case of invoke/call/verify, we need to replace contract address insnippet's + // In case of invoke/call/verify, we need to replace contract address in snippet's // args with prepared contract's address if is_command(&args, &["invoke", "call", "verify"]) { swap_next_element(&mut args, "--contract-address", &contract.contract_address); From 5c9984e465d2b749fbcd77fb2e7a2b75fbc36d1b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 13:28:20 +0100 Subject: [PATCH 176/183] Refactor `get_canonical_path` --- crates/docs/src/utils.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index fdd3e5ad63..8fb1dcd724 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -51,8 +51,7 @@ pub fn print_ignored_snippet_message(snippet: &Snippet) { fn get_canonical_path(relative_path: &str) -> Result> { Ok(Utf8PathBuf::from_str(relative_path)? .canonicalize_utf8()? - .to_string() - .replace('\\', "/")) + .to_string()) } pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box> { From 39f79a6e37827a0fdf8481d9fcbb13fea5285503 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 13:38:50 +0100 Subject: [PATCH 177/183] Add `#[serde(default)]` to bool fields in `SnippetConfig` --- crates/docs/src/snippet.rs | 6 ++++-- crates/docs/src/utils.rs | 2 +- crates/sncast/tests/docs_snippets/validation.rs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index c1e4f12de2..7d0fd6b427 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -54,10 +54,12 @@ impl SnippetType { #[derive(Debug, Deserialize, Serialize, Default)] pub struct SnippetConfig { - pub ignored: Option, + #[serde(default)] + pub ignored: bool, pub package_name: Option, pub contract_name: Option, - pub ignored_output: Option, + #[serde(default)] + pub ignored_output: bool, } #[derive(Debug)] diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 8fb1dcd724..ab88de351b 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -32,7 +32,7 @@ pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &st pub fn print_snippets_validation_summary(snippets: &[Snippet], tool_name: &str) { let validated_snippets_count = snippets .iter() - .filter(|snippet| !snippet.config.ignored.unwrap_or(false)) + .filter(|snippet| !snippet.config.ignored) .count(); let ignored_snippets_count = snippets.len() - validated_snippets_count; diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 791aef94de..8805323c11 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -174,7 +174,7 @@ fn test_docs_snippets() { let contracts = setup_contracts_map(&tempdir, &accounts_json_path); for snippet in &snippets { - if snippet.config.ignored.unwrap_or(false) { + if snippet.config.ignored { print_ignored_snippet_message(snippet); continue; } @@ -209,7 +209,7 @@ fn test_docs_snippets() { let snapbox = runner(&args).current_dir(tempdir.path()); let output = snapbox.assert().success(); - if snippet.output.is_some() && !snippet.config.ignored_output.unwrap_or(false) { + if snippet.output.is_some() && !snippet.config.ignored_output { assert_stdout_contains(output, snippet.output.as_ref().unwrap()); } } From aec16a60a8fce7fd153569964458b905645751b0 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 13:40:45 +0100 Subject: [PATCH 178/183] Rename `user0` to `my_account` --- crates/sncast/tests/docs_snippets/validation.rs | 6 +++--- docs/listings/hello_sncast/snfoundry.toml | 4 ++-- docs/src/starknet/account.md | 2 +- docs/src/starknet/declare.md | 2 +- docs/src/starknet/deploy.md | 2 +- docs/src/starknet/invoke.md | 2 +- docs/src/starknet/show_config.md | 4 ++-- docs/src/starknet/sncast-overview.md | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 8805323c11..ef4c5b091f 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -26,7 +26,7 @@ fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { let accounts = r#" { "alpha-sepolia": { - "user0": { + "my_account": { "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", "deployed": true, "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", @@ -52,7 +52,7 @@ fn declare_and_deploy_contract( "--accounts-file", accounts_file, "--account", - "user0", + "my_account", "declare", "--url", URL, @@ -78,7 +78,7 @@ fn declare_and_deploy_contract( "--accounts-file", accounts_file, "--account", - "user0", + "my_account", "deploy", "--url", URL, diff --git a/docs/listings/hello_sncast/snfoundry.toml b/docs/listings/hello_sncast/snfoundry.toml index 402f14a63e..b31107df2c 100644 --- a/docs/listings/hello_sncast/snfoundry.toml +++ b/docs/listings/hello_sncast/snfoundry.toml @@ -1,9 +1,9 @@ [sncast.default] -account = "user0" +account = "my_account" accounts-file = "accounts.json" url = "http://127.0.0.1:5055/rpc" [sncast.myprofile] -account = "user0" +account = "my_account" accounts-file = "accounts.json" url = "http://127.0.0.1:5055/rpc" diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 2f09421bc6..07af04d94d 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -129,7 +129,7 @@ Available accounts (at [..]): legacy: false type: OpenZeppelin -- user0: +- my_account: network: alpha-sepolia public key: 0x48234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac address: 0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index cf297917cb..fe468a9c06 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -20,7 +20,7 @@ Then run: ```shell -$ sncast --account user0 \ +$ sncast --account my_account \ declare \ --url http://127.0.0.1:5055 \ --fee-token strk \ diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index ddffcc6c07..9d38960930 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -17,7 +17,7 @@ After [declaring your contract](./declare.md), you can deploy it the following w ```shell $ sncast \ - --account user0 \ + --account my_account \ deploy \ --url http://127.0.0.1:5055/rpc \ --fee-token strk \ diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index f8356cb5a2..89d5b004fb 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -20,7 +20,7 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ```shell $ sncast \ - --account user0 \ + --account my_account \ invoke \ --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index 3f24db162c..82a49719cf 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -15,7 +15,7 @@ replace any subcommand (and its parameters) with `show-config` and it will show ```shell $ sncast \ - --account user0 \ + --account my_account \ show-config ``` @@ -24,7 +24,7 @@ $ sncast \ ```shell command: show-config -account: user0 +account: my_account chain_id: alpha-sepolia rpc_url: http://127.0.0.1:5055/rpc ``` diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 796957e17e..8e3aff6b58 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -84,7 +84,7 @@ Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. ```shell -$ sncast --account user0 \ +$ sncast --account my_account \ --wait \ deploy \ --url http://127.0.0.1:5055 \ From af07611e81c1be7e5cbecef8d9285e78e4a67cc6 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 13:48:12 +0100 Subject: [PATCH 179/183] Remove unneeded `unwrap_or` --- crates/forge/tests/e2e/docs_snippets_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index bd147c3922..ac16e555a1 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -21,7 +21,7 @@ fn test_docs_snippets() { .expect("Failed to extract command snippets"); for snippet in &snippets { - if snippet.config.ignored.unwrap_or(false) { + if snippet.config.ignored { print_ignored_snippet_message(snippet); continue; } From 3e8c9cc5b5459a9edd3c8f0b488b3b81154e3380 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 14:41:14 +0100 Subject: [PATCH 180/183] Rename `user0` to `my_user` --- crates/sncast/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index 601de2baa5..af191cf758 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -34,7 +34,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ```shell -$ sncast --account user0 \ +$ sncast --account my_user \ declare \ --contract-name HelloSncast \ --fee-token strk @@ -78,7 +78,7 @@ transaction_hash: [..] ```shell -$ sncast --account user0 \ +$ sncast --account my_user \ deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --url http://127.0.0.1:5055 \ --fee-token strk @@ -123,7 +123,7 @@ transaction_hash: [..] ```shell $ sncast \ - --account user0 \ + --account my_user \ invoke \ --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --function "sum_numbers" \ From ca92dd7051f53c7494359956d53d7753fee4f952 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 14:45:35 +0100 Subject: [PATCH 181/183] Change `my_user` to `my_account` --- crates/sncast/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/sncast/README.md b/crates/sncast/README.md index af191cf758..9ee19756fc 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -34,7 +34,7 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ```shell -$ sncast --account my_user \ +$ sncast --account my_account \ declare \ --contract-name HelloSncast \ --fee-token strk @@ -78,7 +78,7 @@ transaction_hash: [..] ```shell -$ sncast --account my_user \ +$ sncast --account my_account \ deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --url http://127.0.0.1:5055 \ --fee-token strk @@ -123,7 +123,7 @@ transaction_hash: [..] ```shell $ sncast \ - --account my_user \ + --account my_account \ invoke \ --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --function "sum_numbers" \ From af53569c3f319cca3695b7f1e786f16bb472126b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 18:04:49 +0100 Subject: [PATCH 182/183] Move validation util functions --- .../sncast/tests/docs_snippets/validation.rs | 125 +----------------- crates/sncast/tests/helpers/devnet.rs | 119 +++++++++++++++++ 2 files changed, 123 insertions(+), 121 deletions(-) diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index ef4c5b091f..df31c1e06e 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,6 +1,6 @@ -use std::collections::HashMap; -use std::fs; - +use crate::helpers::devnet::{prepare_accounts_file, setup_contracts_map}; +use crate::helpers::fixtures::copy_directory_to_tempdir; +use crate::helpers::runner::runner; use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ @@ -8,124 +8,7 @@ use docs::utils::{ update_scarb_toml_dependencies, }; use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; -use regex::Regex; -use shared::test_utils::output_assert::{assert_stdout_contains, AsOutput}; -use tempfile::TempDir; - -use crate::helpers::constants::URL; -use crate::helpers::fixtures::copy_directory_to_tempdir; -use crate::helpers::runner::runner; - -struct Contract { - class_hash: String, - contract_address: String, -} - -fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { - // Account from predeployed accounts in starknet-devnet-rs - let accounts = r#" - { - "alpha-sepolia": { - "my_account": { - "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", - "deployed": true, - "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", - "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", - "type": "open_zeppelin" - } - } - } - "#; - - let accounts_path = temp.path().join("accounts.json"); - fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); - - Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") -} - -fn declare_and_deploy_contract( - contract_name: &str, - accounts_file: &str, - temp: &TempDir, -) -> Contract { - let args = vec![ - "--accounts-file", - accounts_file, - "--account", - "my_account", - "declare", - "--url", - URL, - "--contract-name", - contract_name, - "--max-fee", - "99999999999999999", - "--fee-token", - "strk", - ]; - - let snapbox = runner(&args).current_dir(temp.path()); - let output = snapbox.assert().success(); - let re_class_hash = Regex::new(r"class_hash:\s+(0x[a-fA-F0-9]+)").unwrap(); - - let class_hash = re_class_hash - .captures(output.as_stdout()) - .and_then(|captures| captures.get(1)) - .map(|match_| match_.as_str()) - .expect("class_hash not found in the output"); - - let args = vec![ - "--accounts-file", - accounts_file, - "--account", - "my_account", - "deploy", - "--url", - URL, - "--class-hash", - class_hash, - "--max-fee", - "99999999999999999", - "--fee-token", - "strk", - ]; - - let re_contract_address = Regex::new(r"contract_address:\s+(0x[a-fA-F0-9]+)").unwrap(); - - let snapbox = runner(&args).current_dir(temp.path()); - let output = snapbox.assert().success(); - - let contract_address = re_contract_address - .captures(output.as_stdout()) - .and_then(|captures| captures.get(1)) - .map(|match_| match_.as_str()) - .expect("contract_address not found in the output"); - - Contract { - class_hash: class_hash.to_string(), - contract_address: contract_address.to_string(), - } -} - -fn setup_contracts_map( - tempdir: &TempDir, - account_json_path: &Utf8PathBuf, -) -> HashMap { - let mut contracts: HashMap = HashMap::new(); - let contract_names = [ - "HelloSncast", - "DataTransformerContract", - "ConstructorContract", - ]; - - for contract_name in &contract_names { - let contract = - declare_and_deploy_contract(contract_name, account_json_path.as_str(), tempdir); - contracts.insert((*contract_name).to_string(), contract); - } - - contracts -} +use shared::test_utils::output_assert::assert_stdout_contains; fn swap_next_element<'a>(args: &mut [&'a str], target: &str, new_value: &'a str) { if let Some(index) = args.iter().position(|&x| x == target) { diff --git a/crates/sncast/tests/helpers/devnet.rs b/crates/sncast/tests/helpers/devnet.rs index 491f0634fb..97541be73c 100644 --- a/crates/sncast/tests/helpers/devnet.rs +++ b/crates/sncast/tests/helpers/devnet.rs @@ -3,14 +3,27 @@ use crate::helpers::fixtures::{ deploy_argent_account, deploy_braavos_account, deploy_cairo_0_account, deploy_keystore_account, deploy_latest_oz_account, }; +use camino::Utf8PathBuf; use ctor::{ctor, dtor}; +use regex::Regex; +use shared::test_utils::output_assert::AsOutput; +use std::collections::HashMap; +use std::fs; use std::net::TcpStream; use std::process::{Command, Stdio}; use std::string::ToString; use std::time::{Duration, Instant}; +use tempfile::TempDir; use tokio::runtime::Runtime; use url::Url; +use super::runner::runner; + +pub struct Contract { + pub class_hash: String, + pub contract_address: String, +} + #[allow(clippy::zombie_processes)] #[cfg(test)] #[ctor] @@ -89,3 +102,109 @@ fn stop_devnet() { .spawn() .expect("Failed to kill devnet processes"); } + +fn declare_and_deploy_contract( + contract_name: &str, + accounts_file: &str, + temp: &TempDir, +) -> Contract { + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "my_account", + "declare", + "--url", + URL, + "--contract-name", + contract_name, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + let re_class_hash = Regex::new(r"class_hash:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let class_hash = re_class_hash + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("class_hash not found in the output"); + + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "my_account", + "deploy", + "--url", + URL, + "--class-hash", + class_hash, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let re_contract_address = Regex::new(r"contract_address:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + + let contract_address = re_contract_address + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("contract_address not found in the output"); + + Contract { + class_hash: class_hash.to_string(), + contract_address: contract_address.to_string(), + } +} + +pub fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { + // Account from predeployed accounts in starknet-devnet-rs + let accounts = r#" + { + "alpha-sepolia": { + "my_account": { + "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", + "deployed": true, + "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", + "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", + "type": "open_zeppelin" + } + } + } + "#; + + let accounts_path = temp.path().join("accounts.json"); + fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); + + Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") +} + +pub fn setup_contracts_map( + tempdir: &TempDir, + account_json_path: &Utf8PathBuf, +) -> HashMap { + let mut contracts: HashMap = HashMap::new(); + let contract_names = [ + "HelloSncast", + "DataTransformerContract", + "ConstructorContract", + ]; + + for contract_name in &contract_names { + let contract = + declare_and_deploy_contract(contract_name, account_json_path.as_str(), tempdir); + contracts.insert((*contract_name).to_string(), contract); + } + + contracts +} From 44f5beed24629316a9c3bbae1f2c06260465f28a Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Wed, 4 Dec 2024 19:04:06 +0100 Subject: [PATCH 183/183] Fix linting --- crates/sncast/tests/helpers/devnet.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/sncast/tests/helpers/devnet.rs b/crates/sncast/tests/helpers/devnet.rs index 97541be73c..fdb1482ef1 100644 --- a/crates/sncast/tests/helpers/devnet.rs +++ b/crates/sncast/tests/helpers/devnet.rs @@ -167,6 +167,7 @@ fn declare_and_deploy_contract( } } +#[must_use] pub fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { // Account from predeployed accounts in starknet-devnet-rs let accounts = r#" @@ -189,6 +190,7 @@ pub fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") } +#[must_use] pub fn setup_contracts_map( tempdir: &TempDir, account_json_path: &Utf8PathBuf,