Merge PR #3207: Fix token printing bug

* Add IsPositive, case check on coins[0]
* Link to correct PR
* Add testcase
This commit is contained in:
Christopher Goes 2019-01-02 19:17:27 +01:00
parent 2b3842c583
commit 4a65bda1f5
3 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
@ -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) {