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

Improve event testing #240

Merged
merged 30 commits into from May 15, 2024
Merged

Improve event testing #240

merged 30 commits into from May 15, 2024

Conversation

sideninja
Copy link
Member

@sideninja sideninja commented May 10, 2024

Improve event testing and fix any found issues.

Summary by CodeRabbit

  • New Features

    • Enhanced log filtering capabilities with block height criteria.
    • Improved streaming of logs using filters in a Web3 environment.
  • Bug Fixes

    • Updated error handling in log retrieval functions for better reliability.
  • Tests

    • Added comprehensive tests for streaming logs using filters.
    • Removed unused import statements to clean up test files.

Copy link

coderabbitai bot commented May 10, 2024

Walkthrough

The recent updates focus on enhancing log filtering and retrieval functionalities within the API, emphasizing block height criteria handling and refined error management. Tests have also been improved to align with these changes, introducing new helper functions and imports to support comprehensive log streaming scenarios.

Changes

File Change Summary
api/stream.go Reordered imports, modified Logs for block height criteria and new filter creation.
tests/web3js/eth_batch_retrieval_test.js Removed unused helpers import statement.
tests/web3js/eth_streaming_filters_test.js Added imports and functions for testing log streaming with filters.
api/api.go Added import for "math/big", enhanced GetLogs for block ID handling, defaults, and error management.

🐇
In the code where data flows,
New filters guide where logs shall go,
With blocks and heights, they now align,
Errors handled, flows refined.
Tests ensure all runs just right,
Logs stream smoothly, day and night.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

@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 553fca6 and 4850c98.
Files selected for processing (4)
  • services/logs/filter.go (2 hunks)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
  • tests/web3js/eth_streaming_test.js (2 hunks)
Files skipped from review due to trivial changes (1)
  • services/logs/filter.go
Additional comments not posted (4)
tests/e2e_web3js_test.go (1)

40-42: New test case added for streaming entities with filters.

This addition aligns with the PR's objective to enhance event testing capabilities. Ensure that the referenced test script eth_streaming_filters_test is correctly implemented and handles all necessary scenarios.

tests/web3js/eth_streaming_test.js (1)

61-61: Variable renaming enhances clarity.

Renaming doneLogs to doneAddressLogs improves the readability and specificity of the variable, making it clear that it pertains to logs from specific addresses.

tests/web3js/eth_streaming_filters_test.js (2)

17-57: New function assertFilterLogs added to test log filtering.

This function is crucial for verifying the correctness of logs based on specified filters. It handles the subscription to log events, collects the logs, and asserts their correctness against expected values. Ensure that the error handling within the promise is robust and that the function is used correctly in the test cases.


59-107: Comprehensive test case added for log streaming with filters.

This test case effectively utilizes the assertFilterLogs function to test various filtering scenarios. It's important to ensure that all edge cases and potential error scenarios are covered in the tests to maintain high reliability.

Copy link

@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

Out of diff range and nitpick comments (1)
api/stream.go (1)

16-20: Consider organizing imports to improve readability.

Imports could be grouped more logically, separating standard library, third-party, and internal project imports.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4850c98 and 8ef5567.
Files selected for processing (4)
  • api/models.go (2 hunks)
  • api/stream.go (5 hunks)
  • services/logs/filter.go (5 hunks)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • api/models.go
Files skipped from review as they are similar to previous changes (2)
  • services/logs/filter.go
  • tests/web3js/eth_streaming_filters_test.js
Additional comments not posted (3)
api/stream.go (3)

Line range hint 29-43: Constructor function NewStreamAPI is well-implemented and initializes all components correctly.


Line range hint 58-58: Address TODO regarding missing data in block headers.


Line range hint 162-194: Optimize block fetching to avoid redundant operations.

-			// todo change this to height filter so we don't have to get the same block twice, once for height and then for id
+			// Refactor to use a single block fetch operation based on height and id

Copy link

@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 8ef5567 and 984cf65.
Files selected for processing (1)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
Files not reviewed due to errors (1)
  • tests/web3js/eth_streaming_filters_test.js (no review received)

api/stream.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

@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 984cf65 and 449f84a.
Files selected for processing (5)
  • api/api.go (2 hunks)
  • models/block.go (1 hunks)
  • services/logs/filter.go (5 hunks)
  • storage/pebble/receipts.go (1 hunks)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • storage/pebble/receipts.go
Additional comments not posted (7)
models/block.go (2)

13-17: Constants for special block numbers are correctly defined and follow common practices.


Line range hint 19-36: The decodeBlock function is well-implemented with proper error handling and data transformation.

services/logs/filter.go (2)

17-20: Constants maxTopics and maxAddresses are well-defined and serve to limit resource usage during log filtering.


35-47: The NewFilterCriteria function correctly enforces limits on topics and addresses and handles errors appropriately.

tests/web3js/eth_streaming_filters_test.js (2)

9-64: The assertFilterLogs function is well-implemented, correctly handling asynchronous log collection and assertions.


66-182: The test cases are comprehensive and effectively test various filtering scenarios in log streaming.

api/api.go (1)

444-482: The GetLogs function is correctly updated to handle filters based on specific block IDs and ranges, integrating well with the filtering logic.

Copy link

@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 449f84a and bf68300.
Files selected for processing (2)
  • api/stream.go (4 hunks)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
Files not reviewed due to errors (1)
  • tests/web3js/eth_streaming_filters_test.js (no review received)
Files skipped from review as they are similar to previous changes (1)
  • api/stream.go

Copy link

@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 bf68300 and c71e144.
Files selected for processing (3)
  • api/stream.go (6 hunks)
  • tests/web3js/eth_batch_retrieval_test.js (2 hunks)
  • tests/web3js/eth_streaming_filters_test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/web3js/eth_batch_retrieval_test.js
Files skipped from review as they are similar to previous changes (2)
  • api/stream.go
  • tests/web3js/eth_streaming_filters_test.js

Copy link

@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 c71e144 and 27b99d3.
Files selected for processing (1)
  • api/api.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • api/api.go

Copy link

@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: 22

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 27b99d3 and 8473656.
Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum
Files selected for processing (5)
  • models/mocks/Engine.go (5 hunks)
  • storage/mocks/AccountIndexer.go (5 hunks)
  • storage/mocks/BlockIndexer.go (10 hunks)
  • storage/mocks/ReceiptIndexer.go (6 hunks)
  • storage/mocks/TransactionIndexer.go (4 hunks)

Comment on lines +21 to +23
if len(ret) == 0 {
panic("no return value specified for Get")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for Get")
- }
+ if len(ret) == 0 {
+     return models.Transaction{}, errors.New("no return value specified for Get")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for Get")
}
if len(ret) == 0 {
return models.Transaction{}, errors.New("no return value specified for Get")
}

Comment on lines +51 to +53
if len(ret) == 0 {
panic("no return value specified for Store")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for Store")
- }
+ if len(ret) == 0 {
+     return errors.New("no return value specified for Store")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for Store")
}
if len(ret) == 0 {
return errors.New("no return value specified for Store")
}

Comment on lines +65 to 71
// NewTransactionIndexer creates a new instance of TransactionIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewTransactionIndexer(t interface {
mock.TestingT
Cleanup(func())
}

// NewTransactionIndexer creates a new instance of TransactionIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewTransactionIndexer(t mockConstructorTestingTNewTransactionIndexer) *TransactionIndexer {
}) *TransactionIndexer {
mock := &TransactionIndexer{}
Copy link

Choose a reason for hiding this comment

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

Ensure proper documentation for the NewTransactionIndexer function.

The documentation for the NewTransactionIndexer function is clear, but it can be improved by specifying the purpose of the function and the expected behavior.

- // NewTransactionIndexer creates a new instance of TransactionIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+ // NewTransactionIndexer creates a new instance of TransactionIndexer. It registers a testing interface on the mock and a cleanup function to assert the mock's expectations.
+ // The first argument is typically a *testing.T value, which is used to manage the lifecycle of the mock.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// NewTransactionIndexer creates a new instance of TransactionIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewTransactionIndexer(t interface {
mock.TestingT
Cleanup(func())
}
// NewTransactionIndexer creates a new instance of TransactionIndexer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewTransactionIndexer(t mockConstructorTestingTNewTransactionIndexer) *TransactionIndexer {
}) *TransactionIndexer {
mock := &TransactionIndexer{}
// NewTransactionIndexer creates a new instance of TransactionIndexer. It registers a testing interface on the mock and a cleanup function to assert the mock's expectations.
// The first argument is typically a *testing.T value, which is used to manage the lifecycle of the mock.
func NewTransactionIndexer(t interface {
mock.TestingT
Cleanup(func())
}) *TransactionIndexer {
mock := &TransactionIndexer{}

Comment on lines +20 to +22
if len(ret) == 0 {
panic("no return value specified for Done")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for Done")
- }
+ if len(ret) == 0 {
+     return make(<-chan struct{})
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for Done")
}
if len(ret) == 0 {
return make(<-chan struct{})
}

Comment on lines +40 to +42
if len(ret) == 0 {
panic("no return value specified for Ready")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for Ready")
- }
+ if len(ret) == 0 {
+     return make(<-chan struct{})
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for Ready")
}
if len(ret) == 0 {
return make(<-chan struct{})
}

Comment on lines +51 to +53
if len(ret) == 0 {
panic("no return value specified for GetByID")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for GetByID")
- }
+ if len(ret) == 0 {
+     return nil, errors.New("no return value specified for GetByID")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for GetByID")
}
if len(ret) == 0 {
return nil, errors.New("no return value specified for GetByID")
}

Comment on lines +81 to +83
if len(ret) == 0 {
panic("no return value specified for GetCadenceHeight")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for GetCadenceHeight")
- }
+ if len(ret) == 0 {
+     return 0, errors.New("no return value specified for GetCadenceHeight")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for GetCadenceHeight")
}
if len(ret) == 0 {
return 0, errors.New("no return value specified for GetCadenceHeight")
}

Comment on lines +109 to +111
if len(ret) == 0 {
panic("no return value specified for GetHeightByID")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for GetHeightByID")
- }
+ if len(ret) == 0 {
+     return 0, errors.New("no return value specified for GetHeightByID")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for GetHeightByID")
}
if len(ret) == 0 {
return 0, errors.New("no return value specified for GetHeightByID")
}

Comment on lines +137 to +139
if len(ret) == 0 {
panic("no return value specified for LatestCadenceHeight")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for LatestCadenceHeight")
- }
+ if len(ret) == 0 {
+     return 0, errors.New("no return value specified for LatestCadenceHeight")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for LatestCadenceHeight")
}
if len(ret) == 0 {
return 0, errors.New("no return value specified for LatestCadenceHeight")
}

Comment on lines +165 to +167
if len(ret) == 0 {
panic("no return value specified for LatestEVMHeight")
}
Copy link

Choose a reason for hiding this comment

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

Avoid using panic in autogenerated mocks.

Using panic in autogenerated mocks can lead to unexpected crashes during testing. Instead, consider returning default values or errors.

- if len(ret) == 0 {
-     panic("no return value specified for LatestEVMHeight")
- }
+ if len(ret) == 0 {
+     return 0, errors.New("no return value specified for LatestEVMHeight")
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if len(ret) == 0 {
panic("no return value specified for LatestEVMHeight")
}
if len(ret) == 0 {
return 0, errors.New("no return value specified for LatestEVMHeight")
}

Copy link

@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 8473656 and b18e802.
Files selected for processing (1)
  • api/api.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • api/api.go

@sideninja sideninja merged commit 313d201 into main May 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants