Skip to content

Commit

Permalink
add string test for coin and coins (cosmos#6547)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
jgimeno and alexanderbez committed Jun 30, 2020
1 parent 497b273 commit c44ca8a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
github.com/tendermint/iavl v0.14.0-rc1
github.com/tendermint/tendermint v0.33.5
github.com/tendermint/tm-db v0.5.1
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
google.golang.org/grpc v1.30.0
gopkg.in/yaml.v2 v2.3.0
)
Expand Down
43 changes: 43 additions & 0 deletions types/coin_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"strings"
"testing"

Expand All @@ -27,6 +28,11 @@ func TestCoin(t *testing.T) {
require.Equal(t, NewInt(5), NewCoin(testDenom1, NewInt(5)).Amount)
}

func TestCoin_String(t *testing.T) {
coin := NewCoin(testDenom1, NewInt(10))
require.Equal(t, fmt.Sprintf("10%s", testDenom1), coin.String())
}

func TestIsEqualCoin(t *testing.T) {
cases := []struct {
inputOne Coin
Expand Down Expand Up @@ -188,6 +194,43 @@ func TestCoinIsZero(t *testing.T) {
// ----------------------------------------------------------------------------
// Coins tests

func TestCoins_String(t *testing.T) {
cases := []struct {
name string
input Coins
expected string
}{
{
name: "empty coins",
input: Coins{},
expected: "",
},
{
name: "single coin",
input: Coins{
{"tree", NewInt(1)},
},
expected: "1tree",
},
{
name: "multiple coins",
input: Coins{
{"tree", NewInt(1)},
{"gas", NewInt(1)},
{"mineral", NewInt(1)},
},
expected: "1tree,1gas,1mineral",
},
}

for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.expected, tt.input.String())
})
}
}

func TestIsZeroCoins(t *testing.T) {
cases := []struct {
inputOne Coins
Expand Down

0 comments on commit c44ca8a

Please sign in to comment.