Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically validate sncast docs snippets #2733

Open
wants to merge 206 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 196 commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
3c4a076
Add expandable shell snippet outputs
franciszekjob Nov 8, 2024
f8b0058
Change shell snippets to expandable blocks
franciszekjob Nov 9, 2024
4e45711
Make expandable snippet open by default
franciszekjob Nov 10, 2024
23493ab
Make `tree` commands expandable
franciszekjob Nov 10, 2024
62bb35a
Restore prompt in shell snippets
franciszekjob Nov 10, 2024
3ef847f
Revert "Restore prompt in shell snippets"
franciszekjob Nov 10, 2024
304e423
Restore prompt in shell snippets
franciszekjob Nov 10, 2024
f10ac8e
Restore prompt in other shell snippets
franciszekjob Nov 10, 2024
be9c9e5
Fix forge version check snippet
franciszekjob Nov 10, 2024
a17d919
Add JS script to remove prompt sign when copying code
franciszekjob Nov 10, 2024
432e366
Add validation of sncast snippets
franciszekjob Nov 11, 2024
2cc325c
Merge branch 'franciszekjob/2479-expandable-shell-snippets' of https:…
franciszekjob Nov 11, 2024
f5f3e41
Remove unnecessary else branch
franciszekjob Nov 12, 2024
beb0855
Fix left docs snippets
franciszekjob Nov 12, 2024
18ffce2
Make `tree` snippet expandable in first steps section
franciszekjob Nov 12, 2024
1d7f284
Fix typo
franciszekjob Nov 12, 2024
48a3fcd
Fix typo
franciszekjob Nov 12, 2024
0438352
Fix typos
franciszekjob Nov 12, 2024
ccfac3f
Merge branch 'master' into franciszekjob/2479-expandable-shell-snippets
franciszekjob Nov 12, 2024
dca617d
Improve sncast snippets validation test
franciszekjob Nov 12, 2024
ed6daa0
Merge branch 'franciszekjob/2479-expandable-shell-snippets' of https:…
franciszekjob Nov 12, 2024
3ae3107
Fix printing number of validated snippets in sncast test
franciszekjob Nov 12, 2024
2f65010
Add snforge docs snippets validation test
franciszekjob Nov 12, 2024
efc2e1d
Remove print
franciszekjob Nov 12, 2024
2823523
Merge branch 'master' into franciszekjob/2479-expandable-shell-snippets
franciszekjob Nov 12, 2024
bcbb861
Merge branch 'franciszekjob/2479-expandable-shell-snippets' into fran…
franciszekjob Nov 12, 2024
1b968be
Move docs validation into separate crate
franciszekjob Nov 12, 2024
041f604
Merge branch 'franciszekjob/2479-2-shell-commands-validation' of http…
franciszekjob Nov 12, 2024
7bbcd99
Fix newline
franciszekjob Nov 12, 2024
bdcd467
Update `Cargo.toml` in `sncast`
franciszekjob Nov 12, 2024
b6db6a5
Test cast docs validation test
franciszekjob Nov 12, 2024
a4535cd
Fix linting
franciszekjob Nov 12, 2024
dcd4e80
Cleanup sncast snippets validation test
franciszekjob Nov 13, 2024
9e34797
Minor refactor of forge snippets validation test
franciszekjob Nov 13, 2024
8ddc850
Fix linting
franciszekjob Nov 13, 2024
8e6678c
Update `Cargo.lock`
franciszekjob Nov 13, 2024
6da2d58
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 14, 2024
92fff9f
Fix deploy contract snippet
franciszekjob Nov 14, 2024
d445531
Use `try_parse_from` in forge docs snippets validation
franciszekjob Nov 15, 2024
46aa9d4
Add skipped args in forge
franciszekjob Nov 15, 2024
1dd0062
Refactor snippets validation test in cast
franciszekjob Nov 15, 2024
80e5b79
Add todo
franciszekjob Nov 15, 2024
54f4247
Code cleanup
franciszekjob Nov 15, 2024
fab960d
Fix typos
franciszekjob Nov 15, 2024
f119e3b
Minor fixes in docs
franciszekjob Nov 18, 2024
853c8ed
Remove `license-file.workspace` from docs crate
franciszekjob Nov 18, 2024
f6a029c
Move todo
franciszekjob Nov 18, 2024
2e0f0f1
Merge branch 'master' into franciszekjob/2479-2-shell-commands-valida…
franciszekjob Nov 18, 2024
41cb86a
Show validated snippets number
franciszekjob Nov 18, 2024
6d8a825
Merge branch 'franciszekjob/2479-2-shell-commands-validation' of http…
franciszekjob Nov 18, 2024
5c84ef1
Fix linting
franciszekjob Nov 18, 2024
8292a54
Display line and file path of failed snippet
franciszekjob Nov 18, 2024
fa40a6b
Fix err message
franciszekjob Nov 18, 2024
d846b42
Code review improvements
franciszekjob Nov 18, 2024
cbda065
Move docs to dev dependencies
franciszekjob Nov 18, 2024
9fe0a3c
Update `tree` output in first steps sections
franciszekjob Nov 19, 2024
906777b
Allow setup packages from docs listings
franciszekjob Nov 19, 2024
446cdfd
Add example packages for "Running tests" section
franciszekjob Nov 19, 2024
2a61d99
wip: Update outputs for snippets in snforge overview
franciszekjob Nov 19, 2024
bcf5f40
Fix typo
franciszekjob Nov 19, 2024
aa4be23
wip: Update outputs for cheatcode snippets
franciszekjob Nov 19, 2024
8449f5e
Update outputs for workspaces
franciszekjob Nov 19, 2024
ece5a07
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 19, 2024
a960649
Update command outputs docs
franciszekjob Nov 20, 2024
826be45
Update packages and manifests in docs listings
franciszekjob Nov 20, 2024
0574214
Add `SnippetType` enum; Add `output` and `snippet_type` fields in `Sn…
franciszekjob Nov 20, 2024
67346ea
Add `setup_package_from_docs_listings`
franciszekjob Nov 20, 2024
127842a
Add util functions to retrieve mapping of docs listing -> crates
franciszekjob Nov 20, 2024
f01065d
Add command execution in forge docs snippets test
franciszekjob Nov 20, 2024
6caf67b
Fix linting
franciszekjob Nov 20, 2024
eb95205
Run `scarb fmt`
franciszekjob Nov 20, 2024
1c2a863
Use `scarb check` in `verify_cairo_listings.sh`
franciszekjob Nov 20, 2024
95d9bb9
Fix linting
franciszekjob Nov 20, 2024
d8481b0
Run `scarb fmt`
franciszekjob Nov 20, 2024
09bac46
Fix typo
franciszekjob Nov 20, 2024
ae39133
Remove comment
franciszekjob Nov 21, 2024
7703ce6
Update sncast docs snippets test
franciszekjob Nov 21, 2024
a106627
Refactor `test_docs_snippets` in forge
franciszekjob Nov 21, 2024
4407733
Refactor util functions
franciszekjob Nov 21, 2024
983e0a6
Change err msg while calling `extract_snippets_from_directory` in forge
franciszekjob Nov 21, 2024
78e3c7d
Format
franciszekjob Nov 21, 2024
97df99f
Add todo
franciszekjob Nov 21, 2024
dc4386c
Remove unused package
franciszekjob Nov 21, 2024
4d245af
Allow ignoring snippets
franciszekjob Nov 21, 2024
0eadab4
Fix failing tests
franciszekjob Nov 21, 2024
c5e3b19
Apply CR suggestions
franciszekjob Nov 21, 2024
4df85ac
Add `hello_workspaces` case in `resolve_temp_dir`
franciszekjob Nov 21, 2024
216c10b
Run `scarb clean` before `scarb check` in `verify_cairo_listings.sh`
franciszekjob Nov 21, 2024
a2f01d5
Revert "Run `scarb clean` before `scarb check` in `verify_cairo_listi…
franciszekjob Nov 21, 2024
a00a460
Reorganize listings packages
franciszekjob Nov 21, 2024
ad9aa26
Update manifests in listings packages
franciszekjob Nov 22, 2024
12edd48
Add `hello_workspace` package
franciszekjob Nov 22, 2024
fd78dd4
Add `SnippetConfig`
franciszekjob Nov 22, 2024
e2eb456
Refactor `setup_package_with_file_patterns`
franciszekjob Nov 22, 2024
3dd6452
Fix typo in packages manifests
franciszekjob Nov 22, 2024
58bac96
Add config to snippets in markdown files
franciszekjob Nov 22, 2024
a951882
Refactor `extract_snippets_from_file`
franciszekjob Nov 22, 2024
538a775
Remove unneeded changes while using `setup_package_with_file_patterns`
franciszekjob Nov 22, 2024
2a7ea51
Update crates/docs/src/validation.rs
franciszekjob Nov 22, 2024
4d18e0a
Trigger CI
franciszekjob Nov 22, 2024
f52f64e
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 22, 2024
e94a85b
Update manifests
franciszekjob Nov 22, 2024
393cc29
Update listings embeds
franciszekjob Nov 22, 2024
db852eb
Fix failing tests
franciszekjob Nov 24, 2024
b97ae4b
Rename package; Fix `should_panic` test
franciszekjob Nov 24, 2024
97171b6
Temporarily change `get_remote_url`
franciszekjob Nov 24, 2024
d680083
Fix dependencies in listings manifests
franciszekjob Nov 24, 2024
4c04d41
Fix dependencies in the rest of packages manifests
franciszekjob Nov 24, 2024
06f10ed
Fix dependencies in the rest of packages manifests
franciszekjob Nov 24, 2024
36164d0
Fix dependencies in the rest of packages manifests
franciszekjob Nov 24, 2024
8424c57
Fix manifests in `hello_workspaces` package
franciszekjob Nov 25, 2024
40461a2
Reorder capture groups
franciszekjob Nov 25, 2024
8b1a330
Merge branch 'master' into franciszekjob/2479-3-shell-commands-runnin…
franciszekjob Nov 25, 2024
73c51b7
Merge branch 'franciszekjob/2479-3-shell-commands-running-validation'…
franciszekjob Nov 25, 2024
5b3b26f
Add comment to `SnippetType.get_re()`
franciszekjob Nov 25, 2024
98217c1
Restructure `docs` crate
franciszekjob Nov 25, 2024
b0a1130
Remove default `SnippetConfig`
franciszekjob Nov 25, 2024
ce93644
Remove unneeded import
franciszekjob Nov 25, 2024
30a8ca5
Remove unused import
franciszekjob Nov 25, 2024
b9ab20a
Fix docs snippets test for `--exit-first` flag
franciszekjob Nov 25, 2024
6e53c06
Merge branch 'master' into franciszekjob/2479-3-shell-commands-runnin…
franciszekjob Nov 25, 2024
815e1fc
Update docs
franciszekjob Nov 25, 2024
7517ddb
Update docs
franciszekjob Nov 25, 2024
d434dbe
Update `SnippetType.get_re()` description
franciszekjob Nov 25, 2024
7bc535a
Change `scarb check` to `scarb test` in verification script
franciszekjob Nov 25, 2024
ebd68fc
Fix building mdbook
franciszekjob Nov 25, 2024
ebdc770
Use `runner` instead of `test_runner`
franciszekjob Nov 25, 2024
c12935b
Inline `is_package_from_docs_listings`
franciszekjob Nov 25, 2024
cb0fe80
Rename `get_parent_dir` to `get_nth_ancestor`
franciszekjob Nov 25, 2024
3f9adf1
Remove `SnippetConfig::from_json`
franciszekjob Nov 25, 2024
800fcfd
Use `trim` in `Snippet.to_command_args`
franciszekjob Nov 25, 2024
75360e0
Used named captures in regex
franciszekjob Nov 25, 2024
5798cd7
Merge branch 'master' into franciszekjob/2479-3-shell-commands-runnin…
franciszekjob Nov 25, 2024
d9f11bf
Refactor `setup_package_with_file_patterns`
franciszekjob Nov 25, 2024
a92325f
Remove `trim` from `Snippet.to_command_args`
franciszekjob Nov 25, 2024
451bb67
Revert "Refactor `setup_package_with_file_patterns`"
franciszekjob Nov 25, 2024
4692dfd
Fix linting
franciszekjob Nov 25, 2024
9b58f51
Ingore snforge snippet with `--exit-first` flag
franciszekjob Nov 26, 2024
8ed2e92
Fix failing cast `test_docs_snippets`
franciszekjob Nov 26, 2024
324ec97
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 26, 2024
624277c
Fix docs snippets test for backtrace
franciszekjob Nov 26, 2024
d85ae00
Update manigest for `basic_example` package
franciszekjob Nov 26, 2024
c375d44
Add missing `snforge_std`
franciszekjob Nov 26, 2024
fbb6358
Use `scarb check` instead of `scarb test`
franciszekjob Nov 26, 2024
5cf8560
Fix CI
franciszekjob Nov 26, 2024
8cd610d
Use `scarb check` instead of `scarb test`
franciszekjob Nov 26, 2024
5fa2ee9
Update todo
franciszekjob Nov 26, 2024
386e2c6
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 26, 2024
8217109
Update cairlo listings verification script
franciszekjob Nov 26, 2024
a1314de
Use `scarb build` instead of `scarb test`
franciszekjob Nov 26, 2024
dd4ede7
Merge branch 'franciszekjob/2479-3-shell-commands-running-validation'…
franciszekjob Nov 26, 2024
879b52f
Remove inlining of `is_package_from_docs_listings`
franciszekjob Nov 26, 2024
5e8bb02
Refactor `is_package_from_docs_listings`
franciszekjob Nov 27, 2024
f6e407c
Remove unneeded `.gitignore` files
franciszekjob Nov 27, 2024
15e8ed3
Fix embed path
franciszekjob Nov 28, 2024
744e083
Fix sncast command in docs
franciszekjob Nov 28, 2024
3a7c286
Fix sncast docs commands
franciszekjob Nov 28, 2024
a30be73
Change printing tx hash in `wait_for_tx`
franciszekjob Nov 29, 2024
0fb04b1
Use `LazyLock` for regex; Add `ignore_output` field in `SnippetConfig`
franciszekjob Nov 29, 2024
48bd8c1
Add `sncast_example` package
franciszekjob Nov 29, 2024
f0e5fd9
Fixes and adjustments to docs snippets
franciszekjob Nov 29, 2024
8c9bda7
Add example contract with constructor
franciszekjob Nov 29, 2024
7a294ea
Fix snippet for `tx-status` command
franciszekjob Nov 29, 2024
19576ab
Further fixes of sncast docs snippets
franciszekjob Nov 29, 2024
82530bd
Add `sncast_std` dependency to `sncast_example`
franciszekjob Nov 29, 2024
77d32ca
Add `update_scarb_toml_dependencies` to utils
franciszekjob Nov 29, 2024
3686cb6
Remove new line when printing in `print_skipped_snippet_message`
franciszekjob Nov 29, 2024
178e2d8
Improve sncast commands validation logic
franciszekjob Nov 29, 2024
74058a5
Update dependencies
franciszekjob Nov 29, 2024
443ebcf
Adjust `test_docs_snippets` in forge
franciszekjob Nov 29, 2024
a3a88bc
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob Nov 29, 2024
d25c233
Rename `ignore_output` to `ignored_output`
franciszekjob Nov 29, 2024
8d9e5a3
Code refactor and cleanup
franciszekjob Nov 29, 2024
88e0a6d
Minor adjustments to snippets outputs
franciszekjob Nov 29, 2024
32535d9
Fix scarb formatting
franciszekjob Nov 29, 2024
4711665
Fix failing tests
franciszekjob Nov 29, 2024
b844f2d
Rename util functions
franciszekjob Nov 29, 2024
7343dfd
Fix newline
franciszekjob Nov 29, 2024
0dadcae
Adjust urls in snippets outputs
franciszekjob Nov 29, 2024
a4e2d91
Fix failing `test_run_script_display_debug_traits`
franciszekjob Nov 29, 2024
0843072
Code cleanup
franciszekjob Nov 30, 2024
00fd1dd
Add todos
franciszekjob Nov 30, 2024
221d53b
Update data transformer contract
franciszekjob Nov 30, 2024
1d25d80
Unignore data transformer snippets
franciszekjob Nov 30, 2024
2c09097
Rename `sncast_example` to `hello_sncast`
franciszekjob Dec 1, 2024
4902f75
Add todos
franciszekjob Dec 1, 2024
b4562b7
Embed `DataTransformerContract` code
franciszekjob Dec 1, 2024
a8532bb
Fix scarb formatting
franciszekjob Dec 1, 2024
777e800
Merge branch 'master' into franciszekjob/2479-4-sncast-commands-valid…
franciszekjob Dec 1, 2024
f3c66a0
Merge branch 'franciszekjob/2479-4-sncast-commands-validation' of htt…
franciszekjob Dec 1, 2024
8705e4d
Update logic of getting contract name
franciszekjob Dec 1, 2024
345b86c
Add todo
franciszekjob Dec 1, 2024
2836dad
Merge branch 'master' into franciszekjob/2479-4-sncast-commands-valid…
franciszekjob Dec 2, 2024
2ab3b69
Update regex err messages
franciszekjob Dec 2, 2024
c821fb9
Update function visibility
franciszekjob Dec 3, 2024
2d929f2
Merge branch 'franciszekjob/2479-4-sncast-commands-validation' of htt…
franciszekjob Dec 3, 2024
84b49b2
Update todo
franciszekjob Dec 4, 2024
5fa190f
Fix typo
franciszekjob Dec 4, 2024
0ba1cd7
Merge branch 'master' into franciszekjob/2479-4-sncast-commands-valid…
franciszekjob Dec 4, 2024
5c9984e
Refactor `get_canonical_path`
franciszekjob Dec 4, 2024
39f79a6
Add `#[serde(default)]` to bool fields in `SnippetConfig`
franciszekjob Dec 4, 2024
aec16a6
Rename `user0` to `my_account`
franciszekjob Dec 4, 2024
af07611
Remove unneeded `unwrap_or`
franciszekjob Dec 4, 2024
3e8c9cc
Rename `user0` to `my_user`
franciszekjob Dec 4, 2024
ca92dd7
Change `my_user` to `my_account`
franciszekjob Dec 4, 2024
af53569
Move validation util functions
franciszekjob Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
27 changes: 19 additions & 8 deletions crates/docs/src/snippet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use std::sync::LazyLock;

use regex::Regex;
use serde::{Deserialize, Serialize};

static RE_SNCAST: LazyLock<Regex> = LazyLock::new(|| {
Regex::new( r"(?ms)^(?:<!--\s*(?P<config>\{.*?\})\s*-->\n)?```shell\n\$ (?P<command>sncast .+?)\n```(?:\s*<details>\n<summary>Output:<\/summary>\n\n```shell\n(?P<output>[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for sncast snippet")
});

static RE_SNFORGE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new( r"(?ms)^(?:<!--\s*(?P<config>\{.*?\})\s*-->\n)?```shell\n\$ (?P<command>snforge .+?)\n```(?:\s*<details>\n<summary>Output:<\/summary>\n\n```shell\n(?P<output>[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for snforge snippet")
});

#[derive(Clone, Debug)]
pub struct SnippetType(String);

Expand All @@ -21,9 +31,9 @@ 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:
// <!-- { "ignored": true, "package_name": "xyz" } -->
// <!-- { content of snippet config JSON } -->
// ```shell
// $ snforge or sncast command with args...
// ```
Expand All @@ -34,19 +44,20 @@ impl SnippetType {
// ```
// </details>

let escaped_command = regex::escape(self.as_str());
let pattern = format!(
r"(?ms)^(?:<!--\s*(?P<config>.*?)\s*-->\n)?```shell\n\$ (?P<command>{escaped_command} .+?)\n```(?:\s*<details>\n<summary>Output:<\/summary>\n\n```shell\n(?P<output>[\s\S]+?)\n```[\s]*<\/details>)?"
);

Regex::new(&pattern).unwrap()
match self.as_str() {
"snforge" => &RE_SNFORGE,
"sncast" => &RE_SNCAST,
_ => panic!("Regex for {} not found", self.as_str()),
}
}
}

#[derive(Debug, Deserialize, Serialize, Default)]
pub struct SnippetConfig {
pub ignored: Option<bool>,
pub package_name: Option<String>,
pub contract_name: Option<String>,
pub ignored_output: Option<bool>,
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Debug)]
Expand Down
45 changes: 39 additions & 6 deletions crates/docs/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -27,15 +29,46 @@ 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_snippets_validation_summary(snippets: &[Snippet], tool_name: &str) {
let validated_snippets_count = snippets
.iter()
.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}");
}

pub fn print_skipped_snippet_message(snippet: &Snippet) {
pub fn print_ignored_snippet_message(snippet: &Snippet) {
println!(
"Skipped validation of {} snippet in the docs in file: {} at line {}",
"Ignoring {} docs snippet, file: {}:{}:1",
snippet.snippet_type.as_str(),
snippet.file_path,
snippet.line_start,
);
}

fn get_canonical_path(relative_path: &str) -> Result<String, Box<dyn std::error::Error>> {
Ok(Utf8PathBuf::from_str(relative_path)?
.canonicalize_utf8()?
.to_string()
.replace('\\', "/"))
}
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved

pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box<dyn std::error::Error>> {
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::<DocumentMut>()
.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(())
}
13 changes: 7 additions & 6 deletions crates/forge/tests/e2e/docs_snippets_validation.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,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_skipped_snippet_message(snippet);
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()
Expand Down Expand Up @@ -55,5 +56,5 @@ fn test_docs_snippets() {
}
}

print_success_message(snippets.len(), snippet_type.as_str());
print_snippets_validation_summary(&snippets, snippet_type.as_str());
}
98 changes: 64 additions & 34 deletions crates/sncast/README.md
Copy link
Member

Choose a reason for hiding this comment

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

From the user standpoint, having outputs with [..] in docs is a bit weird.

Copy link
Member

Choose a reason for hiding this comment

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

What would be the steps to resolve this?

Copy link
Collaborator Author

@franciszekjob franciszekjob Dec 4, 2024

Choose a reason for hiding this comment

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

We could handle it similarly as here. Wdyt?

Original file line number Diff line number Diff line change
Expand Up @@ -31,156 +31,186 @@ All subcommand usages are shown for two scenarios - when all necessary arguments

### Declare a contract

<!-- TODO(#2736) -->
<!-- { "ignored": true } -->
```shell
$ sncast --account myuser \
$ sncast --account user0 \
declare \
--contract-name SimpleBalance
--contract-name HelloSncast \
--fee-token strk
```

<details>
<summary>Output:</summary>

```shell
command: Declare
class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a
transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f
class_hash: [..]
transaction_hash: [..]
```
</details>
<br>

With arguments taken from `snfoundry.toml` file (default profile name):

<!-- TODO(#2736) -->
<!-- { "ignored": true } -->
```shell
$ sncast declare \
--contract-name SimpleBalance
--contract-name HelloSncast \
--fee-token strk
```

<details>
<summary>Output:</summary>

```shell
command: Declare
class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a
transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f
class_hash: [..]
transaction_hash: [..]
```
</details>
<br>


### Deploy a contract

<!-- TODO(#2736) -->
<!-- { "contract_name": "HelloSncast", "ignored": true } -->
```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
```

<details>
<summary>Output:</summary>

```shell
command: Deploy
contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a
transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e
contract_address: [..]
transaction_hash: [..]
```
</details>
<br>

With arguments taken from `snfoundry.toml` file (default profile name):

<!-- TODO(#2736) -->
<!-- { "contract_name": "HelloSncast", "ignored": true } -->
```shell
$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a
$ sncast deploy \
--class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \
--fee-token strk

```

<details>
<summary>Output:</summary>

```shell
command: Deploy
contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a
transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e
contract_address: [..]
transaction_hash: [..]
```
</details>
<br>


### Invoke a contract

<!-- { "contract_name": "HelloSncast" } -->
```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
```

<details>
<summary>Output:</summary>

```shell
command: Invoke
transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f
command: invoke
transaction_hash: [..]

To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/[..]
```
</details>
<br>


With arguments taken from `snfoundry.toml` file (default profile name):

<!-- { "contract_name": "HelloSncast" } -->
```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
```

<details>
<summary>Output:</summary>

```shell
command: Invoke
transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f
command: invoke
transaction_hash: [..]

To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/[..]
```
</details>
<br>

### Call a contract

<!-- { "contract_name": "HelloSncast" } -->
```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
```

<details>
<summary>Output:</summary>

```shell
command: call
response: [0x0]
response: [0x6]
```
</details>
<br>


With arguments taken from `snfoundry.toml` file (default profile name):

<!-- { "contract_name": "HelloSncast" } -->
```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
```

<details>
<summary>Output:</summary>

```shell
command: call
response: [0x0]
response: [0x6]
```
</details>
<br>
Expand Down
Loading
Loading