Skip to content

Commit

Permalink
feat!: update Denom regex to support more DID characters (#9699)
Browse files Browse the repository at this point in the history
* feat!: support DID method-specific-id regex in denoms

* udpate docs

* add test case

* update CHANGELOG.md

* fix CHANGELOG.md

* fix test

* fix test
  • Loading branch information
aaronc committed Sep 27, 2021
1 parent 4c3aa4d commit 3138527
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -117,6 +117,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command.
* (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls.
* (rosetta) [\#10001](https://github.com/cosmos/cosmos-sdk/issues/10001) Add documentation for rosetta-cli dockerfile and rename folder for the rosetta-ci dockerfile
* [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression.

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions types/coin.go
Expand Up @@ -644,8 +644,8 @@ func (coins Coins) Sort() Coins {

var (
// Denominations can be 3 ~ 128 characters long and support letters, followed by either
// a letter, a number or a separator ('/').
reDnmString = `[a-zA-Z][a-zA-Z0-9/-]{2,127}`
// a letter, a number or a separator ('/', ':', '.', '_' or '-').
reDnmString = `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}`
reDecAmt = `[[:digit:]]+(?:\.[[:digit:]]+)?|\.[[:digit:]]+`
reSpc = `[[:space:]]*`
reDnm *regexp.Regexp
Expand Down
3 changes: 2 additions & 1 deletion types/coin_test.go
Expand Up @@ -96,6 +96,7 @@ func (s *coinTestSuite) TestCoinIsValid() {
{sdk.Coin{loremIpsum, sdk.OneInt()}, false},
{sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, true},
{sdk.Coin{"atOm", sdk.OneInt()}, true},
{sdk.Coin{"x:y-z.1_2", sdk.OneInt()}, true},
{sdk.Coin{" ", sdk.OneInt()}, false},
}

Expand Down Expand Up @@ -706,7 +707,7 @@ func (s *coinTestSuite) TestParseCoins() {
{"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name
{"11me coin, 12you coin", false, nil}, // no spaces in coin names
{"1.2btc", true, sdk.Coins{{"btc", sdk.NewInt(1)}}}, // amount can be decimal, will get truncated
{"5foo:bar", false, nil}, // invalid separator
{"5foo:bar", true, sdk.Coins{{"foo:bar", sdk.NewInt(5)}}},
{"10atom10", true, sdk.Coins{{"atom10", sdk.NewInt(10)}}},
{"200transfer/channelToA/uatom", true, sdk.Coins{{"transfer/channelToA/uatom", sdk.NewInt(200)}}},
{"50ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true, sdk.Coins{{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(50)}}},
Expand Down

0 comments on commit 3138527

Please sign in to comment.