-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
WalkthroughThe 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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
todoneAddressLogs
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 functionassertFilterLogs
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.
There was a problem hiding this 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
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 functionNewStreamAPI
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
There was a problem hiding this 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
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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
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
: ThedecodeBlock
function is well-implemented with proper error handling and data transformation.services/logs/filter.go (2)
17-20
: ConstantsmaxTopics
andmaxAddresses
are well-defined and serve to limit resource usage during log filtering.
35-47
: TheNewFilterCriteria
function correctly enforces limits on topics and addresses and handles errors appropriately.tests/web3js/eth_streaming_filters_test.js (2)
9-64
: TheassertFilterLogs
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
: TheGetLogs
function is correctly updated to handle filters based on specific block IDs and ranges, integrating well with the filtering logic.
There was a problem hiding this 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
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
There was a problem hiding this 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
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
There was a problem hiding this 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
There was a problem hiding this 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
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)
if len(ret) == 0 { | ||
panic("no return value specified for Get") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for Store") | ||
} |
There was a problem hiding this comment.
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.
if len(ret) == 0 { | |
panic("no return value specified for Store") | |
} | |
if len(ret) == 0 { | |
return errors.New("no return value specified for Store") | |
} |
// 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{} |
There was a problem hiding this comment.
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.
// 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{} |
if len(ret) == 0 { | ||
panic("no return value specified for Done") | ||
} |
There was a problem hiding this comment.
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.
if len(ret) == 0 { | |
panic("no return value specified for Done") | |
} | |
if len(ret) == 0 { | |
return make(<-chan struct{}) | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for Ready") | ||
} |
There was a problem hiding this comment.
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.
if len(ret) == 0 { | |
panic("no return value specified for Ready") | |
} | |
if len(ret) == 0 { | |
return make(<-chan struct{}) | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for GetByID") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for GetCadenceHeight") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for GetHeightByID") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for LatestCadenceHeight") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
if len(ret) == 0 { | ||
panic("no return value specified for LatestEVMHeight") | ||
} |
There was a problem hiding this comment.
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.
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") | |
} |
There was a problem hiding this 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
Improve event testing and fix any found issues.
Summary by CodeRabbit
New Features
Bug Fixes
Tests