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): inner revert in cairo 1 contract #2889

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

AvivYossef-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

AvivYossef-starkware commented Dec 23, 2024

@AvivYossef-starkware AvivYossef-starkware marked this pull request as ready for review December 23, 2024 10:10
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/test_cairo_panic branch 3 times, most recently from 6bdbf6b to 2aa93aa Compare December 23, 2024 11:14
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

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

It won't pass the CI until #2895 will merge

Reviewable status: 0 of 5 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)

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.

Reviewed 1 of 5 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware and @ilyalesokhin-starkware)


crates/blockifier/feature_contracts/cairo1/test_contract.cairo line 669 at r2 (raw file):

                else {
                    assert(inner_error == 'execute_and_revert', 'Wrong_error');
                }

consider adding this for clarity. non-blocking

Suggestion:

                else {
                    assert(entry_point_selector == selector!("middle_revert_contract"));
                    assert(inner_error == 'execute_and_revert', 'Wrong_error');
                }

crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 87 at r2 (raw file):

/// 2. Contract B error as expected.
/// 3. Tracked resources are correctly identified as SierraGas in all calls.
#[rstest]

if you use rstest you should probably use the case attributes

Suggestion:

#[rstest]
#[cfg_attr(feature = "cairo_native", case::native(RunnableCairo1::Native))]
#[case::vm(RunnableCairo1::Casm)]
/// This test verifies the behavior of a contract call sequence with nested calls and state
/// assertions.
///
/// - Contract A calls Contract B and asserts that the state remains unchanged.
/// - Contract B calls Contract C and panics.
/// - Contract C modifies the state but does not panic.
///
/// The test ensures that:
/// 1. Contract A's state remains unaffected despite the modifications in Contract C.
/// 2. Contract B error as expected.
/// 3. Tracked resources are correctly identified as SierraGas in all calls.

crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 88 at r2 (raw file):

/// 3. Tracked resources are correctly identified as SierraGas in all calls.
#[rstest]
fn test_call_contract_and_than_revert(runnable_version: RunnableCairo1) {

if you use rstest you should probably use the case attributes

Suggestion:

#[rstest]
#[cfg_attr(feature = "cairo_native", case::native(RunnableCairo1::Native))]
#[case::vm(RunnableCairo1::Casm)]
/// This test verifies the behavior of a contract call sequence with nested calls and state
/// assertions.
///
/// - Contract A calls Contract B and asserts that the state remains unchanged.
/// - Contract B calls Contract C and panics.
/// - Contract C modifies the state but does not panic.
///
/// The test ensures that:
/// 1. Contract A's state remains unaffected despite the modifications in Contract C.
/// 2. Contract B error as expected.
/// 3. Tracked resources are correctly identified as SierraGas in all calls.
fn test_call_contract_and_than_revert(#[case] runnable_version: RunnableCairo1) {

crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 144 at r2 (raw file):

        assert_eq!(call.tracked_resource, TrackedResource::SierraGas);
    }
}

how about testing also that state changes in A are not reverted?
maybe add some dummy storage-write in A's context, and assert it's still included in the diff?

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware 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: all files reviewed, 4 unresolved discussions (waiting on @AvivYossef-starkware and @ilyalesokhin-starkware)


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 134 at r2 (raw file):

    assert!(inner_call.execution.failed);
    assert!(inner_call.execution.events.is_empty());
    assert!(inner_call.execution.l2_to_l1_messages.is_empty());

Check C as well - it should not have events or messages on it, even though it didn't fail

Code quote:

    assert!(inner_call.execution.events.is_empty());
    assert!(inner_call.execution.l2_to_l1_messages.is_empty());

@AvivYossef-starkware AvivYossef-starkware changed the base branch from main to aviv/test_storage_changes_after_inner_revert December 24, 2024 09:04
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-starkware 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: 1 of 5 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware, @ilyalesokhin-starkware, and @Yoni-Starkware)


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 87 at r2 (raw file):

Previously, dorimedini-starkware wrote…

if you use rstest you should probably use the case attributes

Done.


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 88 at r2 (raw file):

Previously, dorimedini-starkware wrote…

if you use rstest you should probably use the case attributes

Done.


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 134 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Check C as well - it should not have events or messages on it, even though it didn't fail

Done.


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 144 at r2 (raw file):

Previously, dorimedini-starkware wrote…

how about testing also that state changes in A are not reverted?
maybe add some dummy storage-write in A's context, and assert it's still included in the diff?

Sounds good, I opened separate PR for it

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 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @AvivYossef-starkware, @ilyalesokhin-starkware, and @Yoni-Starkware)


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 145 at r3 (raw file):

    };
    assert!(!inner_inner_call_c.execution.failed);
    

non-blocking but you seem to have extra whitespace here - please check your local formatter (if you merge this, this will appear as a diff in someone else's PR later)

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware 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 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware and @ilyalesokhin-starkware)

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/test_storage_changes_after_inner_revert branch from 29e52d0 to 4c44815 Compare December 24, 2024 10:23
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-starkware 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: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 145 at r3 (raw file):

Previously, dorimedini-starkware wrote…

non-blocking but you seem to have extra whitespace here - please check your local formatter (if you merge this, this will appear as a diff in someone else's PR later)

Is it ok now?
The CI failed on the previous

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/test_storage_changes_after_inner_revert branch from 4c44815 to 3a6c12f Compare December 24, 2024 10:47
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/test_storage_changes_after_inner_revert branch from 3a6c12f to 7237414 Compare December 24, 2024 10:49
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.

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


a discussion (no related file):
blocking until bottom PR is merged, so I'm sure it's over main-v0.13.4

@AvivYossef-starkware AvivYossef-starkware changed the base branch from aviv/test_storage_changes_after_inner_revert to aviv/test_storage_changes_after_inner_revert_v2 December 24, 2024 11:44
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-starkware 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: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


a discussion (no related file):

Previously, dorimedini-starkware wrote…

blocking until bottom PR is merged, so I'm sure it's over main-v0.13.4

Done.

@AvivYossef-starkware AvivYossef-starkware changed the base branch from aviv/test_storage_changes_after_inner_revert_v2 to graphite-base/2889 December 24, 2024 12:21
@AvivYossef-starkware AvivYossef-starkware changed the base branch from graphite-base/2889 to main-v0.13.4 December 24, 2024 12:21
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.

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)

@AvivYossef-starkware AvivYossef-starkware merged commit 7002777 into main-v0.13.4 Dec 24, 2024
12 checks passed
Copy link
Contributor Author

Merge activity

  • Dec 24, 7:56 AM EST: A user merged this pull request with Graphite.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants