add string test for coin and coins (#6547)
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
497b27305d
commit
c44ca8ae34
1
go.mod
1
go.mod
|
@ -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
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue