-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -112,6 +112,8 @@ func (s *coinTestSuite) TestCoinIsValid() { | |||||||
|
||||||||
func (s *coinTestSuite) TestCustomValidation() { | ||||||||
newDnmRegex := `[\x{1F600}-\x{1F6FF}]` | ||||||||
reDnmString := `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}` | ||||||||
|
||||||||
sdk.SetCoinDenomRegex(func() string { | ||||||||
return newDnmRegex | ||||||||
}) | ||||||||
|
@@ -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 }) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After modifying the coin denomination regex with + defer sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex) Committable suggestion
Suggested change
|
||||||||
} | ||||||||
|
||||||||
func (s *coinTestSuite) TestCoinsDenoms() { | ||||||||
|
@@ -998,6 +1000,33 @@ func (s *coinTestSuite) TestParseCoins() { | |||||||
} | ||||||||
} | ||||||||
|
||||||||
func (s *coinTestSuite) TestValidateDenom() { | ||||||||
cases := []struct { | ||||||||
input string | ||||||||
valid bool | ||||||||
}{ | ||||||||
{"", false}, | ||||||||
{"stake", true}, | ||||||||
{"stake,", false}, | ||||||||
{"me coin", false}, | ||||||||
{"me coin much", false}, | ||||||||
{"not a coin", false}, | ||||||||
{"foo:bar", true}, // special characters '/' | ':' | '.' | '_' | '-' are allowed | ||||||||
{"atom10", true}, // number in denom is allowed | ||||||||
{"transfer/channelToA/uatom", true}, | ||||||||
{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true}, | ||||||||
} | ||||||||
|
||||||||
for _, tc := range cases { | ||||||||
err := sdk.ValidateDenom(tc.input) | ||||||||
if !tc.valid { | ||||||||
s.Require().Error(err) | ||||||||
} else { | ||||||||
s.Require().NoError(err) | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
func (s *coinTestSuite) TestSortCoins() { | ||||||||
good := sdk.Coins{ | ||||||||
sdk.NewInt64Coin("gas", 1), | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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: ", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||
}, | ||||||
{ | ||||||
"Valid tx send authorization", | ||||||
|
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.
The introduction of
isValidRune
andMatchDenom
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?