Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

test: add tests staking #1439

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

test: add tests staking #1439

wants to merge 11 commits into from

Conversation

hoank101
Copy link

@hoank101 hoank101 commented Jan 18, 2024

add tests staking and improve coverage

Summary by CodeRabbit

  • New Features

    • Enhanced staking-related test coverage with new test cases.
    • Introduced telemetry metrics for transaction pool events and mempool statistics.
    • Improved client compatibility in Ethereum compatibility layer by handling cases when the pending block is not available.
  • Improvements

    • Added constants for timeout configuration to simplify codebase and improve maintainability.
    • Improved error messaging in configuration parsing.
  • Refactor

    • Separated stateless and stateful checks in transaction processing logic.
    • Refactored transaction inclusion logic for better clarity and tracking.
  • Documentation

    • No visible documentation changes for end-users.
  • Bug Fixes

    • No user-facing bug fixes reported.
  • Style

    • No style changes affecting end-users.
  • Tests

    • Expanded test suite for staking functionality.
  • Chores

    • Internal code cleanup and telemetry enhancements.
  • Revert

    • No reverts affecting end-users.

Copy link

coderabbitai bot commented Jan 18, 2024

Walkthrough

The recent updates encompass enhancements to testing, configuration, and runtime transaction handling in the Cosmos codebase. New test cases and blocks have been added, constants for timeouts have been introduced, error messaging has been improved, and telemetry has been integrated to track events and metrics. The transaction pool logic has been refactored for better performance and monitoring, while the Ethereum compatibility layer has been adjusted to improve client interactions and error responses.

Changes

Files Change Summary
cosmos/precompile/staking/staking_test.go Introduced new test blocks for validator and delegator functions.
cosmos/config/default.go
cosmos/config/config.go
Added new constants for timeouts and improved error formatting.
cosmos/runtime/txpool/ante.go
cosmos/runtime/txpool/handler.go
cosmos/runtime/txpool/mempool.go
cosmos/runtime/txpool/mocks/tx_sub_provider.go
cosmos/runtime/txpool/telemetry.go
Refactored transaction pool logic, added telemetry tracking, and introduced new methods for transaction handling.
eth/polar/api_backend.go Enhanced client compatibility and error handling for block and state retrieval methods.

"In the realm of code, where the cosmos align,
🐇 CodeRabbit hopped through, with updates to refine.
With tests now in place, and metrics to trace,
The blockchain's heart beats, with a more stable pace."

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1fc6fc3 and 4114e04.
Files selected for processing (1)
  • cosmos/precompile/staking/staking_test.go (1 hunks)
Additional comments: 4
cosmos/precompile/staking/staking_test.go (4)
  • 610-638: The tests added for GetBondedValidatorsByPower cover scenarios with no active validators, one active validator, and all validators active. This is a good range of test cases to ensure the method works under different conditions.
  • 640-658: The tests for GetValidators include scenarios without pagination and with pagination. This ensures that the pagination logic is correctly handled.
  • 661-670: The tests for GetValidator check both a valid and an invalid validator. It's important to ensure that the method behaves correctly when provided with an invalid address.
  • 673-683: The tests for GetDelegatorValidators include a success case and a case with an invalid delegator. This ensures that the method can handle error scenarios gracefully.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4114e04 and 112dcc6.
Files selected for processing (1)
  • cosmos/precompile/staking/staking_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/precompile/staking/staking_test.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 112dcc6 and 223f7d3.
Files selected for processing (1)
  • cosmos/precompile/staking/staking_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/precompile/staking/staking_test.go

@hoank101
Copy link
Author

can you review this PR @itsdevbear

@itsdevbear
Copy link
Member

Lgtm just fix linter, the e2e tests failing is on us, we will fix :)

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 223f7d3 and 83160b3.
Files selected for processing (1)
  • cosmos/config/default.go (2 hunks)
Additional comments: 2
cosmos/config/default.go (2)
  • 34-36: Introduced constants TimeoutProposeSeconds and TimeoutDefault. Ensure that the naming convention is consistent with the project's standards and that the values are appropriate for the timeouts they represent.
  • 53-55: Replaced hard-coded timeout values with the new constants in the RecommendedCometBFTConfig function. Verify that these changes do not affect other parts of the codebase where the previous hard-coded values were expected.
Verification successful

The verification process has confirmed that the changes made to the timeout values in the RecommendedCometBFTConfig function using the new constants TimeoutProposeSeconds and TimeoutDefault are localized and do not affect other parts of the codebase. The constants are not used outside of the cosmos/config/default.go file, and other instances of time.Second in the codebase are unrelated to the consensus timeouts and serve different purposes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old hard-coded timeout values to ensure they are not used elsewhere.
rg --type go '3 \* time.Second' --context 5
rg --type go '1 \* time.Second' --context 5

Length of output: 91



Script:

#!/bin/bash
# Search for any occurrences of 'time.Second' to catch any other hard-coded timeout values.
rg --type go 'time.Second' --context 5

# Check for the usage of the new constants `TimeoutProposeSeconds` and `TimeoutDefault`.
rg --type go 'TimeoutProposeSeconds' --context 5
rg --type go 'TimeoutDefault' --context 5

Length of output: 6964

@hoank101
Copy link
Author

hoank101 commented Jan 19, 2024

Lgtm just fix linter, the e2e tests failing is on us, we will fix :)

thank you, fixed

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (17ea475) 46.33% compared to head (83160b3) 47.38%.
Report is 10 commits behind head on main.

❗ Current head 83160b3 differs from pull request most recent head a1d16e1. Consider uploading reports for the commit a1d16e1 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1439      +/-   ##
==========================================
+ Coverage   46.33%   47.38%   +1.05%     
==========================================
  Files          89       89              
  Lines        5169     5149      -20     
==========================================
+ Hits         2395     2440      +45     
+ Misses       2598     2524      -74     
- Partials      176      185       +9     
Files Coverage Δ
cosmos/runtime/txpool/ante.go 0.00% <ø> (ø)
cosmos/runtime/txpool/comet.go 42.85% <ø> (ø)
cosmos/runtime/txpool/handler.go 64.76% <ø> (-0.06%) ⬇️
cosmos/runtime/txpool/mempool.go 0.00% <0.00%> (ø)
cosmos/config/default.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

@hoank101
Copy link
Author

@itsdevbear
All PR after #1439 has linter error, please merge it before merge other PR

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 83160b3 and 7d2df3d.
Files ignored due to path filters (18)
  • build/tools/go.mod is excluded by: !**/*.mod
  • build/tools/go.sum is excluded by: !**/*.sum
  • contracts/go.mod is excluded by: !**/*.mod
  • contracts/go.sum is excluded by: !**/*.sum
  • cosmos/go.mod is excluded by: !**/*.mod
  • cosmos/go.sum is excluded by: !**/*.sum
  • e2e/localnet/go.mod is excluded by: !**/*.mod
  • e2e/localnet/go.sum is excluded by: !**/*.sum
  • e2e/precompile/go.mod is excluded by: !**/*.mod
  • e2e/precompile/go.sum is excluded by: !**/*.sum
  • e2e/testapp/go.mod is excluded by: !**/*.mod
  • e2e/testapp/go.sum is excluded by: !**/*.sum
  • eth/go.mod is excluded by: !**/*.mod
  • eth/go.sum is excluded by: !**/*.sum
  • go.work is excluded by: !**/*.work
  • go.work.sum is excluded by: !**/*.sum
  • lib/go.mod is excluded by: !**/*.mod
  • lib/go.sum is excluded by: !**/*.sum
Files selected for processing (7)
  • cosmos/config/default.go (2 hunks)
  • cosmos/runtime/txpool/ante.go (4 hunks)
  • cosmos/runtime/txpool/handler.go (6 hunks)
  • cosmos/runtime/txpool/mempool.go (2 hunks)
  • cosmos/runtime/txpool/mocks/tx_sub_provider.go (1 hunks)
  • cosmos/runtime/txpool/telemetry.go (1 hunks)
  • eth/polar/api_backend.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/config/default.go
Additional comments: 11
cosmos/runtime/txpool/telemetry.go (1)
  • 25-45: The introduction of new metric keys for telemetry is consistent with the summary. The prefix change to "polaris_cometbft_" aligns with the CometBFT consensus algorithm branding. This change is straightforward and does not appear to introduce any issues.
cosmos/runtime/txpool/mocks/tx_sub_provider.go (1)
  • 57-59: The Stats method has been added to the TxSubProvider mock as described in the summary. It returns two integers, presumably representing some statistics about transactions. Since this is a mock, the implementation is expected to be simplistic. However, it's important to ensure that the actual implementation of Stats in the real TxSubProvider interface is consistent with this mock.
cosmos/runtime/txpool/ante.go (1)
  • 70-114: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [42-113]

Telemetry increments have been added to the AnteHandle and shouldEjectFromCometMempool functions to track events such as ejections from the mempool. The logic within shouldEjectFromCometMempool has been refactored to separate stateless and stateful checks, which is a good practice for clarity and maintainability. The added telemetry increments for expired transactions and transactions with gas price below the limit are consistent with the summary and seem to be correctly implemented.

cosmos/runtime/txpool/mempool.go (2)
  • 36-36: The import statement for telemetry from "github.com/cosmos/cosmos-sdk/telemetry" has been added, which is necessary for the new telemetry features being implemented.
  • 134-134: A new telemetry counter is incremented under certain conditions within the Insert function. This change is consistent with the summary and the overall goal of enhancing telemetry within the transaction pool.
cosmos/runtime/txpool/handler.go (3)
  • 45-45: The constants statPeriod and retryDelay have been added. These constants are used for scheduling statistics reporting and managing retry delays, respectively. The introduction of these constants is a good practice for code maintainability and readability.
  • 56-56: The Stats method has been added to the TxSubProvider interface, which is consistent with the changes in the mock file and the summary.
  • 181-201: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [126-197]

Three new methods, statLoop, failedLoop, and Stats, have been added to the handler type, and telemetry tracking has been incorporated into the mainLoop and failedLoop methods. These changes are consistent with the summary and are implemented correctly to enhance the tracking and handling of transactions within the runtime transaction pool.

eth/polar/api_backend.go (3)
  • 208-213: The HeaderByNumber method has been modified to return the latest state if the pending block is not available, which improves client compatibility. This change is consistent with the summary and is a sensible fallback.
  • 262-269: Similarly, the BlockByNumber method has been updated to handle the case when the pending block is not available by returning the latest state. This change aligns with the summary and the modification in the HeaderByNumber method.
  • 208-213: Both HeaderByNumber and BlockByNumber methods have been modified to improve client compatibility by returning the latest state if the pending block is not available. This is a good approach to ensure that the system remains functional even when the pending block is not present.

Also applies to: 262-269

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 83160b3 and 874f08d.
Files selected for processing (1)
  • cosmos/config/config.go (2 hunks)
Additional comments: 2
cosmos/config/config.go (2)
  • 24-24: The addition of the "fmt" package import is appropriate for the use of fmt.Errorf in the error handling.
  • 110-110: The use of fmt.Errorf to format the error message with the invalid git commit length is correct and improves error reporting.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 112dcc6 and 73442f6.
Files selected for processing (1)
  • cosmos/precompile/staking/staking_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cosmos/precompile/staking/staking_test.go

@hoank101
Copy link
Author

hi @itsdevbear can you merge this PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants