Skip to content

Commit aa92710

Browse files
committed
Run tests on a new and compatibility plugin
commit-id:aa2a40e5
1 parent f768358 commit aa92710

File tree

41 files changed

+819
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+819
-301
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
tool: nextest@0.9.98
3939
- name: Build and archive tests
40-
run: cargo nextest archive --release -p forge --archive-file 'nextest-archive-${{ runner.os }}.tar.zst'
40+
run: cargo nextest archive --release -p forge --features skip_plugin_checks --archive-file 'nextest-archive-${{ runner.os }}.tar.zst'
4141
- name: Upload archive to workflow
4242
uses: actions/upload-artifact@v4
4343
with:
@@ -106,6 +106,7 @@ jobs:
106106
- uses: actions/checkout@v4
107107
- uses: dtolnay/rust-toolchain@stable
108108
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6
109+
- uses: asdf-vm/actions/install@1902764435ca0dd2f3388eea723a4f92a4eb8302
109110
- uses: software-mansion/setup-scarb@v1
110111
- uses: software-mansion/setup-universal-sierra-compiler@v1
111112
- uses: taiki-e/install-action@v2
@@ -117,6 +118,17 @@ jobs:
117118
- name: nextest partition ${{ matrix.partition }}/3
118119
run: cargo nextest run --no-fail-fast --partition 'count:${{ matrix.partition }}/3' --archive-file 'nextest-archive-${{ runner.os }}.tar.zst' e2e
119120

121+
test-plugin-checks:
122+
name: Test plugin across different scarb versions
123+
runs-on: ubuntu-latest
124+
steps:
125+
- uses: actions/checkout@v4
126+
- uses: dtolnay/rust-toolchain@stable
127+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6
128+
- uses: software-mansion/setup-universal-sierra-compiler@v1
129+
- uses: asdf-vm/actions/install@1902764435ca0dd2f3388eea723a4f92a4eb8302
130+
- run: cargo test --package forge e2e::plugin_versions
131+
120132
test-requirements-check-special-conditions:
121133
name: Test requirements check special conditions
122134
runs-on: ubuntu-latest

.github/workflows/scheduled.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
run: |
9292
curl -L https://raw.githubusercontent.com/software-mansion/cairo-coverage/main/scripts/install.sh | sh
9393
94-
- run: cargo test --release -p forge e2e
94+
- run: cargo test --release -p forge --features skip_plugin_checks e2e
9595

9696
test-cast:
9797
if: github.event.repository.fork == false
@@ -151,16 +151,34 @@ jobs:
151151
uses: ./.github/workflows/_build-plugin-binaries.yml
152152
with:
153153
overridden_plugin_version: ${{ needs.get-version.outputs.version }}-test.${{ github.run_id }}
154+
plugin_name: 'snforge-scarb-plugin'
154155

155156
publish-plugin:
156157
needs: [get-version, build-plugin-binaries]
157158
uses: ./.github/workflows/_publish-plugin.yml
158159
secrets: inherit
159160
with:
160161
overridden_plugin_version: ${{ needs.get-version.outputs.version }}-test.${{ github.run_id }}
162+
plugin_name: 'snforge-scarb-plugin'
163+
164+
build-compatibility-plugin-binaries:
165+
name: Build compatibility plugin binaries
166+
needs: get-version
167+
uses: ./.github/workflows/_build-plugin-binaries.yml
168+
with:
169+
overridden_plugin_version: ${{ needs.get-version.outputs.version }}-test.${{ github.run_id }}
170+
plugin_name: 'snforge-scarb-plugin-compatibility'
171+
172+
publish-compatibility-plugin:
173+
needs: [get-version, build-compatibility-plugin-binaries]
174+
uses: ./.github/workflows/_publish-plugin.yml
175+
secrets: inherit
176+
with:
177+
overridden_plugin_version: ${{ needs.get-version.outputs.version }}-test.${{ github.run_id }}
178+
plugin_name: 'snforge-scarb-plugin-compatibility'
161179

162180
publish-std:
163-
needs: [get-version, publish-plugin]
181+
needs: [get-version, publish-plugin, publish-compatibility-plugin]
164182
uses: ./.github/workflows/publish-std.yml
165183
secrets: inherit
166184
with:

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
scarb nightly-2025-06-18
1+
scarb nightly-2025-06-18 2.10.1
22
starknet-devnet 0.4.3

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.

crates/cheatnet/tests/contracts/src/panic_call.cairo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ mod PanicCall {
77
fn panic_call(ref self: ContractState) {
88
panic(
99
array![
10-
'shortstring', 0, 0x800000000000011000000000000000000000000000000000000000000000000,
10+
'shortstring',
11+
0,
12+
0x800000000000011000000000000000000000000000000000000000000000000,
1113
'shortstring2',
1214
],
1315
);

crates/forge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ scarb_2_9_1 = []
1111
no_scarb_installed = []
1212
debugging = []
1313
assert_non_exact_gas = ["test_utils/assert_non_exact_gas"]
14+
skip_plugin_checks = []
1415
supports-panic-backtrace = []
1516

1617
[dependencies]

crates/forge/src/new.rs

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ struct TemplateManifestConfig {
5050
impl TemplateManifestConfig {
5151
fn add_dependencies(
5252
&self,
53-
scarb_version: &Version,
5453
scarb_manifest_path: &PathBuf,
54+
use_snforge_std_compatibility: bool,
5555
) -> Result<()> {
5656
if env::var("DEV_DISABLE_SNFORGE_STD_DEPENDENCY").is_err() {
5757
// TODO: Check Scarb `2.12`
58-
let snforge_package = if scarb_version.build.is_empty() {
58+
let snforge_package = if use_snforge_std_compatibility {
5959
"snforge_std_compatibility"
6060
} else {
6161
"snforge_std"
@@ -76,7 +76,11 @@ impl TemplateManifestConfig {
7676
Ok(())
7777
}
7878

79-
fn update_config(&self, scarb_manifest_path: &Path) -> Result<()> {
79+
fn update_config(
80+
&self,
81+
scarb_manifest_path: &Path,
82+
use_snforge_std_compatibility: bool,
83+
) -> Result<()> {
8084
let scarb_toml_content = fs::read_to_string(scarb_manifest_path)?;
8185
let mut document = scarb_toml_content
8286
.parse::<DocumentMut>()
@@ -89,7 +93,7 @@ impl TemplateManifestConfig {
8993
set_cairo_edition(&mut document, CAIRO_EDITION);
9094
add_test_script(&mut document);
9195
add_assert_macros(&mut document)?;
92-
add_allow_prebuilt_macros(&mut document)?;
96+
add_allow_prebuilt_macros(&mut document, use_snforge_std_compatibility)?;
9397

9498
if self.fork_config {
9599
add_fork_config(&mut document)?;
@@ -184,18 +188,30 @@ fn overwrite_or_copy_template_files(
184188
template_path: &Path,
185189
project_path: &Path,
186190
project_name: &str,
191+
use_snforge_std_compatibility: bool,
187192
) -> Result<()> {
188193
for entry in dir.entries() {
189194
let path_without_template_name = entry.path().strip_prefix(template_path)?;
190195
let destination = project_path.join(path_without_template_name);
191196
match entry {
192197
DirEntry::Dir(dir) => {
193198
fs::create_dir_all(&destination)?;
194-
overwrite_or_copy_template_files(dir, template_path, project_path, project_name)?;
199+
overwrite_or_copy_template_files(
200+
dir,
201+
template_path,
202+
project_path,
203+
project_name,
204+
use_snforge_std_compatibility,
205+
)?;
195206
}
196207
DirEntry::File(file) => {
197208
let contents = file.contents();
198209
let contents = replace_project_name(contents, project_name)?;
210+
let contents = if use_snforge_std_compatibility {
211+
replace_imports_snforge_std_with_compatibility(&contents)?
212+
} else {
213+
contents
214+
};
199215
fs::write(destination, contents)?;
200216
}
201217
}
@@ -204,6 +220,12 @@ fn overwrite_or_copy_template_files(
204220
Ok(())
205221
}
206222

223+
fn replace_imports_snforge_std_with_compatibility(contents: &[u8]) -> Result<Vec<u8>> {
224+
let contents = std::str::from_utf8(contents).context("UTF-8 error")?;
225+
let contents = contents.replace("snforge_std::", "snforge_std_compatibility::");
226+
Ok(contents.into_bytes())
227+
}
228+
207229
fn replace_project_name(contents: &[u8], project_name: &str) -> Result<Vec<u8>> {
208230
let contents = std::str::from_utf8(contents).context("UTF-8 error")?;
209231
let contents = contents.replace("{{ PROJECT_NAME }}", project_name);
@@ -251,7 +273,10 @@ fn add_assert_macros(document: &mut DocumentMut) -> Result<()> {
251273
Ok(())
252274
}
253275

254-
fn add_allow_prebuilt_macros(document: &mut DocumentMut) -> Result<()> {
276+
fn add_allow_prebuilt_macros(
277+
document: &mut DocumentMut,
278+
use_snforge_std_compatibility: bool,
279+
) -> Result<()> {
255280
let tool_section = document.entry("tool").or_insert(Item::Table(Table::new()));
256281
let tool_table = tool_section
257282
.as_table_mut()
@@ -261,7 +286,11 @@ fn add_allow_prebuilt_macros(document: &mut DocumentMut) -> Result<()> {
261286
let mut scarb_table = Table::new();
262287

263288
let mut allow_prebuilt_macros = Array::new();
264-
allow_prebuilt_macros.push("snforge_std");
289+
if use_snforge_std_compatibility {
290+
allow_prebuilt_macros.push("snforge_std_compatibility");
291+
} else {
292+
allow_prebuilt_macros.push("snforge_std");
293+
}
265294

266295
scarb_table.insert(
267296
"allow-prebuilt-plugins",
@@ -371,21 +400,32 @@ pub fn new(
371400
create_snfoundry_manifest(&snfoundry_manifest_path)?;
372401
}
373402

403+
// TODO: Check Scarb `2.12`
404+
let use_snforge_compatibility = scarb_version.build.is_empty();
405+
374406
let template_config = TemplateManifestConfig::try_from(&template)?;
375-
template_config.add_dependencies(&scarb_version, &scarb_manifest_path)?;
376-
template_config.update_config(&scarb_manifest_path)?;
407+
template_config.add_dependencies(&scarb_manifest_path, use_snforge_compatibility)?;
408+
template_config.update_config(&scarb_manifest_path, use_snforge_compatibility)?;
377409

378410
let template_dir = get_template_dir(&template)?;
379-
overwrite_or_copy_template_files(&template_dir, template_dir.path(), &project_path, &name)?;
411+
overwrite_or_copy_template_files(
412+
&template_dir,
413+
template_dir.path(),
414+
&project_path,
415+
&name,
416+
use_snforge_compatibility,
417+
)?;
380418

381419
extend_gitignore(&project_path)?;
382420

383421
// Fetch to create lock file.
384-
ScarbCommand::new_with_stdio()
385-
.manifest_path(scarb_manifest_path)
386-
.arg("fetch")
387-
.run()
388-
.context("Failed to fetch created project")?;
422+
if env::var("DEV_USE_OFFLINE_MODE").is_err() {
423+
ScarbCommand::new_with_stdio()
424+
.manifest_path(scarb_manifest_path)
425+
.arg("fetch")
426+
.run()
427+
.context("Failed to fetch created project")?;
428+
}
389429

390430
Ok(())
391431
}

crates/forge/src/scarb.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,14 @@ mod tests {
120120
use crate::scarb::config::ForkTarget;
121121
use assert_fs::TempDir;
122122
use assert_fs::fixture::{FileWriteStr, PathChild, PathCopy};
123-
use camino::Utf8PathBuf;
124123
use cheatnet::runtime_extensions::forge_config_extension::config::BlockId;
125124
use configuration::load_package_config;
126125
use forge_runner::forge_config::ForgeTrackedResource;
127126
use indoc::{formatdoc, indoc};
128127
use scarb_api::metadata::MetadataCommandExt;
129128
use scarb_metadata::PackageId;
130129
use std::env;
131-
use std::str::FromStr;
132-
use test_utils::tempdir_with_tool_versions;
130+
use test_utils::{get_snforge_std_entry, tempdir_with_tool_versions};
133131

134132
fn setup_package(package_name: &str) -> TempDir {
135133
let temp = tempdir_with_tool_versions().unwrap();
@@ -139,12 +137,7 @@ mod tests {
139137
)
140138
.unwrap();
141139

142-
let snforge_std_path = Utf8PathBuf::from_str("../../snforge_std")
143-
.unwrap()
144-
.canonicalize_utf8()
145-
.unwrap()
146-
.to_string()
147-
.replace('\\', "/");
140+
let snforge_std_entry = get_snforge_std_entry().unwrap();
148141

149142
let manifest_path = temp.child("Scarb.toml");
150143
manifest_path
@@ -156,7 +149,7 @@ mod tests {
156149
157150
[dependencies]
158151
starknet = "2.4.0"
159-
snforge_std = {{ path = "{}" }}
152+
{}
160153
161154
[[tool.snforge.fork]]
162155
name = "FIRST_FORK_NAME"
@@ -179,7 +172,7 @@ mod tests {
179172
block_id.tag = "latest"
180173
"#,
181174
package_name,
182-
snforge_std_path
175+
snforge_std_entry
183176
))
184177
.unwrap();
185178

crates/forge/test_utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition.workspace = true
99
assert_non_exact_gas = []
1010

1111
[dependencies]
12+
walkdir.workspace = true
1213
anyhow.workspace = true
1314
shared.workspace = true
1415
blockifier.workspace = true

crates/forge/test_utils/src/lib.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
pub mod runner;
22
pub mod running_tests;
33

4-
use std::path::PathBuf;
5-
64
use anyhow::Result;
75
use assert_fs::fixture::PathCopy;
6+
use camino::Utf8PathBuf;
87
use project_root::get_project_root;
98
use scarb_api::ScarbCommand;
109
use semver::Version;
10+
use std::str::FromStr;
1111

1212
const DEFAULT_ASSERT_MACROS: Version = Version::new(0, 1, 0);
1313
const MINIMAL_SCARB_FOR_CORRESPONDING_ASSERT_MACROS: Version = Version::new(2, 8, 0);
1414

15-
pub fn get_local_snforge_std_absolute_path() -> Result<PathBuf> {
16-
Ok(get_project_root()?.canonicalize()?.join("snforge_std"))
17-
}
18-
1915
pub fn tempdir_with_tool_versions() -> Result<assert_fs::TempDir> {
2016
let project_root = get_project_root()?;
2117
let temp_dir = assert_fs::TempDir::new()?;
@@ -33,3 +29,35 @@ pub fn get_assert_macros_version() -> Result<Version> {
3329
};
3430
Ok(assert_macros_version)
3531
}
32+
33+
#[must_use]
34+
pub fn get_std_name() -> String {
35+
if use_snforge_std_compatibility() {
36+
"snforge_std_compatibility".to_string()
37+
} else {
38+
"snforge_std".to_string()
39+
}
40+
}
41+
42+
pub fn get_std_path() -> Result<String> {
43+
let name = get_std_name();
44+
Ok(Utf8PathBuf::from_str(&format!("../../{name}"))?
45+
.canonicalize_utf8()?
46+
.to_string())
47+
}
48+
49+
pub fn get_snforge_std_entry() -> Result<String> {
50+
let name = get_std_name();
51+
let path = get_std_path()?;
52+
53+
Ok(format!("{name} = {{ path = \"{path}\" }}"))
54+
}
55+
56+
#[must_use]
57+
pub fn use_snforge_std_compatibility() -> bool {
58+
let scarb_version_output = ScarbCommand::version()
59+
.run()
60+
.expect("Failed to get scarb version");
61+
// TODO: Replace with condition for `2.12`
62+
scarb_version_output.scarb.build.is_empty()
63+
}

0 commit comments

Comments
 (0)