From 2f7875dec03201de8121dd93c225078f282015ab Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 31 Jan 2017 12:24:49 +0100 Subject: [PATCH] Fixed Coins IsValid, issue #8 --- types/coin.go | 2 ++ types/coin_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/types/coin.go b/types/coin.go index 94e38b7011..23dc8f0868 100644 --- a/types/coin.go +++ b/types/coin.go @@ -35,6 +35,8 @@ func (coins Coins) IsValid() bool { if coin.Amount == 0 { return false } + // we compare each coin against the last denom + lowDenom = coin.Denom } return true } diff --git a/types/coin_test.go b/types/coin_test.go index 00a07a6f36..158f159c50 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -42,6 +42,19 @@ func TestCoinsBadSort(t *testing.T) { } } +func TestCoinsBadSort2(t *testing.T) { + // both are after the first one, but the second and third are in the wrong order + coins := Coins{ + Coin{"GAS", 1}, + Coin{"TREE", 1}, + Coin{"MINERAL", 1}, + } + + if coins.IsValid() { + t.Fatal("Coins are not sorted") + } +} + func TestCoinsBadAmount(t *testing.T) { coins := Coins{ Coin{"GAS", 1},