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 committed by GitHub
parent 0d63c92be1
commit 5ca8c5bb83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

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

View File

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

View File

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