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(testing): Introduce node-api E2E testing #1820

Merged
merged 59 commits into from
Aug 20, 2024
Merged

feat(testing): Introduce node-api E2E testing #1820

merged 59 commits into from
Aug 20, 2024

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Jul 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new API endpoint for node interactions with enhanced port management.
    • Added new command-line options for improved configurability of the beacon node.
    • Implemented a client for interacting with the BeaconKitNode.
    • Created placeholder API functions to maintain compatibility during ongoing development.
    • Expanded the test suite for end-to-end validation of the Beacon API.
    • Defined constants for client configurations and deposit settings in the testing environment.
    • Streamlined the unit fuzz testing process for focused testing.
    • Added debugging capabilities for the BeaconBlock struct during SSZ encoding.
  • Bug Fixes

    • Updated status representation in the backend process for better clarity.
  • Chores

    • Added new dependencies for logging, validation, and telemetry to enhance maintainability.
    • Centralized testing configurations for improved management.
  • Documentation

    • Comments added to outline future enhancements for structured ID management.

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

The recent updates to the Berachain ecosystem enhance functionality and organization across the codebase. Key improvements include the introduction of new constants and interfaces for better API interactions, streamlined testing configurations, and refined validation mechanisms. Additionally, command execution and context management optimizations improve operational capabilities, while updates to the testing suite promote maintainability. Overall, these changes aim to enhance clarity, usability, and extensibility throughout the system.

Changes

Files Change Summary
build/scripts/linting.mk, build/scripts/testing.mk Modified nilaway command to exclude errors in an additional directory; simplified test-unit-fuzz target by removing commands for certain fuzz tests.
kurtosis/src/nodes/consensus/beacond/*.star Added constants for a node API port; enhanced the start function with new command-line options for greater configurability.
mod/geth-primitives/pkg/eip4788/*.go Introduced Go bindings for the BeaconVerifier smart contract, providing structured interfaces for both read and write operations.
mod/node-api/backend/validator.go, mod/node-api/client/*.go Updated status representation in the validator; introduced a client for the BeaconKitNode with improved error handling and context management.
mod/node-api/handlers/node/*.go Added placeholder functions for syncing and version checks; updated route handling to implement these functionalities, enhancing API usability.
testing/e2e/*.go Established configuration for consensus clients and deposits; added end-to-end tests for the Beacon API; refactored constants for improved maintainability.
testing/go.mod, mod/node-api/go.mod Updated module dependencies and versions, including new libraries for logging and validation, enhancing overall functionality and observability.
mod/consensus-types/pkg/types/block.go Added a debugging statement to the DefineSSZ method in BeaconBlock, improving the visibility of the block's state during serialization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Handler
    participant NodeAPI

    User->>Handler: Request for Node Version
    Handler->>NodeAPI: Fetch Node Version
    NodeAPI-->>Handler: Return Node Version
    Handler-->>User: Respond with Node Version
Loading
sequenceDiagram
    participant User
    participant Handler
    participant Validator

    User->>Handler: Request for Syncing Status
    Handler->>Validator: Check Syncing Status
    Validator-->>Handler: Return Syncing Status
    Handler-->>User: Respond with Syncing Status
Loading

Poem

In the burrows, bright and new,
Changes hop with every view.
Linting clean and tests refined,
A rabbit's joy in code aligned! 🐇✨
With each update, we leap and dance,
Celebrating growth, we take a chance!


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 Configuration 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

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 76 lines in your changes missing coverage. Please review.

Project coverage is 21.78%. Comparing base (07b1861) to head (586a102).
Report is 1 commits behind head on main.

Files Patch % Lines
mod/node-api/handlers/node/placeholders.go 0.00% 30 Missing ⚠️
testing/e2e/suite/types/consensus_client.go 0.00% 27 Missing ⚠️
testing/e2e/suite/types/beacon_client.go 0.00% 13 Missing ⚠️
mod/node-api/handlers/node/routes.go 0.00% 2 Missing ⚠️
mod/node-api/backend/validator.go 0.00% 1 Missing ⚠️
mod/node-api/handlers/beacon/historical.go 0.00% 1 Missing ⚠️
mod/node-api/handlers/node/handler.go 0.00% 1 Missing ⚠️
testing/e2e/suite/setup.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1820      +/-   ##
==========================================
- Coverage   21.86%   21.78%   -0.09%     
==========================================
  Files         346      348       +2     
  Lines       15759    15821      +62     
  Branches       21       21              
==========================================
  Hits         3446     3446              
- Misses      12197    12259      +62     
  Partials      116      116              
Files Coverage Δ
mod/node-api/engines/echo/vaildator.go 0.00% <ø> (ø)
mod/node-api/handlers/utils/id.go 0.00% <ø> (ø)
mod/node-api/backend/validator.go 0.00% <0.00%> (ø)
mod/node-api/handlers/beacon/historical.go 0.00% <0.00%> (ø)
mod/node-api/handlers/node/handler.go 0.00% <0.00%> (ø)
testing/e2e/suite/setup.go 0.00% <0.00%> (ø)
mod/node-api/handlers/node/routes.go 0.00% <0.00%> (ø)
testing/e2e/suite/types/beacon_client.go 0.00% <0.00%> (ø)
testing/e2e/suite/types/consensus_client.go 0.00% <0.00%> (ø)
mod/node-api/handlers/node/placeholders.go 0.00% <0.00%> (ø)

Copy link
Contributor

@itsdevbear itsdevbear left a comment

Choose a reason for hiding this comment

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

move client to testing folder otherwise lgtm

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 2f85d0d and 4d7ad22.

Files selected for processing (4)
  • testing/e2e/e2e_api_test.go (1 hunks)
  • testing/e2e/suite/types/beacon_client.go (1 hunks)
  • testing/e2e/suite/types/consensus_client.go (4 hunks)
  • testing/go.mod (9 hunks)
Additional comments not posted (16)
testing/e2e/e2e_api_test.go (3)

1-20: Ensure License Compliance.

The file includes a Business Source License (BUSL-1.1). Ensure that all licensing terms are adhered to, including any obligations to provide source code or other requirements specified in the license.


23-27: Review Import Statements for Necessity and Usage.

The imports include specific packages from attestantio and berachain. Ensure these are necessary and used within the file. If any are unused, consider removing them to maintain clarity.


31-49: Add a Check for Non-Zero State Root.

The past comment suggests adding a check for non-zero state root. Ensure this is implemented to prevent potential issues with zeroed state roots.

testing/e2e/suite/types/beacon_client.go (4)

1-20: Ensure License Compliance.

The file includes a Business Source License (BUSL-1.1). Ensure that all licensing terms are adhered to, including any obligations to provide source code or other requirements specified in the license.


23-29: Review Import Statements for Necessity and Usage.

The imports include packages for context management and client interfaces. Ensure these are necessary and used within the file. If any are unused, consider removing them to maintain clarity.


31-85: Interface Segregation Principle (ISP) Adherence.

The BeaconKitNode interface extends multiple client interfaces. Ensure that it adheres to the Interface Segregation Principle by only including methods that are necessary for its implementation.


87-107: Handle Type Assertion Errors Gracefully.

The NewBeaconKitClient function handles errors during type assertion. Ensure that the error message is clear and provides enough context for debugging.

testing/e2e/suite/types/consensus_client.go (6)

Line range hint 1-20: Ensure License Compliance.

The file includes a Business Source License (BUSL-1.1). Ensure that all licensing terms are adhered to, including any obligations to provide source code or other requirements specified in the license.


27-32: Review Import Statements for Necessity and Usage.

The imports include packages for context management, error handling, and client interactions. Ensure these are necessary and used within the file. If any are unused, consider removing them to maintain clarity.


55-55: Avoid Using panic for Error Handling.

Using panic for error handling is not ideal for robustness. Consider returning an error instead to allow for graceful handling by the caller.


63-94: Context Management and Error Handling in Connect.

The Connect method includes context management and error handling. Ensure that the context is appropriately canceled on errors to prevent resource leaks.


108-108: Ensure Proper Context Passing in Start.

The Start method passes the context to the Connect method. Verify that the context is correctly managed throughout the operation.


115-115: Ensure Proper Resource Cleanup in Stop.

The Stop method calls cc.cancelFunc() to cleanly cancel ongoing operations. Ensure that this effectively releases all resources.

testing/go.mod (3)

9-9: Local module replacement approved.

The replacement of github.com/berachain/beacon-kit/mod/node-api with a local path supports local development and testing, which aligns with the PR objectives.


Line range hint 34-254: New indirect dependencies approved.

The addition of new indirect dependencies such as github.com/go-logr/logr, github.com/go-logr/stdr, and go.opentelemetry.io/otel aligns with the project's goals to enhance logging and observability.


18-18: Version update approved. Verify compatibility.

The update to github.com/berachain/beacon-kit/mod/log is approved. Ensure that the updated version is compatible with the rest of the project.

testing/e2e/suite/types/consensus_client.go Show resolved Hide resolved
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4d7ad22 and cf36833.

Files selected for processing (1)
  • testing/e2e/e2e_api_test.go (1 hunks)
Additional comments not posted (2)
testing/e2e/e2e_api_test.go (2)

1-19: License Information Approved.

The license information is correctly formatted and appears standard for the project.


21-29: Package Declaration and Imports Approved.

The package name and imports are appropriate for the file's purpose.

testing/e2e/e2e_api_test.go Outdated Show resolved Hide resolved
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: ASSERTIVE

Commits

Files that changed from the base of the PR and between cf36833 and 002012e.

Files selected for processing (2)
  • mod/node-api/handlers/beacon/historical.go (1 hunks)
  • testing/e2e/e2e_api_test.go (1 hunks)
Additional comments not posted (3)
testing/e2e/e2e_api_test.go (1)

31-49: Consider Using a Test Logger Instead of fmt.Println.

Using fmt.Println for logging within tests is generally discouraged. Consider using a test logger or s.T().Log for better integration with test output.

- fmt.Println("stateRootResp data", *stateRootResp.Data)
+ s.T().Log("stateRootResp data", *stateRootResp.Data)
mod/node-api/handlers/beacon/historical.go (2)

50-50: Simplified Data Assignment in GetStateRoot.

The direct assignment of RootData improves clarity by removing unnecessary wrapping. Ensure that this change aligns with the expected data handling throughout the codebase.


Line range hint 64-64: Verify Necessity of types.Wrap in GetStateFork.

While GetStateRoot now directly assigns data, GetStateFork still uses types.Wrap. Ensure that this wrapping is necessary and consistent with the intended data handling.

Verification successful

Use of types.Wrap in GetStateFork is Necessary

The types.Wrap function is used to structure the response data consistently within the codebase. Its usage in GetStateFork is necessary to wrap the fork data into a DataResponse, aligning with how responses are generally handled. This ensures consistency and proper encapsulation of the response data.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and necessity of `types.Wrap` in the codebase.

# Test: Search for `types.Wrap` usage. Expect: Consistent usage across similar methods.
rg --type go 'types\.Wrap'

Length of output: 196


Script:

#!/bin/bash
# Description: Investigate the definition of `types.Wrap` and its necessity.

# Find the definition of `types.Wrap` to understand its purpose.
rg --type go 'func Wrap' -A 10

# Find the usage of `fork` in the `GetStateFork` method to see how it's used.
rg --type go 'GetStateFork' -A 20

Length of output: 6185

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: ASSERTIVE

Commits

Files that changed from the base of the PR and between 002012e and 38c9273.

Files selected for processing (1)
  • build/scripts/testing.mk (1 hunks)
Additional comments not posted (1)
build/scripts/testing.mk (1)

Line range hint 144-148:
Verify the adequacy of remaining fuzz tests.

The test-unit-fuzz target has been simplified to include only two fuzz tests. Ensure that these tests sufficiently cover critical paths and potential edge cases. If the removed tests are still necessary, consider reintroducing them or justifying their removal.

Verification successful

No issue with the removal of fuzz tests from test-unit-fuzz. The removed fuzz tests FuzzPayloadIDCacheBasic and FuzzPayloadIDInvalidInput are still being executed in other parts of the testing.mk file. This ensures that critical paths and edge cases are still covered. The simplification of the test-unit-fuzz target does not compromise the overall testing strategy.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removed fuzz tests are not necessary.

# Test: Check for the presence of removed fuzz tests in the codebase.
# Expect: No critical paths or edge cases are left untested.
rg --type go -A 5 'FuzzPayloadIDCacheBasic|FuzzPayloadIDInvalidInput'

Length of output: 1180


Script:

#!/bin/bash
# Description: Check if the removed fuzz tests are included in other targets or scripts.

# Search for references to the removed fuzz tests in the Makefile or other scripts.
rg 'FuzzPayloadIDCacheBasic|FuzzPayloadIDInvalidInput' build/scripts

Length of output: 314

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 comments (1)
testing/e2e/suite/types/consensus_client.go (1)

Line range hint 48-57: Avoid Using panic for Error Handling.

Using panic for error handling in NewConsensusClient is not ideal. Consider returning an error instead to allow for graceful handling by the caller.

-  if err := cc.Connect(context.Background()); err != nil {
-    panic(err)
+  if err := cc.Connect(context.Background()); err != nil {
+    return nil, err
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 38c9273 and e569d6c.

Files selected for processing (2)
  • testing/e2e/suite/types/beacon_client.go (1 hunks)
  • testing/e2e/suite/types/consensus_client.go (4 hunks)
Additional comments not posted (9)
testing/e2e/suite/types/beacon_client.go (4)

1-21: License and Package Declaration: Looks Good!

The license header and package declaration are appropriate and correctly formatted.


23-29: Imports: Looks Good!

The imported packages are necessary and relevant for the implementation of the beacon client.


31-85: Interface Definition: Looks Good!

The BeaconKitNodeClient interface is well-structured, extending necessary interfaces for comprehensive beacon node interaction.


87-107: Function Implementation: Looks Good!

The NewBeaconKitNodeClient function is well-implemented, with appropriate error handling and context management.

testing/e2e/suite/types/consensus_client.go (5)

27-32: Imports: Looks Good!

The imported packages are necessary for context management, error handling, and client interactions.


37-46: Struct Definition: Looks Good!

The ConsensusClient struct is well-organized, with new fields enhancing functionality and context management.


63-94: Reconsider the Use of panic for Error Handling.

Using panic for error handling when the public port is not found is not ideal for robustness. Consider returning an error instead to allow for graceful handling by the caller.

-    panic("Couldn't find the public port for the comet JSON-RPC")
+    return fmt.Errorf("couldn't find the public port for the comet JSON-RPC")
-    panic("Couldn't find the public port for the node API")
+    return fmt.Errorf("couldn't find the public port for the node API")

Line range hint 96-155: Method Implementations: Looks Good!

The Start, Stop, and other methods are well-implemented, with proper context management and error handling.


154-155: Implement TODOs for Beacon Node-API Client Helpers.

The TODO comment indicates that helper functions for the beacon node-api client are needed. Consider implementing these to facilitate conversions and interactions.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e569d6c and 4bd3be6.

Files selected for processing (1)
  • mod/consensus-types/pkg/types/block.go (2 hunks)

mod/consensus-types/pkg/types/block.go Outdated Show resolved Hide resolved
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: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4bd3be6 and 586a102.

Files ignored due to path filters (1)
  • testing/go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • testing/go.mod (9 hunks)
Additional comments not posted (5)
testing/go.mod (5)

9-9: Verify the necessity of the local module replacement.

The replacement of github.com/berachain/beacon-kit/mod/node-api with a local path is useful for local development. Ensure this change is not included in the production codebase.


18-18: Verify compatibility of the updated mod/log version.

The version update for github.com/berachain/beacon-kit/mod/log may include new features or bug fixes. Ensure that this update is compatible with the rest of the codebase.


120-121: Enhancements for logging and observability.

The addition of github.com/go-logr/logr, github.com/go-logr/stdr, and go.opentelemetry.io/otel enhances logging and observability capabilities, which are vital for monitoring and debugging.

Also applies to: 237-239


247-247: Verify the usage of golang.org/x/xerrors.

The addition of golang.org/x/xerrors provides advanced error handling capabilities. Ensure it is used effectively in the codebase.


253-254: Verify the necessity and usage of new dependencies.

The addition of gopkg.in/Knetic/govaluate.v3 and gopkg.in/cenkalti/backoff.v1 can enhance expression evaluation and retry mechanisms. Verify their necessity and correct usage in the codebase.

@itsdevbear itsdevbear enabled auto-merge (squash) August 20, 2024 15:31
@itsdevbear itsdevbear merged commit 58bd944 into main Aug 20, 2024
16 checks passed
@itsdevbear itsdevbear deleted the api-e2e branch August 20, 2024 15:34
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.

3 participants