Skip to content

Commit

Permalink
Merge PR #3207: Fix token printing bug
Browse files Browse the repository at this point in the history
* Add IsPositive, case check on coins[0]
* Link to correct PR
* Add testcase
  • Loading branch information
cwgoes committed Jan 2, 2019
1 parent 2b3842c commit 4a65bda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.29.1

BUG FIXES

* 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](https://github.com/cosmos/cosmos-sdk/issues/3207) - Fix token printing bug

## 0.29.0

BREAKING CHANGES
Expand Down
7 changes: 6 additions & 1 deletion types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,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 coin.Denom <= lowDenom {
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 @@ -281,6 +281,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.True(t, good.IsPositive(), "Expected coins to be positive: %v", good)
Expand All @@ -292,6 +296,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

0 comments on commit 4a65bda

Please sign in to comment.