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

Add test cases to consensus params validate #1536

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

Manav-Aggarwal
Copy link
Member

@Manav-Aggarwal Manav-Aggarwal commented Feb 9, 2024

Overview

Closes: #1379

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • Refactor
    • Improved error handling in consensus parameter validation for enhanced clarity in error messages.
  • Tests
    • Added new test cases for consensus parameter validation to ensure robustness and reliability.

Copy link
Contributor

coderabbitai bot commented Feb 9, 2024

Warning

Rate Limit Exceeded

@Manav-Aggarwal has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 44 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between bc6b409 and 36663bb.

Walkthrough

This update focuses on refining the error handling within the ConsensusParamsValidateBasic function and enhancing the test suite for consensus parameters. By introducing specific error variables and expanding test coverage, the changes aim to improve error messages and ensure the system's robustness through comprehensive testing.

Changes

Files Change Summary
types/params.go Refactored error handling by introducing specific error variables for improved error messages.
types/params_test.go Added new test cases covering MaxBytes, MaxGas, VoteExtensionsEnableHeight, and PubKeyTypes with corresponding error checks.

Assessment against linked issues

Objective Addressed Explanation
Enhance test coverage of TestConsensusParamsValidateBasic for robustness (#1379)
Ensure added test cases cover edge cases and boundary conditions (#1379)
Improve reliability and effectiveness of the test suite for validating consensus parameters (#1379)

Poem

In the garden of code, where logic threads weave,
A rabbit hopped in, with tricks up its sleeve.
🐇💻 With a flair and a bound, it refined and it tested,
Ensuring the code was robustly bested.

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.

@Manav-Aggarwal Manav-Aggarwal added T:testing Related to testing T:code-hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. labels Feb 9, 2024
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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 254e958 and ac7ae45.
Files selected for processing (2)
  • types/params.go (1 hunks)
  • types/params_test.go (1 hunks)
Additional comments: 7
types/params.go (2)
  • 24-33: Use errors.New for static error messages and fmt.Errorf for dynamic error messages. The current usage is correct, but ensure consistency across the codebase.
  • 38-46: The error wrapping with %w is correctly used for dynamic error messages, allowing for error unwrapping. This is a good practice.
types/params_test.go (5)
  • 35-46: The test case "MaxBytes cannot be 0" correctly prepares the test data and expects the appropriate error. This aligns with the validation logic.
  • 49-60: The test case "MaxBytes invalid" is well-structured, testing for a specific invalid condition. Ensure that the error message in the assertion matches the one defined in types/params.go.
  • 88-101: The test case "VoteExtensionsEnableHeight negative" is correctly set up to test negative values for VoteExtensionsEnableHeight. This is a good practice for boundary testing.
  • 104-117: The test case "PubKeyTypes empty" accurately tests the scenario where PubKeyTypes is an empty slice. This aligns with the validation logic that expects at least one pubkey type.
  • 120-133: The test case "PubKeyType unknown" tests for an unknown pubkey type, which is a valuable edge case. Ensure that the string "unknownType" does not accidentally become a valid type in the future.

types/params.go Outdated Show resolved Hide resolved
types/params.go Outdated Show resolved Hide resolved
types/params_test.go Show resolved Hide resolved
Copy link
Contributor

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

couple minor edits, otherwise LGTM 👍

types/params.go Outdated Show resolved Hide resolved
types/params.go Show resolved Hide resolved
types/params.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ac7ae45 and bc6b409.
Files selected for processing (1)
  • types/params.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • types/params.go

@MSevey MSevey added this pull request to the merge queue Feb 9, 2024
Merged via the queue into main with commit e014d85 Feb 9, 2024
17 checks passed
@MSevey MSevey deleted the manav/add_more_test_cases_to_consensus_params_validate branch February 9, 2024 20:17
AryanGodara pushed a commit to AryanGodara/rollkit that referenced this pull request Feb 13, 2024
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

Closes: rollkit#1379

<!--
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue.
-->

<!--
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords

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

- **Refactor**
- Improved error handling in consensus parameter validation for enhanced
clarity in error messages.
- **Tests**
- Added new test cases for consensus parameter validation to ensure
robustness and reliability.

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

move getRandomBlockWithProposer to utils

create single getBlockfunction always returning privkey

update to context pattern

update getValidator to a single function, remove redundant code

change height to pointer, allow passing nil for all three types

update GetRanomBytes to use Crypto.read, and check for errors

extract out repitition of start-stop node code for each test

refactor node-creation for fullnodes and lightnodes, add enum type for nodes instead of hardcoded string

pass testing.T pointer to helper functions, instead of directly passing assert (only few remaining instances)

refactor initializeAndStartNode to handle node teardown, reduce redundant calls to cleanupnode

streamline the setdalc pattern using helper function

change to use loop for all test cases

update helper name, and return app config created inside it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:code-hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. T:testing Related to testing
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add more test cases to TestConsensusParamsValidateBasic for robustness
3 participants