-
Notifications
You must be signed in to change notification settings - Fork 246
improved validation for scarb version and scarb.toml config #2900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improved validation for scarb version and scarb.toml config #2900
Conversation
ksew1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests similar to found here:
https://github.com/foundry-rs/starknet-foundry/blob/master/crates/forge/tests/e2e/coverage.rs
Add delete this:
| "perhaps the contract was compiled without the following entry in Scarb.toml under [profile.dev.cairo]: |
And this:
| "perhaps the contract was compiled without the following entry in Scarb.toml under [profile.dev.cairo]: |
| Ok(()) | ||
| } | ||
|
|
||
| pub fn is_backtrace_enabled() -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this function also here:
| let is_backtrace_enabled = env::var(BACKTRACE_ENV).is_ok_and(|value| value == "1"); |
crates/forge-runner/src/backtrace.rs
Outdated
| env::var(BACKTRACE_ENV).is_ok_and(|value| value == "1") | ||
| } | ||
|
|
||
| fn contains_entry_with_value(table: &Table, key: &str, value: &str) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn contains_entry_with_value(table: &Table, key: &str, value: bool) -> bool {
table
.get(key)
.and_then(toml_edit::Item::as_bool)
.is_some_and(|entry| entry == value)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be taking value as a bool? Shouldn't it be a &str? @ksew1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be bool for 100%
… into improve_scarb_validation
|
Please fix:
|
|
@PoulavBhowmick03 any progress on this? |
apologies, was a little acquired, i will fix and modify the changes by tonight or tomorrow at max |
… into improve_scarb_validation
|
@ddoktorski PTAL |
crates/forge-runner/src/backtrace.rs
Outdated
| const BACKTRACE_ENV: &str = "SNFORGE_BACKTRACE"; | ||
| const MINIMAL_SCARB_VERSION: Version = Version::new(2, 8, 0); | ||
|
|
||
| const BACKTRACE_REQUIRED_ENTRIES: [(&str, &str); 2] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const BACKTRACE_REQUIRED_ENTRIES: [(&str, &str); 2] = [ | |
| const BACKTRACE_REQUIRED_ENTRIES: [(&str,bool); 2] = [ |
crates/forge-runner/src/backtrace.rs
Outdated
|
|
||
| let is_backtrace_enabled = env::var(BACKTRACE_ENV).is_ok_and(|value| value == "1"); | ||
| let is_backtrace_enabled = is_backtrace_enabled(); | ||
| if !is_backtrace_enabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if !is_backtrace_enabled { | |
| if !is_backtrace_enabled() { |
crates/forge-runner/src/backtrace.rs
Outdated
|
|
||
| let manifest = fs::read_to_string(&scarb_metadata.runtime_manifest)?.parse::<DocumentMut>()?; | ||
|
|
||
| let profile_cairo = manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe like this:
let has_needed_entries = manifest
.get("profile")
.and_then(|profile| profile.get(&scarb_metadata.current_profile))
.and_then(|profile| profile.get("cairo"))
.and_then(|cairo| cairo.as_table())
.is_some_and(|profile_cairo| {
BACKTRACE_REQUIRED_ENTRIES
.iter()
.all(|(key, value)| contains_entry_with_value(profile_cairo, key, *value))
});
ensure!(
has_needed_entries,
formatdoc! {
"Scarb.toml must have the following Cairo compiler configuration to run backtrace:
[profile.{profile}.cairo]
unstable-add-statements-functions-debug-info = true
unstable-add-statements-code-locations-debug-info = true
... other entries ...
",
profile = scarb_metadata.current_profile
},
);
crates/forge-runner/src/backtrace.rs
Outdated
| "perhaps the contract was compiled without the following entry in Scarb.toml under [profile.dev.cairo]: | ||
| unstable-add-statements-code-locations-debug-info = true | ||
| VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info).context( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info).context( | |
| VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info)?; |
crates/forge-runner/src/backtrace.rs
Outdated
| "perhaps the contract was compiled without the following entry in Scarb.toml under [profile.dev.cairo]: | ||
| unstable-add-statements-functions-debug-info = true | ||
| VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info).context( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info).context( | |
| VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info)?; |
|
@ksew1 PTAL |
ksew1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run cargo fmt before pushing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pleas add similar test:
| fn test_fail_on_scarb_version_lt_2_8_0() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PoulavBhowmick03
It seems that this comment is still unaddressed
|
@PoulavBhowmick03 |
|
Hi @PoulavBhowmick03 |
|
@ksew1 hello, i was actually going through a surgery, and so i was completely away from my works, give me time till this weekend, it will be ready |
Closes #2710
Introduced changes
Checklist
CHANGELOG.md