Skip to content

Commit b61796c

Browse files
authored
Fix negative values in arguments (#3205)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3203 ## Introduced changes <!-- A brief description of the changes --> - ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent 811fc2f commit b61796c

File tree

13 files changed

+75
-55
lines changed

13 files changed

+75
-55
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
- The state correctly reverts after failed internal calls
2525

26+
### Cast
27+
28+
#### Fixed
29+
30+
- Bug that prevented from passing values to `--arguments` that started with a leading minus `-` sign.
31+
2632
## [0.41.0] - 2025-04-08
2733

2834
### Forge

crates/data-transformer/tests/data/data_transformer/Scarb.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ edition = "2024_07"
66
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html
77

88
[dependencies]
9-
starknet = "2.10.0"
9+
starknet = "2.9.4"
1010
alexandria_data_structures = "0.4.0"
1111

1212
[dev-dependencies]
1313
snforge_std = "0.39.0"
14-
assert_macros = "2.10.0"
14+
assert_macros = "2.9.4"
1515

1616
[[target.starknet-contract]]
1717
sierra = true

crates/data-transformer/tests/data/data_transformer/src/lib.cairo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub trait IDataTransformer<TContractState> {
5959
ref self: TContractState, a: BitArray, b: alexandria_data_structures::bit_array::BitArray,
6060
);
6161
fn span_fn(ref self: TContractState, a: Span<felt252>);
62+
fn multiple_signed_fn(ref self: TContractState, a: i32, b: i8);
6263
}
6364

6465
#[starknet::contract]
@@ -101,5 +102,6 @@ mod DataTransformer {
101102
b: alexandria_data_structures::bit_array::BitArray,
102103
) {}
103104
fn span_fn(ref self: ContractState, a: Span<felt252>) {}
105+
fn multiple_signed_fn(ref self: ContractState, a: i32, b: i8) {}
104106
}
105107
}

crates/data-transformer/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use url::Url;
1515

1616
// Deployment of contract from /tests/data/data_transformer
1717
const TEST_CLASS_HASH: Felt =
18-
Felt::from_hex_unchecked("0x032e6763d5e778f153e5b6ea44200d94ec89aac7b42a0aef0e4e0caac8dafdab");
18+
Felt::from_hex_unchecked("0x0786d1f010d66f838837290e472415186ba6a789fb446e7f92e444bed7b5d9c0");
1919

2020
static CLASS: OnceCell<ContractClass> = OnceCell::const_new();
2121

crates/sncast/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub struct Arguments {
164164
pub calldata: Option<Vec<String>>,
165165

166166
// Arguments of the called function as a comma-separated string of Cairo expressions
167-
#[arg(long)]
167+
#[arg(long, allow_hyphen_values = true)]
168168
pub arguments: Option<String>,
169169
}
170170

crates/sncast/tests/e2e/call.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use crate::helpers::constants::{
33
};
44
use crate::helpers::fixtures::invoke_contract;
55
use crate::helpers::runner::runner;
6+
use crate::helpers::shell::os_specific_shell;
7+
use camino::Utf8PathBuf;
68
use indoc::indoc;
79
use shared::test_utils::output_assert::assert_stderr_contains;
8-
use snapbox::cmd::{Command, cargo_bin};
10+
use snapbox::cmd::cargo_bin;
911
use sncast::helpers::fee::FeeSettings;
10-
use std::path::PathBuf;
1112

1213
#[test]
1314
fn test_happy_case() {
@@ -242,21 +243,20 @@ fn test_wrong_block_id() {
242243

243244
#[test]
244245
fn test_happy_case_shell() {
245-
let script_extension = if cfg!(windows) { ".ps1" } else { ".sh" };
246-
let test_path = PathBuf::from(format!("tests/shell/call{script_extension}"))
247-
.canonicalize()
248-
.unwrap();
249246
let binary_path = cargo_bin!("sncast");
247+
let command = os_specific_shell(&Utf8PathBuf::from("tests/shell/call"));
250248

251-
let command = if cfg!(windows) {
252-
Command::new("powershell")
253-
.arg("-ExecutionPolicy")
254-
.arg("Bypass")
255-
.arg("-File")
256-
.arg(test_path)
257-
} else {
258-
Command::new(test_path)
259-
};
249+
let snapbox = command
250+
.arg(binary_path)
251+
.arg(URL)
252+
.arg(DATA_TRANSFORMER_CONTRACT_ADDRESS_SEPOLIA);
253+
snapbox.assert().success();
254+
}
255+
256+
#[test]
257+
fn test_leading_negative_values() {
258+
let binary_path = cargo_bin!("sncast");
259+
let command = os_specific_shell(&Utf8PathBuf::from("tests/shell/call_unsigned"));
260260

261261
let snapbox = command
262262
.arg(binary_path)

crates/sncast/tests/e2e/deploy.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ use crate::helpers::fixtures::{
88
get_transaction_hash, get_transaction_receipt,
99
};
1010
use crate::helpers::runner::runner;
11+
use crate::helpers::shell::os_specific_shell;
12+
use camino::Utf8PathBuf;
1113
use indoc::indoc;
1214
use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_contains};
13-
use snapbox::cmd::{Command, cargo_bin};
15+
use snapbox::cmd::cargo_bin;
1416
use sncast::AccountType;
1517
use sncast::helpers::constants::OZ_CLASS_HASH;
1618
use sncast::helpers::fee::FeeArgs;
1719
use starknet::core::types::TransactionReceipt::Deploy;
1820
use starknet_types_core::felt::Felt;
19-
use std::path::PathBuf;
2021
use tempfile::tempdir;
2122
use test_case::test_case;
2223

@@ -351,22 +352,8 @@ fn test_too_low_gas() {
351352
#[tokio::test]
352353
async fn test_happy_case_shell() {
353354
let tempdir = create_and_deploy_oz_account().await;
354-
355-
let script_extension = if cfg!(windows) { ".ps1" } else { ".sh" };
356-
let test_path = PathBuf::from(format!("tests/shell/deploy{script_extension}"))
357-
.canonicalize()
358-
.unwrap();
359355
let binary_path = cargo_bin!("sncast");
360-
361-
let command = if cfg!(windows) {
362-
Command::new("powershell")
363-
.arg("-ExecutionPolicy")
364-
.arg("Bypass")
365-
.arg("-File")
366-
.arg(test_path)
367-
} else {
368-
Command::new(test_path)
369-
};
356+
let command = os_specific_shell(&Utf8PathBuf::from("tests/shell/deploy"));
370357

371358
let snapbox = command
372359
.current_dir(tempdir.path())

crates/sncast/tests/e2e/invoke.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ use crate::helpers::fixtures::{
88
get_transaction_hash, get_transaction_receipt,
99
};
1010
use crate::helpers::runner::runner;
11+
use crate::helpers::shell::os_specific_shell;
12+
use camino::Utf8PathBuf;
1113
use indoc::indoc;
1214
use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_contains};
13-
use snapbox::cmd::{Command, cargo_bin};
15+
use snapbox::cmd::cargo_bin;
1416
use sncast::AccountType;
1517
use sncast::helpers::constants::{ARGENT_CLASS_HASH, OZ_CLASS_HASH};
1618
use sncast::helpers::fee::FeeArgs;
1719
use starknet::core::types::TransactionReceipt::Invoke;
1820
use starknet_types_core::felt::Felt;
19-
use std::path::PathBuf;
2021
use tempfile::tempdir;
2122
use test_case::test_case;
2223

@@ -339,22 +340,8 @@ async fn test_happy_case_cairo_expression_calldata() {
339340
#[tokio::test]
340341
async fn test_happy_case_shell() {
341342
let tempdir = create_and_deploy_oz_account().await;
342-
343-
let script_extension = if cfg!(windows) { ".ps1" } else { ".sh" };
344-
let test_path = PathBuf::from(format!("tests/shell/invoke{script_extension}"))
345-
.canonicalize()
346-
.unwrap();
347343
let binary_path = cargo_bin!("sncast");
348-
349-
let command = if cfg!(windows) {
350-
Command::new("powershell")
351-
.arg("-ExecutionPolicy")
352-
.arg("Bypass")
353-
.arg("-File")
354-
.arg(test_path)
355-
} else {
356-
Command::new(test_path)
357-
};
344+
let command = os_specific_shell(&Utf8PathBuf::from("tests/shell/invoke"));
358345

359346
let snapbox = command
360347
.current_dir(tempdir.path())

crates/sncast/tests/helpers/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const NETWORK: &str = "testnet";
1111
pub const SEED: u32 = 1_053_545_548;
1212

1313
// Block number used by devnet to fork the Sepolia testnet network in the tests
14-
pub const FORK_BLOCK_NUMBER: u32 = 369_169;
14+
pub const FORK_BLOCK_NUMBER: u32 = 721_720;
1515

1616
pub const CONTRACTS_DIR: &str = "tests/data/contracts";
1717
pub const SCRIPTS_DIR: &str = "tests/data/scripts";
@@ -38,4 +38,4 @@ pub const CONSTRUCTOR_WITH_PARAMS_CONTRACT_CLASS_HASH_SEPOLIA: &str =
3838
"0x59426c817fb8103edebdbf1712fa084c6744b2829db9c62d1ea4dce14ee6ded";
3939

4040
pub const DATA_TRANSFORMER_CONTRACT_ADDRESS_SEPOLIA: &str =
41-
"0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd";
41+
"0x00351c816183324878714973f3da1a43c1a40d661b8dac5cb69294cc333342ed";

crates/sncast/tests/helpers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod env;
44
pub mod fee;
55
pub mod fixtures;
66
pub mod runner;
7+
pub mod shell;

0 commit comments

Comments
 (0)