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

test(blockifier): add from file trait #1720

Merged
merged 1 commit into from
Nov 3, 2024
Merged

Conversation

noaov1
Copy link
Collaborator

@noaov1 noaov1 commented Oct 31, 2024

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 68.99%. Comparing base (e3165c4) to head (037e230).
Report is 145 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/test_utils/struct_impls.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1720       +/-   ##
===========================================
+ Coverage   40.10%   68.99%   +28.89%     
===========================================
  Files          26      100       +74     
  Lines        1895    13461    +11566     
  Branches     1895    13461    +11566     
===========================================
+ Hits          760     9288     +8528     
- Misses       1100     3771     +2671     
- Partials       35      402      +367     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Nov 2, 2024

Artifacts upload triggered. View details here

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @noaov1)


crates/blockifier/src/test_utils/struct_impls.rs line 216 at r1 (raw file):

pub trait LoadFile {
    fn from_file(contract_path: &str) -> Self;

I see that many paths are saved as &str with this infra, including get_raw_contract_class but not as PathBuf (or something).
I see not many functions are using this infra. We can still fix that before the type keeps spreading!

(probably an issue for another PR).

Code quote:

    fn from_file(contract_path: &str) -> Self;

crates/blockifier/src/test_utils/struct_impls.rs line 217 at r1 (raw file):

pub trait LoadFile {
    fn from_file(contract_path: &str) -> Self;
}

Either document or rename. With this name for the trait and the function, this trait can be used more generally than for contract classes.

Third option: this seems very useful - can this be shared more generally?

Maybe all of these comments should be non-blocking.

Code quote:

pub trait LoadFile {
    fn from_file(contract_path: &str) -> Self;
}

crates/blockifier/src/test_utils/struct_impls.rs line 231 at r1 (raw file):

        serde_json::from_str(&raw_contract_class).unwrap()
    }
}

Code dedup.

Suggestion:

pub trait LoadFile: serde::de::DeserializeOwned {
    fn from_file(contract_path: &str) -> Self {
        let raw_contract_class = get_raw_contract_class(contract_path);
        serde_json::from_str(&raw_contract_class).unwrap()
    }
}

impl LoadFile for DeprecatedContractClass {}

impl LoadFile for CasmContractClass {}

Copy link
Collaborator Author

@noaov1 noaov1 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware and @dorimedini-starkware)


crates/blockifier/src/test_utils/struct_impls.rs line 216 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

I see that many paths are saved as &str with this infra, including get_raw_contract_class but not as PathBuf (or something).
I see not many functions are using this infra. We can still fix that before the type keeps spreading!

(probably an issue for another PR).

Another PR. I added a TODO.


crates/blockifier/src/test_utils/struct_impls.rs line 217 at r1 (raw file):

With this name for the trait and the function, this trait can be used more generally than for contract classes.

Is this bad?
With the default implantation of the trait it must be contract specific. I changed the name of the trait.


crates/blockifier/src/test_utils/struct_impls.rs line 231 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Code dedup.

Like. Done.

Copy link

github-actions bot commented Nov 3, 2024

Artifacts upload triggered. View details here

@ArniStarkware
Copy link
Contributor

crates/blockifier/src/test_utils/struct_impls.rs line 232 at r2 (raw file):

        Self::try_from_json_string(&raw_contract_class).unwrap()
    }
}

delete?

Code quote:

impl ContractClassV1 {
    pub fn from_file(contract_path: &str) -> Self {
        let raw_contract_class = get_raw_contract_class(contract_path);
        Self::try_from_json_string(&raw_contract_class).unwrap()
    }
}

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @noaov1)

Copy link
Collaborator Author

@noaov1 noaov1 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @dorimedini-starkware)


crates/blockifier/src/test_utils/struct_impls.rs line 232 at r2 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

delete?

I deleted the CairoV0 one by accident. It is still used. Will be deleted in this PR.

Copy link

github-actions bot commented Nov 3, 2024

Artifacts upload triggered. View details here

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

@noaov1 noaov1 merged commit 9b7cf84 into main Nov 3, 2024
12 checks passed
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.

5 participants