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(gateway): make sure we are using the latest block in the stateful validator #401

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

yair-starkware
Copy link
Contributor

@yair-starkware yair-starkware commented Jul 8, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.61%. Comparing base (7f2356e) to head (1efb99d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #401   +/-   ##
=======================================
  Coverage   82.60%   82.61%           
=======================================
  Files          39       39           
  Lines        1788     1789    +1     
  Branches     1788     1789    +1     
=======================================
+ Hits         1477     1478    +1     
  Misses        237      237           
  Partials       74       74           

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

Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 7 files at r1, all commit messages.
Reviewable status: 3 of 7 files reviewed, 1 unresolved discussion (waiting on @dafnamatsry and @yair-starkware)


crates/gateway/src/state_reader.rs line 16 at r1 (raw file):

}

#[automock]

What does it mean?
Is there an alternative to incorporating testing code into production code?

Code quote:

#[automock]

@yair-starkware yair-starkware force-pushed the yair/mock_state_reader_factory branch from 2369072 to 5e4d0ce Compare July 9, 2024 10:55
@yair-starkware
Copy link
Contributor Author

crates/gateway/src/state_reader.rs line 16 at r1 (raw file):

Previously, elintul (Elin) wrote…

What does it mean?
Is there an alternative to incorporating testing code into production code?

It is a tool to create mocks of traits.
Changed the code so it is behind 'test' feature.

Please note that this PR is on top of #369

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 7 files at r1, 2 of 5 files at r3, 3 of 4 files at r4, all commit messages.
Reviewable status: 6 of 7 files reviewed, 3 unresolved discussions (waiting on @elintul and @yair-starkware)


crates/gateway/src/stateful_transaction_validator_test.rs line 81 at r4 (raw file):

    // Using Arc and cloning because mock requires moving the state_reader_factory, but we need it
    // twice.
    let state_reader_factory =

IIUC we need this factory only to create a state_reader to be returned from the mock factory.
Can we just create a TestStateReader directly here? somthing like:

let test_state_reader = Box::new(...);
mock_state_reader_factory
    .expect_get_state_reader_from_latest_block()
    .returning(move || test_state_reader);


crates/gateway/src/stateful_transaction_validator_test.rs line 97 at r4 (raw file):

        assert_eq!(block_number, state_reader_factory.state_reader.block_info.block_number);
        state_reader_factory.get_state_reader(block_number)
    });

Suggestion:

    mock_state_reader_factory.expect_get_state_reader().with(eq(block_number)).returning(move |block_number| {
        state_reader_factory.get_state_reader(block_number)
    });

@yair-starkware yair-starkware force-pushed the yair/mock_state_reader_factory branch 2 times, most recently from 1886f59 to 22c53aa Compare July 9, 2024 13:53
Copy link
Contributor Author

@yair-starkware yair-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: 3 of 7 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry and @elintul)


crates/gateway/src/stateful_transaction_validator_test.rs line 81 at r4 (raw file):

Previously, dafnamatsry wrote…

IIUC we need this factory only to create a state_reader to be returned from the mock factory.
Can we just create a TestStateReader directly here? somthing like:

let test_state_reader = Box::new(...);
mock_state_reader_factory
    .expect_get_state_reader_from_latest_block()
    .returning(move || test_state_reader);

Done.


crates/gateway/src/stateful_transaction_validator_test.rs line 97 at r4 (raw file):

        assert_eq!(block_number, state_reader_factory.state_reader.block_info.block_number);
        state_reader_factory.get_state_reader(block_number)
    });

Done.

Copy link
Collaborator

@dafnamatsry dafnamatsry 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 4 of 4 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @elintul)

Copy link
Collaborator

@elintul elintul 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, 1 unresolved discussion (waiting on @yair-starkware)


crates/gateway/src/state_reader.rs line 16 at r1 (raw file):

Previously, yair-starkware (Yair) wrote…

It is a tool to create mocks of traits.
Changed the code so it is behind 'test' feature.

Please note that this PR is on top of #369

Please add Gilad as a reviewer, would like his opinion here.

Copy link
Contributor Author

@yair-starkware yair-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, 1 unresolved discussion (waiting on @elintul and @giladchase)


crates/gateway/src/state_reader.rs line 16 at r1 (raw file):

Previously, elintul (Elin) wrote…

Please add Gilad as a reviewer, would like his opinion here.

Done.

Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

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

@yair-starkware yair-starkware force-pushed the yair/mock_state_reader_factory branch from 22c53aa to 1efb99d Compare July 23, 2024 12:03
Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@yair-starkware yair-starkware merged commit ef2a585 into main Jul 23, 2024
8 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.

4 participants