From 4a65bda1f5c8e8e89405e1aa49707d20ba1108c6 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Wed, 2 Jan 2019 19:17:27 +0100 Subject: [PATCH] Merge PR #3207: Fix token printing bug * Add IsPositive, case check on coins[0] * Link to correct PR * Add testcase --- CHANGELOG.md | 8 ++++++++ types/coin.go | 7 ++++++- types/coin_test.go | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b37dca1c9b..7292702c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/types/coin.go b/types/coin.go index 9742545324..e569674026 100644 --- a/types/coin.go +++ b/types/coin.go @@ -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 diff --git a/types/coin_test.go b/types/coin_test.go index 774534860d..92036adfca 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -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) {