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

feat(state network): improve StateContentKey tests #1138

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

morph-dev
Copy link
Collaborator

What was wrong?

The StateContentKey tests weren't using test vectors from portal-spec-tests and they weren't testing serialization.

How was it fixed?

I rewrote the tests and added new one.

To-Do

#[case::account_trie_node_key("account_trie_node_key.yaml")]
#[case::contract_storage_trie_node_key("contract_storage_trie_node_key.yaml")]
#[case::contract_bytecode_key("contract_bytecode_key.yaml")]
fn encode_decode(#[case] filename: &str) -> Result<()> {
Copy link
Member

@ogenev ogenev Feb 5, 2024

Choose a reason for hiding this comment

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

I don't think that we need to return Result here and in other tests., because we are not doing anything with the error. In tests we usually want to panic or return ().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I personally like to return Result in tests because I can use ? operator instead of .unwrap(), which in my mind makes code cleaner (returning Err makes the code fail).

I also don't think it's something that is generally considered bad practice. See:
Rust Book: https://doc.rust-lang.org/book/ch11-01-writing-tests.html#using-resultt-e-in-tests
Rust by Example: https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html#tests-and-

Copy link
Member

@ogenev ogenev left a comment

Choose a reason for hiding this comment

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

@ogenev ogenev merged commit 88a2c47 into ethereum:master Feb 5, 2024
8 checks passed
@morph-dev morph-dev deleted the state_content_key_tests branch February 5, 2024 08:30
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.

2 participants