Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

PoulavBhowmick03
Copy link

@PoulavBhowmick03 PoulavBhowmick03 commented Jan 30, 2025

Closes #2710

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

Copy link
Member

@ksew1 ksew1 left a 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 {
Copy link
Member

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");

env::var(BACKTRACE_ENV).is_ok_and(|value| value == "1")
}

fn contains_entry_with_value(table: &Table, key: &str, value: &str) -> bool {
Copy link
Member

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)
}

Copy link
Author

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

Copy link
Member

@ksew1 ksew1 Feb 4, 2025

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%

@ddoktorski
Copy link
Contributor

@PoulavBhowmick03

Please fix:

@ddoktorski
Copy link
Contributor

@PoulavBhowmick03 any progress on this?

@PoulavBhowmick03
Copy link
Author

@PoulavBhowmick03 any progress on this?

apologies, was a little acquired, i will fix and modify the changes by tonight or tomorrow at max

@PoulavBhowmick03 PoulavBhowmick03 requested a review from a team as a code owner February 10, 2025 03:57
@PoulavBhowmick03
Copy link
Author

@ddoktorski PTAL


const BACKTRACE_REQUIRED_ENTRIES: [(&str, &str); 2] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const BACKTRACE_REQUIRED_ENTRIES: [(&str, &str); 2] = [
const BACKTRACE_REQUIRED_ENTRIES: [(&str,bool); 2] = [

@@ -30,7 +39,7 @@ pub fn add_backtrace_footer(
return message;
}

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !is_backtrace_enabled {
if !is_backtrace_enabled() {


let manifest = fs::read_to_string(&scarb_metadata.runtime_manifest)?.parse::<DocumentMut>()?;

let profile_cairo = manifest
Copy link
Member

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
        },
    );

"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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info).context(
VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info)?;

"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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info).context(
VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info)?;

@PoulavBhowmick03
Copy link
Author

@ksew1 PTAL

Copy link
Member

@ksew1 ksew1 left a 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

Copy link
Member

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() {

Copy link
Contributor

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

@ddoktorski
Copy link
Contributor

@PoulavBhowmick03
Are you planning to address the last comment and resolve merge conflicts? Once that’s done it should be good to go.

@ksew1
Copy link
Member

ksew1 commented Mar 25, 2025

Hi @PoulavBhowmick03
Please address the last comment and resolve merge conflicts or i will need to close this pr :(

@PoulavBhowmick03
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve validation for Scarb Version and Scarb.toml Configuration for Forge Backtrace
3 participants