Skip to content

Commit

Permalink
fix(textual): error if a formatted coin contains a comma (#19265)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
facundomedica and alexanderbez authored Jan 29, 2024
1 parent bb239a4 commit 7d66bb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Bug Fixes

* [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) Reject denoms that contain a comma.

### Improvements

* [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` from `core/coins` to this package under `signing/textual`.
Expand Down
6 changes: 6 additions & 0 deletions x/tx/signing/textual/coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ func FormatCoins(coins []*basev1beta1.Coin, metadata []*bankv1beta1.Metadata) (s
if err != nil {
return "", err
}

// If a coin contains a comma, return an error given that the output
// could be misinterpreted by the user as 2 different coins.
if strings.Contains(formatted[i], ",") {
return "", fmt.Errorf("coin %s contains a comma", formatted[i])
}
}

if len(coins) == 0 {
Expand Down
7 changes: 6 additions & 1 deletion x/tx/signing/textual/internal/testdata/coin.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,10 @@
{"text":"", "error": true},
{"text":"1COSM", "error": true},
{"text":"1 COSM", "error": true},
{"text":" 1 COSM", "error": true}
{"text":" 1 COSM", "error": true},
{
"proto": {"amount": "10000000", "denom": "point, 222222 point"},
"metadata": {"display": "POINT", "base": "point", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]},
"error": true
}
]

0 comments on commit 7d66bb3

Please sign in to comment.