Skip to content

Commit dfe8de7

Browse files
committed
Refactor execute tests
1 parent ef51756 commit dfe8de7

File tree

6 files changed

+105
-153
lines changed

6 files changed

+105
-153
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/scarb-execute/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ console.workspace = true
2525
create-output-dir = { path = "../../utils/create-output-dir" }
2626
indoc.workspace = true
2727
mimalloc = { workspace = true, features = ["secure"] }
28+
num-bigint = { version = "0.4", features = ["serde"] }
2829
predicates.workspace = true
2930
scarb-extensions-cli = { path = "../../utils/scarb-extensions-cli", default-features = false, features = ["execute"] }
31+
scarb-fs-utils = { path = "../../utils/scarb-fs-utils" }
3032
scarb-metadata = { path = "../../scarb-metadata" }
3133
scarb-oracle-hint-service = { path = "../../utils/scarb-oracle-hint-service" }
3234
scarb-ui = { path = "../../utils/scarb-ui" }
3335
serde.workspace = true
3436
serde_json.workspace = true
3537
stwo-cairo-adapter.workspace = true
38+
test-case.workspace = true
3639
thousands.workspace = true
3740
tracing-subscriber.workspace = true
38-
num-bigint = { version = "0.4", features = ["serde"] }
39-
scarb-fs-utils = { path = "../../utils/scarb-fs-utils" }
4041

4142
[dev-dependencies]
4243
assert_fs.workspace = true
Lines changed: 27 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,19 @@
11
use assert_fs::TempDir;
22
use assert_fs::fixture::{FileWriteStr, PathChild};
3-
use indoc::indoc;
3+
use indoc::{formatdoc, indoc};
44
use scarb_test_support::command::Scarb;
55
use scarb_test_support::project_builder::ProjectBuilder;
6-
7-
#[test]
8-
fn standalone_can_take_big_number_as_arg() {
9-
let t = TempDir::new().unwrap();
10-
11-
ProjectBuilder::start()
12-
.name("hello")
13-
.version("0.1.0")
14-
.manifest_extra(indoc! {r#"
15-
[executable]
16-
17-
[cairo]
18-
enable-gas = false
19-
"#})
20-
.dep_cairo_execute()
21-
.lib_cairo(indoc! {r#"
22-
#[executable]
23-
fn main(a: felt252, b: felt252) -> felt252 {
24-
b
25-
}
26-
"#})
27-
.build(&t);
28-
29-
Scarb::quick_command()
30-
.arg("execute")
31-
.arg("--print-program-output")
32-
.arg("--arguments")
33-
.arg(r#"1,1129815197211541481934112806673325772687763881719835256646064516195041515616"#)
34-
.current_dir(&t)
35-
.assert()
36-
.success()
37-
.stdout_eq(indoc! {r#"
38-
[..]Compiling hello v0.1.0 ([..]/Scarb.toml)
39-
[..]Finished `dev` profile target(s) in [..]
40-
[..]Executing hello
41-
Program output:
42-
1129815197211541481934112806673325772687763881719835256646064516195041515616
43-
Saving output to: target/execute/hello/execution1
44-
"#});
45-
}
46-
47-
#[test]
48-
fn standalone_can_read_arguments_from_file() {
6+
use test_case::test_case;
7+
8+
#[test_case(
9+
"standalone",
10+
"1129815197211541481934112806673325772687763881719835256646064516195041515616"
11+
)]
12+
#[test_case(
13+
"bootloader",
14+
"1\n3\n-1272769738511508193392446484420387256363817420616635924344207712676117344847\n1129815197211541481934112806673325772687763881719835256646064516195041515616"
15+
)]
16+
fn can_take_big_number_as_arg(target: &str, output: &str) {
4917
let t = TempDir::new().unwrap();
5018

5119
ProjectBuilder::start()
@@ -66,73 +34,34 @@ fn standalone_can_read_arguments_from_file() {
6634
"#})
6735
.build(&t);
6836

69-
t.child("args.txt")
70-
.write_str(r#"["0x1","0x27F73E6C94FA8249EC9F2F4EEC607ACC97FA632C9E8FB6C49437E62390D9860"]"#)
71-
.unwrap();
72-
73-
Scarb::quick_command()
74-
.arg("execute")
75-
.arg("--print-program-output")
76-
.args(["--arguments-file", "args.txt"])
77-
.current_dir(&t)
78-
.assert()
79-
.success()
80-
.stdout_eq(indoc! {r#"
81-
[..]Compiling hello v0.1.0 ([..]/Scarb.toml)
82-
[..]Finished `dev` profile target(s) in [..]
83-
[..]Executing hello
84-
Program output:
85-
1129815197211541481934112806673325772687763881719835256646064516195041515616
86-
Saving output to: target/execute/hello/execution1
87-
"#});
88-
}
89-
90-
#[test]
91-
fn bootloader_can_take_big_number_as_arg() {
92-
let t = TempDir::new().unwrap();
93-
94-
ProjectBuilder::start()
95-
.name("hello")
96-
.version("0.1.0")
97-
.manifest_extra(indoc! {r#"
98-
[executable]
99-
100-
[cairo]
101-
enable-gas = false
102-
"#})
103-
.dep_cairo_execute()
104-
.lib_cairo(indoc! {r#"
105-
#[executable]
106-
fn main(a: felt252, b: felt252) -> felt252 {
107-
b
108-
}
109-
"#})
110-
.build(&t);
111-
11237
Scarb::quick_command()
11338
.arg("execute")
11439
.arg("--print-program-output")
115-
.arg("--target=bootloader")
40+
.arg(format!("--target={target}"))
11641
.arg("--arguments")
11742
.arg(r#"1,1129815197211541481934112806673325772687763881719835256646064516195041515616"#)
11843
.current_dir(&t)
11944
.assert()
12045
.success()
121-
.stdout_eq(indoc! {r#"
46+
.stdout_eq(formatdoc! {r#"
12247
[..]Compiling hello v0.1.0 ([..]/Scarb.toml)
12348
[..]Finished `dev` profile target(s) in [..]
12449
[..]Executing hello
12550
Program output:
126-
1
127-
3
128-
-1272769738511508193392446484420387256363817420616635924344207712676117344847
129-
1129815197211541481934112806673325772687763881719835256646064516195041515616
51+
{output}
13052
Saving output to: target/execute/hello/execution1
13153
"#});
13254
}
13355

134-
#[test]
135-
fn bootloader_can_read_arguments_from_file() {
56+
#[test_case(
57+
"standalone",
58+
"1129815197211541481934112806673325772687763881719835256646064516195041515616"
59+
)]
60+
#[test_case(
61+
"bootloader",
62+
"1\n3\n-1272769738511508193392446484420387256363817420616635924344207712676117344847\n1129815197211541481934112806673325772687763881719835256646064516195041515616"
63+
)]
64+
fn can_read_arguments_from_file(target: &str, output: &str) {
13665
let t = TempDir::new().unwrap();
13766

13867
ProjectBuilder::start()
@@ -159,21 +88,18 @@ fn bootloader_can_read_arguments_from_file() {
15988

16089
Scarb::quick_command()
16190
.arg("execute")
162-
.arg("--target=bootloader")
16391
.arg("--print-program-output")
92+
.arg(format!("--target={target}"))
16493
.args(["--arguments-file", "args.txt"])
16594
.current_dir(&t)
16695
.assert()
16796
.success()
168-
.stdout_eq(indoc! {r#"
97+
.stdout_eq(formatdoc! {r#"
16998
[..]Compiling hello v0.1.0 ([..]/Scarb.toml)
17099
[..]Finished `dev` profile target(s) in [..]
171100
[..]Executing hello
172101
Program output:
173-
1
174-
3
175-
-1272769738511508193392446484420387256363817420616635924344207712676117344847
176-
1129815197211541481934112806673325772687763881719835256646064516195041515616
102+
{output}
177103
Saving output to: target/execute/hello/execution1
178104
"#});
179105
}

0 commit comments

Comments
 (0)