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: Add 100% test coverage to tevm/utils #1303

Conversation

roninjin10
Copy link
Collaborator

@roninjin10 roninjin10 commented Jul 11, 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

  • Bug Fixes

    • Improved error handling in the createMemoryDb function for better user experience.
  • Tests

    • Introduced comprehensive test suites for:
      • Bloom class functionalities.
      • createMemoryDb function, including various operations and error handling.
      • invariant function behavior under different conditions.
      • Prefunded accounts functionality and associated constants.
  • Refactor

    • Updated invariant function signature for clearer error parameter specification.

Copy link

vercel bot commented Jul 11, 2024

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

Name Status Preview Comments Updated (UTC)
tevm-monorepo-tevm ❌ Failed (Inspect) Jul 11, 2024 7:29pm

Copy link

changeset-bot bot commented Jul 11, 2024

🦋 Changeset detected

Latest commit: 086c017

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@tevm/utils Patch
@tevm/ethers Patch
@tevm/viem Patch
@tevm/actions Patch
@tevm/address Patch
@tevm/base-client Patch
@tevm/block Patch
@tevm/blockchain Patch
@tevm/client-types Patch
@tevm/common Patch
@tevm/contract Patch
@tevm/decorators Patch
@tevm/evm Patch
@tevm/http-client Patch
@tevm/memory-client Patch
@tevm/precompiles Patch
@tevm/predeploys Patch
@tevm/procedures Patch
@tevm/receipt-manager Patch
@tevm/server Patch
@tevm/state Patch
@tevm/tx Patch
@tevm/txpool Patch
@tevm/vm Patch
tevm Patch
@tevm/experimental-solc Patch
@tevm/test-utils Patch
@tevm/sync-storage-persister Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

The changeset focuses on achieving 100% test coverage in the tevm/utils package by introducing new test files and fixtures while also refining some existing functions. Key updates include comprehensive test cases for multiple utility functions, improved error handling, and minor bug fixes. This ensures robust and reliable code by covering all functionalities with adequate tests.

Changes

File(s) Change Summary
.changeset/forty-rice-invent.md Added a changeset summary outlining the updates and their purpose.
packages/utils/src/Bloom.spec.ts Introduced tests for the Bloom class, covering initialization, element addition, element checks, multi-checks, and error handling.
packages/utils/src/createMemoryDb.js Modified error handling in createMemoryDb to return a rejected promise instead of throwing an UnreachableCodeError.
packages/utils/src/createMemoryDb.spec.ts Added tests for createMemoryDb, covering get, put, delete operations, key encoding, shallow copies, batch operations, and the open method.
packages/utils/src/invariant.spec.ts Introduced a test suite for the invariant function, testing various conditions and custom error handling.
packages/utils/src/invariant.ts Updated the invariant function's signature to explicitly specify the error parameter type as Error.
packages/utils/src/prefundedAccounts.spec.ts Added tests for prefunded accounts, including constants for accounts and keys.

Possibly related issues

Poem

In the realm of code so vast and bright,
Tests were added to ensure all's right.
A bloom of checks for filters' might,
And memory’s errors taken in new light.
With invariant truths now deftly tight,
Prefunded accounts in tests take flight.
The utils stand robust, a coder’s delight!

   (\(\
  ( -.-)
  o_(")(")

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

roninjin10 commented Jul 11, 2024

@roninjin10 roninjin10 marked this pull request as ready for review July 11, 2024 19:20
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f4a1473 and 086c017.

Files ignored due to path filters (1)
  • packages/utils/src/__snapshots__/createMemoryDb.spec.ts.snap is excluded by !**/*.snap
Files selected for processing (7)
  • .changeset/forty-rice-invent.md (1 hunks)
  • packages/utils/src/Bloom.spec.ts (1 hunks)
  • packages/utils/src/createMemoryDb.js (1 hunks)
  • packages/utils/src/createMemoryDb.spec.ts (1 hunks)
  • packages/utils/src/invariant.spec.ts (1 hunks)
  • packages/utils/src/invariant.ts (1 hunks)
  • packages/utils/src/prefundedAccounts.spec.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • .changeset/forty-rice-invent.md
Additional comments not posted (16)
packages/utils/src/invariant.ts (1)

3-3: Enhance type safety for the error parameter.

The change to explicitly specify the type of the error parameter as Error improves type safety and clarity.

packages/utils/src/prefundedAccounts.spec.ts (1)

1-21: Comprehensive tests for prefunded accounts.

The tests thoroughly validate the constants for prefunded accounts and their keys, ensuring consistency and correctness.

packages/utils/src/createMemoryDb.js (1)

49-49: Improved error handling in the batch method.

The change to return a rejected promise with the error object instead of throwing an UnreachableCodeError aligns with promise-based error handling and improves consistency.

Ensure that all function calls to createMemoryDb are updated accordingly.

Verification successful

All function calls to createMemoryDb are updated accordingly.

The search did not reveal any external calls to createMemoryDb, implying that no further updates are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `createMemoryDb` are updated accordingly.

# Test: Search for the function usage. Expect: Only occurrences of the updated error handling.
rg --type js -A 5 $'createMemoryDb'

Length of output: 1931


Script:

#!/bin/bash
# Description: Search for all function calls to `createMemoryDb` across the entire codebase.

# Test: Search for the function usage in all files. Expect: Occurrences of the updated error handling.
rg 'createMemoryDb' -t js

Length of output: 941

packages/utils/src/invariant.spec.ts (1)

1-33: Comprehensive tests for the invariant function.

The tests thoroughly cover various scenarios and error handling for the invariant function, ensuring it behaves correctly with different inputs.

packages/utils/src/createMemoryDb.spec.ts (6)

14-23: LGTM!

The test case for basic CRUD operations is well-written and comprehensive.


25-35: LGTM!

The test case for encoding Uint8Array keys is well-written and comprehensive.


37-49: LGTM!

The test case for creating a shallow copy of the database is well-written and comprehensive.


51-59: LGTM!

The test case for handling batch operations is well-written and comprehensive.


61-66: LGTM!

The test case for throwing an UnreachableCodeError for unknown batch operation types is well-written and comprehensive.


68-70: LGTM!

The test case for resolving the open method is well-written and comprehensive.

packages/utils/src/Bloom.spec.ts (6)

7-10: LGTM!

The test case for initializing with zeros if no bitvector is provided is well-written and comprehensive.


12-15: LGTM!

The test case for throwing an error if bitvector length is not 256 is well-written and comprehensive.


17-31: LGTM!

The test case for adding an element to the bloom filter is well-written and comprehensive.


34-41: LGTM!

The test case for checking if an element is in the bloom filter is well-written and comprehensive.


43-52: LGTM!

The test case for checking if multiple topics are in the bloom filter is well-written and comprehensive.


54-61: LGTM!

The test case for throwing a DefensiveNullCheckError if an item is undefined in the or method is well-written and comprehensive.

@roninjin10 roninjin10 merged commit 277ed48 into main Jul 12, 2024
9 of 10 checks passed
@roninjin10 roninjin10 deleted the 07-11-_white_check_mark_test_add_100_test_coverage_to_tevm_utils branch July 12, 2024 00:02
roninjin10 added a commit that referenced this pull request Jul 12, 2024
## Description

_Concise description of proposed changes_

## Testing

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

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling in the `createMemoryDb` function for better
user experience.

- **Tests**
  - Introduced comprehensive test suites for:
    - `Bloom` class functionalities.
- `createMemoryDb` function, including various operations and error
handling.
    - `invariant` function behavior under different conditions.
    - Prefunded accounts functionality and associated constants.

- **Refactor**
- Updated `invariant` function signature for clearer error parameter
specification.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: William Cory <[email protected]>
roninjin10 pushed a commit that referenced this pull request Jul 12, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`main` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `main`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @tevm/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- [#1306](#1306)
[`e19fc84`](e19fc84)
Thanks [@roninjin10](https://github.com/roninjin10)! - - Increased unit
test coverage of tevm/actions to 87%
- fixed bug where we weren't properly returning tracing and access list
information any errors happen during evm execution. Returning this
information helps make debugging easier for users of tevm
- Fixed bug in callHandler where some validation errors were being
swallowed
- fixed bug in setAccount and getAccount where some validation errors
were being swallowed
- fixed bug with evm not reforking state manager in situation where
forkUrl is set and blockTag for a call is before
- fixed bug with vm blockchainManager not being updated where forkUrl is
set and blockTag for a call is before. This could cause state to leak
from this call to the cannonical blockchain
- fixed bug with a bad blockTag causing an unexpected `InternalError`
rather than `ForkError` to be thrown
- Fixed issue with stateOverrides not respecting the `code` property
- fixed issue where block.cliqueSigner() on forked blocks not properly
throwing an error for not being a POA network
- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

- [#1303](#1303)
[`277ed48`](277ed48)
Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed some very
minor bugs in tevm/utils based on adding 100% test coverage

- [#1306](#1306)
[`e19fc84`](e19fc84)
Thanks [@roninjin10](https://github.com/roninjin10)! - - Increased unit
test coverage of tevm/actions to 87%
- fixed bug where we weren't properly returning tracing and access list
information any errors happen during evm execution. Returning this
information helps make debugging easier for users of tevm
- Fixed bug in callHandler where some validation errors were being
swallowed
- fixed bug in setAccount and getAccount where some validation errors
were being swallowed
- fixed bug with evm not reforking state manager in situation where
forkUrl is set and blockTag for a call is before
- fixed bug with vm blockchainManager not being updated where forkUrl is
set and blockTag for a call is before. This could cause state to leak
from this call to the cannonical blockchain
- fixed bug with a bad blockTag causing an unexpected `InternalError`
rather than `ForkError` to be thrown
- Fixed issue with stateOverrides not respecting the `code` property
- fixed issue where block.cliqueSigner() on forked blocks not properly
throwing an error for not being a POA network

## @tevm/[email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## @tevm/[email protected]

### Patch Changes

-   Updated dependencies \[]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]

## [email protected]

### Patch Changes

- Updated dependencies
\[[`277ed48`](277ed48),
[`e19fc84`](e19fc84)]:
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]
    -   @tevm/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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