diff --git a/extensions/scarb-cairo-run/src/deserialization.rs b/extensions/scarb-cairo-run/src/deserialization.rs index cd833a86b..5673626ee 100644 --- a/extensions/scarb-cairo-run/src/deserialization.rs +++ b/extensions/scarb-cairo-run/src/deserialization.rs @@ -15,7 +15,7 @@ pub enum ArgsError { #[error("failed to convert slice to array: {0}")] ArrayFromSlice(#[from] std::array::TryFromSliceError), #[error("number out of range")] - NumberOutOfRange, + NumberOutOfRange(#[from] starknet_types_core::felt::FromStrError), #[error("failed to parse arguments: {0}")] ParseError(#[from] serde_json::Error), } @@ -91,8 +91,8 @@ impl Args { for arg in iterator { match arg { Value::Number(n) => { - let n = n.as_u64().ok_or(ArgsError::NumberOutOfRange)?; - args.push(Arg::Value(Felt252::from(n))); + let n = Felt252::from_str(n.to_string().as_str())?; + args.push(Arg::Value(n)); } Value::String(n) => { let n = num_bigint::BigUint::from_str(n)?; diff --git a/extensions/scarb-cairo-run/tests/arguments.rs b/extensions/scarb-cairo-run/tests/arguments.rs index d7e5e3f55..1efd71bab 100644 --- a/extensions/scarb-cairo-run/tests/arguments.rs +++ b/extensions/scarb-cairo-run/tests/arguments.rs @@ -42,6 +42,35 @@ fn valid_number_of_args() { "#}); } +#[test] +fn can_deserialize_big_number() { + let t = TempDir::new().unwrap(); + + ProjectBuilder::start() + .name("hello") + .version("0.1.0") + .lib_cairo(indoc! {r#" + fn main(n: felt252) -> felt252 { + n + } + "#}) + .build(&t); + + Scarb::quick_snapbox() + .arg("cairo-run") + .arg("--") + .arg(r#"[1129815197211541481934112806673325772687763881719835256646064516195041515616]"#) + .current_dir(&t) + .assert() + .success() + .stdout_matches(indoc! {r#" + Compiling hello v0.1.0 ([..]/Scarb.toml) + Finished release target(s) in [..] + Running hello + Run completed successfully, returning [1129815197211541481934112806673325772687763881719835256646064516195041515616] + "#}); +} + #[test] fn invalid_number_of_args() { let t = TempDir::new().unwrap();