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

R4R: Fix token printing bug #3207

Merged
merged 3 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BREAKING CHANGES

* SDK
* [\#3064](https://github.com/cosmos/cosmos-sdk/issues/3064) Sanitize `sdk.Coin` denom. Coins denoms are now case insensitive, i.e. 100fooToken equals to 100FOOTOKEN.
* \#3207 - Fix token printing bug

* Tendermint

Expand Down
7 changes: 6 additions & 1 deletion types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ func (coins Coins) IsValid() bool {
case 1:
return coins[0].IsPositive()
default:
if strings.ToLower(coins[0].Denom) != coins[0].Denom {
return false
}
if !coins[0].IsPositive() {
return false
}
lowDenom := coins[0].Denom

for _, coin := range coins[1:] {
if strings.ToLower(coin.Denom) != coin.Denom {
return false
Expand Down
5 changes: 5 additions & 0 deletions types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ func TestCoins(t *testing.T) {
{"gas", NewInt(1)},
{"mineral", NewInt(1)},
}
neg := Coins{
{"gas", NewInt(-1)},
{"mineral", NewInt(1)},
}

assert.True(t, good.IsValid(), "Coins are valid")
assert.False(t, mixedCase.IsValid(), "Coins denoms contain upper case characters")
Expand All @@ -298,6 +302,7 @@ func TestCoins(t *testing.T) {
assert.False(t, badSort2.IsValid(), "Coins are not sorted")
assert.False(t, badAmt.IsValid(), "Coins cannot include 0 amounts")
assert.False(t, dup.IsValid(), "Duplicate coin")
assert.False(t, neg.IsValid(), "Negative first-denom coin")
}

func TestCoinsGT(t *testing.T) {
Expand Down