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 196 commits into
base: master
Choose a base branch
from

Conversation

franciszekjob
Copy link
Collaborator

@franciszekjob franciszekjob commented Nov 29, 2024

Retales #2479

Introduced changes

This PR adds validation of sncast command snippets. Before validation, we declare + deploy contracts which are used in the examples.

  • Fix/adjust commands
  • Add hello_sncast package with necessary examples
  • Add logic for commands validation
  • Minor refactor of util functions

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

franciszekjob and others added 30 commits November 8, 2024 17:38
@franciszekjob franciszekjob marked this pull request as ready for review December 1, 2024 13:18
Comment on lines 1 to 13
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 normalizing loop function names")
});

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 normalizing loop function names")
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note: Using static regex is more efficient.

Ok(Utf8PathBuf::from_str(relative_path)?
.canonicalize_utf8()?
.to_string()
.replace('\\', "/"))
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this line?

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?

@@ -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 \
Copy link
Member

Choose a reason for hiding this comment

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

Why did we change the devnet port?

@@ -255,6 +255,8 @@ sncast_std = "0.33.0"

To run the script, do:

<!-- TODO: Add script example and remove ignoring output -->
Copy link
Member

Choose a reason for hiding this comment

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

Link issue please

.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
Copy link
Member

Choose a reason for hiding this comment

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

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

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

Successfully merging this pull request may close these issues.

2 participants