From d7e626d25bb7016742339ab9f60ecd4e546cccfd Mon Sep 17 00:00:00 2001 From: maciektr Date: Wed, 20 Mar 2024 18:00:30 +0100 Subject: [PATCH] Allow testing without gas calculation (#1211) - **Update Cairo** - **Allow testing without gas calculation** --- Cargo.lock | 61 ++++++++++++---------- Cargo.toml | 44 ++++++++-------- extensions/scarb-cairo-run/Cargo.toml | 2 +- extensions/scarb-cairo-test/Cargo.toml | 3 ++ extensions/scarb-cairo-test/src/main.rs | 21 +++++++- extensions/scarb-cairo-test/tests/build.rs | 55 +++++++++++++++++++ 6 files changed, 133 insertions(+), 53 deletions(-) create mode 100644 extensions/scarb-cairo-test/tests/build.rs diff --git a/Cargo.lock b/Cargo.lock index 2e9e2110c..ce04ca958 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -554,7 +554,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-utils", "indoc", @@ -567,7 +567,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-lang-defs", @@ -589,7 +589,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-utils", ] @@ -597,7 +597,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -613,7 +613,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -624,7 +624,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-utils", "good_lp", @@ -633,7 +633,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -646,7 +646,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -666,7 +666,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -696,7 +696,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -743,7 +743,7 @@ version = "1.0.0" [[package]] name = "cairo-lang-parser" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -762,7 +762,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -780,7 +780,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "quote", @@ -790,7 +790,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -803,7 +803,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "ark-ff", "ark-secp256k1", @@ -833,7 +833,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -857,7 +857,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-felt", @@ -882,7 +882,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -896,7 +896,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -910,7 +910,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -932,7 +932,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "assert_matches", "cairo-felt", @@ -952,7 +952,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -961,7 +961,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-felt", @@ -991,7 +991,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-felt", "cairo-lang-casm", @@ -1015,7 +1015,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -1030,7 +1030,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "genco", "xshell", @@ -1039,7 +1039,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-felt", @@ -1066,7 +1066,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "anyhow", "cairo-felt", @@ -1088,7 +1088,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.6.3" -source = "git+https://github.com/starkware-libs/cairo?rev=0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a#0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" +source = "git+https://github.com/starkware-libs/cairo?rev=53db45434c501e56ac84f1b27fac311183f14dbe#53db45434c501e56ac84f1b27fac311183f14dbe" dependencies = [ "env_logger", "hashbrown 0.14.3", @@ -4591,10 +4591,13 @@ name = "scarb-cairo-test" version = "2.6.3" dependencies = [ "anyhow", + "assert_fs", "cairo-lang-test-plugin", "cairo-lang-test-runner", "clap", + "indoc", "scarb-metadata 1.11.1", + "scarb-test-support", "scarb-ui", "serde_json", "snapbox", diff --git a/Cargo.toml b/Cargo.toml index 144cf9ae6..2373e1db0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,28 +35,28 @@ assert_fs = "1" async-trait = "0.1" axum = { version = "0.6", features = ["http2"] } cairo-felt = "0.9.1" -cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "0e51256f50ce6e20ba746f7d1dcfea3aaaacb86a", features = ["env_logger"] } +cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "53db45434c501e56ac84f1b27fac311183f14dbe", features = ["env_logger"] } camino = { version = "1", features = ["serde1"] } cargo_metadata = ">=0.18" clap = { version = "4", features = ["derive", "env", "string"] } diff --git a/extensions/scarb-cairo-run/Cargo.toml b/extensions/scarb-cairo-run/Cargo.toml index 5ca20d3e9..5b94cd479 100644 --- a/extensions/scarb-cairo-run/Cargo.toml +++ b/extensions/scarb-cairo-run/Cargo.toml @@ -8,7 +8,6 @@ authors.workspace = true [dependencies] anyhow.workspace = true -assert_fs.workspace = true cairo-felt.workspace = true cairo-lang-runner.workspace = true cairo-lang-sierra.workspace = true @@ -25,3 +24,4 @@ thiserror.workspace = true [dev-dependencies] scarb-test-support = { path = "../../utils/scarb-test-support" } snapbox.workspace = true +assert_fs.workspace = true diff --git a/extensions/scarb-cairo-test/Cargo.toml b/extensions/scarb-cairo-test/Cargo.toml index f4cb381e3..4df7950d0 100644 --- a/extensions/scarb-cairo-test/Cargo.toml +++ b/extensions/scarb-cairo-test/Cargo.toml @@ -18,3 +18,6 @@ serde_json.workspace = true [dev-dependencies] snapbox.workspace = true test-for-each-example = { path = "../../utils/test-for-each-example" } +scarb-test-support = { path = "../../utils/scarb-test-support" } +assert_fs.workspace = true +indoc.workspace = true diff --git a/extensions/scarb-cairo-test/src/main.rs b/extensions/scarb-cairo-test/src/main.rs index 20d44c30c..27b407082 100644 --- a/extensions/scarb-cairo-test/src/main.rs +++ b/extensions/scarb-cairo-test/src/main.rs @@ -5,7 +5,9 @@ use cairo_lang_test_plugin::TestCompilation; use cairo_lang_test_runner::{CompiledTestRunner, RunProfilerConfig, TestRunConfig}; use clap::Parser; -use scarb_metadata::{Metadata, MetadataCommand, PackageMetadata, ScarbCommand, TargetMetadata}; +use scarb_metadata::{ + Metadata, MetadataCommand, PackageId, PackageMetadata, ScarbCommand, TargetMetadata, +}; use scarb_ui::args::PackagesFilter; /// Execute all unit tests of a local package. @@ -67,6 +69,7 @@ fn main() -> Result<()> { include_ignored: args.include_ignored, ignored: args.ignored, run_profiler: RunProfilerConfig::None, + gas_enabled: is_gas_enabled(&metadata, &package.id, target), }; let runner = CompiledTestRunner::new(test_compilation, config); runner.run(None)?; @@ -77,6 +80,22 @@ fn main() -> Result<()> { Ok(()) } +fn is_gas_enabled(metadata: &Metadata, package_id: &PackageId, target: &TargetMetadata) -> bool { + metadata + .compilation_units + .iter() + .find(|cu| { + cu.package == *package_id && cu.target.kind == "test" && cu.target.name == target.name + }) + .map(|cu| cu.compiler_config.clone()) + .and_then(|c| { + c.as_object() + .and_then(|c| c.get("enable_gas").and_then(|x| x.as_bool())) + }) + // Defaults to true, meaning gas enabled - relies on cli config then. + .unwrap_or(true) +} + fn find_testable_targets(package: &PackageMetadata) -> Vec<&TargetMetadata> { package .targets diff --git a/extensions/scarb-cairo-test/tests/build.rs b/extensions/scarb-cairo-test/tests/build.rs new file mode 100644 index 000000000..2b8f01f58 --- /dev/null +++ b/extensions/scarb-cairo-test/tests/build.rs @@ -0,0 +1,55 @@ +use assert_fs::TempDir; +use indoc::indoc; +use scarb_test_support::command::Scarb; +use scarb_test_support::project_builder::ProjectBuilder; + +#[test] +fn can_test_without_gas() { + let t = TempDir::new().unwrap(); + ProjectBuilder::start() + .name("hello") + .lib_cairo(indoc! {r#" + fn foo(mut shape: Span) -> usize { + let mut result: usize = 1; + + loop { + match shape.pop_front() { + Option::Some(item) => { result *= *item; }, + Option::None => { break; } + }; + }; + + result + } + + + #[cfg(test)] + mod tests { + use super::foo; + + #[test] + fn test_foo() { + foo(array![1, 2].span()); + } + } + "#}) + .manifest_extra(indoc! {r#" + [cairo] + enable-gas = false + "#}) + .build(&t); + Scarb::quick_snapbox() + .arg("cairo-test") + .current_dir(&t) + .assert() + .success() + .stdout_matches(indoc! {r#" + [..]Compiling test(hello_unittest) hello v1.0.0 ([..]Scarb.toml) + [..]Finished release target(s) in [..] + testing hello ... + running 1 test + test hello::tests::test_foo ... ok + test result: ok. 1 passed; 0 failed; 0 ignored; 0 filtered out; + + "#}); +}