Fix is_valid bug (#3211)
This commit is contained in:
parent
5ca8c5bb83
commit
67a1e47c6e
|
@ -142,12 +142,13 @@ func (coins Coins) IsValid() bool {
|
||||||
case 0:
|
case 0:
|
||||||
return true
|
return true
|
||||||
case 1:
|
case 1:
|
||||||
return coins[0].IsPositive()
|
|
||||||
default:
|
|
||||||
if strings.ToLower(coins[0].Denom) != coins[0].Denom {
|
if strings.ToLower(coins[0].Denom) != coins[0].Denom {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !coins[0].IsPositive() {
|
return coins[0].IsPositive()
|
||||||
|
default:
|
||||||
|
// Check single coin case
|
||||||
|
if !(Coins{coins[0]}).IsValid() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
lowDenom := coins[0].Denom
|
lowDenom := coins[0].Denom
|
||||||
|
|
|
@ -255,11 +255,18 @@ func TestCoins(t *testing.T) {
|
||||||
{"mineral", NewInt(1)},
|
{"mineral", NewInt(1)},
|
||||||
{"tree", NewInt(1)},
|
{"tree", NewInt(1)},
|
||||||
}
|
}
|
||||||
mixedCase := Coins{
|
mixedCase1 := Coins{
|
||||||
{"gAs", NewInt(1)},
|
{"gAs", NewInt(1)},
|
||||||
{"MineraL", NewInt(1)},
|
{"MineraL", NewInt(1)},
|
||||||
{"TREE", NewInt(1)},
|
{"TREE", NewInt(1)},
|
||||||
}
|
}
|
||||||
|
mixedCase2 := Coins{
|
||||||
|
{"gAs", NewInt(1)},
|
||||||
|
{"mineral", NewInt(1)},
|
||||||
|
}
|
||||||
|
mixedCase3 := Coins{
|
||||||
|
{"gAs", NewInt(1)},
|
||||||
|
}
|
||||||
empty := Coins{
|
empty := Coins{
|
||||||
{"gold", NewInt(0)},
|
{"gold", NewInt(0)},
|
||||||
}
|
}
|
||||||
|
@ -292,7 +299,9 @@ func TestCoins(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, good.IsValid(), "Coins are valid")
|
assert.True(t, good.IsValid(), "Coins are valid")
|
||||||
assert.False(t, mixedCase.IsValid(), "Coins denoms contain upper case characters")
|
assert.False(t, mixedCase1.IsValid(), "Coins denoms contain upper case characters")
|
||||||
|
assert.False(t, mixedCase2.IsValid(), "First Coins denoms contain upper case characters")
|
||||||
|
assert.False(t, mixedCase3.IsValid(), "Single denom in Coins contains upper case characters")
|
||||||
assert.True(t, good.IsPositive(), "Expected coins to be positive: %v", good)
|
assert.True(t, good.IsPositive(), "Expected coins to be positive: %v", good)
|
||||||
assert.False(t, null.IsPositive(), "Expected coins to not be positive: %v", null)
|
assert.False(t, null.IsPositive(), "Expected coins to not be positive: %v", null)
|
||||||
assert.True(t, good.IsAllGTE(empty), "Expected %v to be >= %v", good, empty)
|
assert.True(t, good.IsAllGTE(empty), "Expected %v to be >= %v", good, empty)
|
||||||
|
|
Loading…
Reference in New Issue