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: MOre stateManager test coverage #1299

Merged

Conversation

roninjin10
Copy link
Collaborator

@roninjin10 roninjin10 commented Jul 10, 2024

Description

Concise description of proposed changes

Testing

Explain the quality checks that have been done on the code changes

Additional Information

Your ENS/address:

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive test cases for generateCanonicalGenesis, getContractStorage, getForkBlockTag, and putContractStorage functions.
    • Added stripZeros utility to remove leading zeros from Uint8Array.
  • Improvements

    • Enhanced error handling in getContractStorage by introducing InternalError for specific invalid conditions.
    • Improved test coverage for various state management functions and scenarios, ensuring robust validation of functionality.
  • Refactor

    • Replaced in-file stripZeros function with an imported version from a utility module for cleaner code reuse.

Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tevm-monorepo-tevm 🛑 Canceled (Inspect) Jul 10, 2024 2:12am

Copy link

changeset-bot bot commented Jul 10, 2024

⚠️ No Changeset found

Latest commit: a783e06

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@roninjin10 roninjin10 marked this pull request as ready for review July 10, 2024 01:39
Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Warning

Rate limit exceeded

@roninjin10 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 54 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between e18aa55 and a783e06.

Walkthrough

This update enhances and expands the test coverage for numerous functions within the packages/state module, specifically related to blockchain state management, ensuring better validation and error handling. It introduces new test files for functions like getContractStorage, putContractStorage, generateCanonicalGenesis, among others, and enriches existing test files with additional test cases and improved coverage.

Changes

File Path Change Summary
packages/state/src/actions/commit.js Removed a TODO comment about potentially pruning state roots.
packages/state/src/actions/commit.spec.ts Added new imports, additional test cases for commit, mock functions setups, and tests for handling onCommit callback.
packages/state/src/actions/deepCopy.spec.ts Introduced InternalError import and added a test verifying deepCopy throwing an error on uncommitted state.
packages/state/src/actions/generateCannonicalGenesis.spec.ts New file with test cases for generateCanonicalGenesis, including handling of uncommitted checkpoints.
packages/state/src/actions/getAccount.spec.ts Added various imports, afterEach block for restoring mocks, and extended test cases for fetching and caching accounts, including from remote providers.
packages/state/src/actions/getContractStorage.js Throws InternalError instead of a generic error when the storage key length is not 32 bytes.
packages/state/src/actions/getContractStorage.spec.ts New file with test cases for getContractStorage, including retrieval validation and error handling scenarios.
packages/state/src/actions/getForkBlockTag.spec.ts New file with test cases for getForkBlockTag function.
packages/state/src/actions/putContractStorage.js Removed local stripZeros function declaration and replaced it with an import from ../utils/stripZeros.js.
packages/state/src/actions/putContractStorage.spec.ts New file with test cases for putContractStorage, covering storage behavior and edge cases like zero values and non-existent accounts.
packages/state/src/utils/stripZeros.js New file providing a stripZeros function to remove leading zeros from a Uint8Array.
packages/state/src/utils/stripZeros.spec.ts New file with test cases for stripZeros function, validating its ability to strip leading zeros from various input scenarios.

Possibly related issues

  • Issue 100% Test coverage #1263: The PR addresses improving the coverage for various functions in the @tevm/state package, aligning with the issue's objective to achieve 100% test coverage across core packages.

Poem

In the code's deep, where zeros hide,
Tests now hunt them, far and wide.
Errors caught with boundless glee,
Mock accounts, just wait and see.
Genesis crafted, storage set,
State's now perfect, you can bet.
🐰✨🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @roninjin10 and the rest of your teammates on Graphite Graphite

@roninjin10 roninjin10 mentioned this pull request Jul 10, 2024
80 tasks
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
packages/state/src/utils/stripZeros.js (1)

1-1: Improve error message detail.

Consider providing a more detailed error message to aid debugging.

- throw new InternalError('Unexpected type')
+ throw new InternalError(`Unexpected type: expected Uint8Array but received ${typeof bytes}`)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dac15b5 and e18aa55.

Files ignored due to path filters (6)
  • packages/state/src/actions/__snapshots__/commit.spec.ts.snap is excluded by !**/*.snap
  • packages/state/src/actions/__snapshots__/deepCopy.spec.ts.snap is excluded by !**/*.snap
  • packages/state/src/actions/__snapshots__/generateCannonicalGenesis.spec.ts.snap is excluded by !**/*.snap
  • packages/state/src/actions/__snapshots__/getAccount.spec.ts.snap is excluded by !**/*.snap
  • packages/state/src/actions/__snapshots__/getContractStorage.spec.ts.snap is excluded by !**/*.snap
  • packages/state/src/actions/__snapshots__/putContractStorage.spec.ts.snap is excluded by !**/*.snap
Files selected for processing (12)
  • packages/state/src/actions/commit.js (1 hunks)
  • packages/state/src/actions/commit.spec.ts (1 hunks)
  • packages/state/src/actions/deepCopy.spec.ts (2 hunks)
  • packages/state/src/actions/generateCannonicalGenesis.spec.ts (1 hunks)
  • packages/state/src/actions/getAccount.spec.ts (2 hunks)
  • packages/state/src/actions/getContractStorage.js (2 hunks)
  • packages/state/src/actions/getContractStorage.spec.ts (1 hunks)
  • packages/state/src/actions/getForkBlockTag.spec.ts (1 hunks)
  • packages/state/src/actions/putContractStorage.js (1 hunks)
  • packages/state/src/actions/putContractStorage.spec.ts (1 hunks)
  • packages/state/src/utils/stripZeros.js (1 hunks)
  • packages/state/src/utils/stripZeros.spec.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/state/src/actions/commit.js
  • packages/state/src/actions/putContractStorage.js
Additional context used
Biome
packages/state/src/actions/putContractStorage.spec.ts

[error] 15-15: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)

Additional comments not posted (31)
packages/state/src/utils/stripZeros.js (1)

7-12: LGTM!

The function implementation is correct and efficiently removes leading zeros from a Uint8Array.

packages/state/src/actions/getForkBlockTag.spec.ts (1)

1-42: Comprehensive test cases for getForkBlockTag.

The test cases cover various scenarios and ensure robust functionality of the getForkBlockTag function.

packages/state/src/utils/stripZeros.spec.ts (1)

1-34: Comprehensive test cases for stripZeros.

The test cases cover various scenarios and ensure robust functionality of the stripZeros function.

packages/state/src/actions/generateCannonicalGenesis.spec.ts (1)

1-38: Comprehensive test cases for generateCanonicalGenesis.

The test cases cover various scenarios and ensure robust functionality of the generateCanonicalGenesis function.

packages/state/src/actions/getContractStorage.js (1)

Line range hint 6-21:
LGTM! Verify usage of InternalError.

The addition of InternalError for invalid storage key lengths enhances error handling.

Ensure that InternalError is correctly defined and used across the codebase.

packages/state/src/actions/putContractStorage.spec.ts (6)

33-36: Test case approved.

The test case correctly verifies that the value is added to the cache for the account at the provided key.


38-43: Test case approved.

The test case ensures that leading zeros are stripped from the value before storing it.


45-50: Test case approved.

The test case correctly verifies that an InternalError is thrown when the key is not 32 bytes long.


52-57: Test case approved.

The test case correctly verifies that an InternalError is thrown when the account does not exist.


59-63: Test case approved.

The test case ensures that the value is deleted when it is empty.


65-69: Test case approved.

The test case ensures that the value is deleted when it is filled with zeros.

packages/state/src/actions/getAccount.spec.ts (6)

10-12: Test case approved.

The test case correctly verifies that the account is retrievable from the base state.


57-60: Test case approved.

The test case correctly verifies that the account is retrievable with forking enabled.


62-64: Test case approved.

The test case correctly verifies that an undefined account is returned when no fork transport is provided.


66-68: Test case approved.

The test case correctly verifies that an undefined account is returned when fetching from fork is skipped.


70-78: Test case approved.

The test case correctly verifies that the account is fetched from a remote provider and cached.


80-105: Test case approved.

The test case correctly verifies that an undefined account is cached when fetched from a remote provider.

packages/state/src/actions/getContractStorage.spec.ts (6)

35-37: Test case approved.

The test case correctly verifies that the storage value is retrievable for the provided address and key.


39-42: Test case approved.

The test case correctly verifies that an empty Uint8Array is returned when the storage does not exist.


44-49: Test case approved.

The test case correctly verifies that an error is thrown when the key is not 32 bytes long.


51-55: Test case approved.

The test case correctly verifies that an empty Uint8Array is returned when the account is not a contract.


80-87: Test case approved.

The test case correctly verifies that the storage value is fetched from a remote provider and cached.


89-96: Test case approved.

The test case correctly verifies that an empty Uint8Array is returned when the account does not exist and no fork transport is provided.

packages/state/src/actions/commit.spec.ts (5)

1-7: Imports look good!

The added imports are necessary for the new test cases.


11-32: Test case for clearing storage entries is comprehensive.

The test case covers the necessary scenarios for clearing storage entries and includes appropriate assertions.


50-62: Test case for committing to existing state root is well-structured.

The test case includes all necessary assertions to verify the correct behavior of committing to an existing state root.


64-78: Test case for committing to a new state root is comprehensive.

The test case includes all necessary assertions to verify the correct behavior of committing to a new state root.


80-87: Test case for handling onCommit callback is well-structured.

The test case includes all necessary assertions to verify the correct behavior of the commit function with the onCommit callback.

packages/state/src/actions/deepCopy.spec.ts (3)

11-11: Import of InternalError looks good!

The added import is necessary for the new test case.


Line range hint 1-45:
Test case for creating a copy of the state is comprehensive.

The test case covers the necessary scenarios for creating a copy of the state and includes appropriate assertions.


46-67: Test case for throwing error on uncommitted state is well-structured.

The test case includes all necessary assertions to verify that the deepCopy function throws an InternalError when called on an uncommitted state.

@roninjin10 roninjin10 force-pushed the 07-09-_white_check_mark_test_more_statemanager_test_coverage branch 2 times, most recently from 882aa2e to ef08bab Compare July 10, 2024 01:48
@roninjin10 roninjin10 force-pushed the 07-09-_white_check_mark_test_more_statemanager_test_coverage branch from c23dc81 to a783e06 Compare July 10, 2024 01:59
@roninjin10 roninjin10 merged commit 738cb23 into main Jul 10, 2024
9 of 10 checks passed
@roninjin10 roninjin10 deleted the 07-09-_white_check_mark_test_more_statemanager_test_coverage branch July 10, 2024 04:45
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.

1 participant