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
3 changed files with 12 additions and 1 deletions
+6 -1
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
+5
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) {