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

Use sncast_std from registry for sncast script init #3137

Merged
merged 4 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `sncast completion` command - used to generate autocompletion script

#### Changed

- `sncast script init` command now initializes project with the `sncast_std` dependency from the [registry](https://scarbs.xyz/packages/sncast_std)

## [0.38.3] - 2025-03-07

### Forge
Expand Down
29 changes: 14 additions & 15 deletions crates/sncast/src/starknet_commands/script/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,11 @@ fn add_dependencies(script_root_dir: &Utf8PathBuf) -> Result<()> {
}

fn add_sncast_std_dependency(script_root_dir: &Utf8PathBuf) -> Result<()> {
let cast_version = format!("v{}", env!("CARGO_PKG_VERSION"));

let cast_version = env!("CARGO_PKG_VERSION").to_string();
let dep_id = format!("sncast_std@{cast_version}");
ScarbCommand::new()
.current_dir(script_root_dir)
.args([
"--offline",
"add",
"sncast_std",
"--git",
"https://github.com/foundry-rs/starknet-foundry.git",
"--tag",
&cast_version,
])
.args(["--offline", "add", &dep_id])
.run()?;

Ok(())
Expand Down Expand Up @@ -130,13 +122,20 @@ fn create_script_main_file(script_name: &str, script_root_dir: &Utf8PathBuf) ->
fs::write(
script_main_file_path,
indoc! {r#"
use sncast_std::{call, CallResult};
use sncast_std::call;

// The example below uses a contract deployed to the Sepolia testnet
const CONTRACT_ADDRESS: felt252 =
0x07e867f1fa6da2108dd2b3d534f1fbec411c5ec9504eb3baa1e49c7a0bef5ab5;

fn main() {
let contract_address = 0x07e867f1fa6da2108dd2b3d534f1fbec411c5ec9504eb3baa1e49c7a0bef5ab5;
let call_result = call(contract_address.try_into().unwrap(), selector!("get_greeting"), array![]).expect('call failed');
assert(*call_result.data[1]=='Hello, Starknet!', *call_result.data[1]);
let call_result = call(
CONTRACT_ADDRESS.try_into().unwrap(), selector!("get_greeting"), array![],
)
.expect('call failed');

assert(*call_result.data[1] == 'Hello, Starknet!', *call_result.data[1]);

println!("{:?}", call_result);
}
"#},
Expand Down
17 changes: 12 additions & 5 deletions crates/sncast/tests/e2e/script/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_script_init_happy_case() {
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
sncast_std = {{ git = "https://github.com/foundry-rs/starknet-foundry", tag = "v{cast_version}" }}
sncast_std = "{cast_version}"
starknet = ">={cairo_version}"

[dev-dependencies]
Expand All @@ -62,13 +62,20 @@ fn test_script_init_happy_case() {
assert_eq!(
main_file_content,
indoc! {r#"
use sncast_std::{call, CallResult};
use sncast_std::call;

// The example below uses a contract deployed to the Sepolia testnet
const CONTRACT_ADDRESS: felt252 =
0x07e867f1fa6da2108dd2b3d534f1fbec411c5ec9504eb3baa1e49c7a0bef5ab5;

fn main() {
let contract_address = 0x07e867f1fa6da2108dd2b3d534f1fbec411c5ec9504eb3baa1e49c7a0bef5ab5;
let call_result = call(contract_address.try_into().unwrap(), selector!("get_greeting"), array![]).expect('call failed');
assert(*call_result.data[1]=='Hello, Starknet!', *call_result.data[1]);
let call_result = call(
CONTRACT_ADDRESS.try_into().unwrap(), selector!("get_greeting"), array![],
)
.expect('call failed');

assert(*call_result.data[1] == 'Hello, Starknet!', *call_result.data[1]);

println!("{:?}", call_result);
}
"#}
Expand Down
Loading