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

chore: add back removal regex #591

Merged
merged 2 commits into from
Mar 25, 2024
Merged

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Mar 25, 2024

Description

Closes: #XXXX

Matt tested and determined this PR is non problematic. Adding it back.

Summary by CodeRabbit

  • New Features
    • Implemented caching speedups in CacheKV.
    • Introduced v0.50 slashing bitmap logic in the latest release.
  • Bug Fixes
    • Updated error messages for invalid coin denominations across various tests and functions.
  • Refactor
    • Changed the regular expression for coin denominations to support a broader range of characters.
    • Enhanced validation logic for coin denominations, including custom parsing logic for decimal coins.

Copy link

coderabbitai bot commented Mar 25, 2024

Walkthrough

The v24 update of cosmos-sdk introduces significant enhancements focusing on speed improvements in CacheKV and the adoption of v0.50 slashing bitmap logic. Moreover, it standardizes error messaging and customizes regex patterns for coin denominations across various tests and types, ensuring stricter validation and more intuitive error responses for users. This version marks a leap towards optimized performance and user-friendly error handling.

Changes

Files Change Summary
CHANGELOG.md Introduced caching speedups in CacheKV and implemented v0.50 slashing bitmap logic in v0.47.5-v24-osmo-3.
tests/.../authz/tx.go
x/authz/.../tx_test.go
Changed error message to "invalid character in denomination."
tests/integration/bank/.../deterministic_test.go
tests/integration/staking/.../deterministic_test.go
Switched to custom regex pattern [a-zA-Z][a-zA-Z0-9/:._-]{2,127} for coin denominations.
types/coin.go
types/coin_test.go
types/dec_coin.go
Enhanced denomination validation with new regex, added unicode support, and introduced functions for rune validation and denomination matching.
x/gov/.../util_test.go Updated expected error messages for invalid decimal coin expressions to focus on invalid characters in the denomination.

🐰✨
In the world of code, where changes abound,
A rabbit hopped in, improvements were found.
With regex so neat and errors so clear,
cosmos-sdk v24 brings cheer.
So here's to the devs, with their code so bright,
May your bugs be few, and your tests always right.
🌟🐇

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.
    • 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 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 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.

@@ -326,7 +326,7 @@ func (s *CLITestSuite) TestCLITxGrantAuthorization() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()),
},
true,
"invalid decimal coin expression",
"nvalid character in denomination: ",
Copy link

Choose a reason for hiding this comment

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

The error message has been modified to be more specific, which is beneficial. However, there appears to be a typographical error in the message. It should likely start with "Invalid" instead of "nvalid".

- "nvalid character in denomination: ",
+ "Invalid character in denomination: ",

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
"nvalid character in denomination: ",
"Invalid character in denomination: ",

@@ -130,7 +132,7 @@ func (s *coinTestSuite) TestCustomValidation() {
for i, tc := range cases {
s.Require().Equal(tc.expectPass, tc.coin.IsValid(), "unexpected result for IsValid, tc #%d", i)
}
sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex)
sdk.SetCoinDenomRegex(func() string { return reDnmString })
Copy link

Choose a reason for hiding this comment

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

After modifying the coin denomination regex with sdk.SetCoinDenomRegex, it's a good practice to reset it to its original state at the end of the test to prevent unintended side effects on subsequent tests.

+ defer sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex)

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
sdk.SetCoinDenomRegex(func() string { return reDnmString })
sdk.SetCoinDenomRegex(func() string { return reDnmString })
defer sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex)

Comment on lines +874 to +901
// isValidRune checks if a given rune is a valid character for a rune.
// It returns true if the rune is a letter, digit, '/', ':', '.', '_', or '-'.
func isValidRune(r rune) bool {
return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-'
}

// MatchDenom checks if the given string is a valid denomination.
// A valid denomination must have a length between 3 and 128 characters,
// start with a letter, and only contain valid runes.
func MatchDenom(s string) bool {
length := len(s)
if length < 3 || length > 128 {
return false
}

firstRune := rune(s[0])
if !unicode.IsLetter(firstRune) {
return false
}

for _, r := range s[1:] {
if !isValidRune(r) {
return false
}
}

return true
}
Copy link

Choose a reason for hiding this comment

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

The introduction of isValidRune and MatchDenom functions enhances the validation logic by providing clear, focused checks for denomination validity. This modular approach improves the maintainability and readability of the code. It's recommended to add unit tests for these functions to ensure their correctness and handle edge cases effectively.

Would you like me to help with adding unit tests for these new validation functions?

@czarcas7ic czarcas7ic merged commit 0732c8a into osmo/v0.47.5 Mar 25, 2024
21 checks passed
@czarcas7ic czarcas7ic deleted the adam/add-back-removal-regex branch March 25, 2024 17:05
mergify bot pushed a commit that referenced this pull request Mar 25, 2024
* Reapply "Backport: Removal of regex usage on denom validation  (#570)"

This reverts commit a07f5de.

* changelog

(cherry picked from commit 0732c8a)
czarcas7ic added a commit that referenced this pull request Mar 25, 2024
* Reapply "Backport: Removal of regex usage on denom validation  (#570)"

This reverts commit a07f5de.

* changelog

(cherry picked from commit 0732c8a)

Co-authored-by: Adam Tucker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant