1
- package types
1
+ package types_test
2
2
3
3
import (
4
4
"testing"
5
5
6
6
"github.com/stretchr/testify/require"
7
7
8
8
sdk "github.com/cosmos/cosmos-sdk/types"
9
+ bank "github.com/cosmos/cosmos-sdk/x/bank/types"
9
10
)
10
11
11
12
func TestBalanceValidate (t * testing.T ) {
12
-
13
13
testCases := []struct {
14
14
name string
15
- balance Balance
15
+ balance bank. Balance
16
16
expErr bool
17
17
}{
18
18
{
19
19
"valid balance" ,
20
- Balance {
20
+ bank. Balance {
21
21
Address : "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t" ,
22
22
Coins : sdk.Coins {sdk .NewInt64Coin ("uatom" , 1 )},
23
23
},
24
24
false ,
25
25
},
26
- {"empty balance" , Balance {}, true },
26
+ {"empty balance" , bank. Balance {}, true },
27
27
{
28
28
"nil balance coins" ,
29
- Balance {
29
+ bank. Balance {
30
30
Address : "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t" ,
31
31
},
32
32
true ,
33
33
},
34
34
{
35
35
"dup coins" ,
36
- Balance {
36
+ bank. Balance {
37
37
Address : "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t" ,
38
38
Coins : sdk.Coins {
39
39
sdk .NewInt64Coin ("uatom" , 1 ),
@@ -44,7 +44,7 @@ func TestBalanceValidate(t *testing.T) {
44
44
},
45
45
{
46
46
"invalid coin denom" ,
47
- Balance {
47
+ bank. Balance {
48
48
Address : "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t" ,
49
49
Coins : sdk.Coins {
50
50
sdk.Coin {Denom : "" , Amount : sdk .OneInt ()},
@@ -54,7 +54,7 @@ func TestBalanceValidate(t *testing.T) {
54
54
},
55
55
{
56
56
"negative coin" ,
57
- Balance {
57
+ bank. Balance {
58
58
Address : "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t" ,
59
59
Coins : sdk.Coins {
60
60
sdk.Coin {Denom : "uatom" , Amount : sdk .NewInt (- 1 )},
@@ -78,3 +78,26 @@ func TestBalanceValidate(t *testing.T) {
78
78
})
79
79
}
80
80
}
81
+
82
+ func TestBalance_GetAddress (t * testing.T ) {
83
+ tests := []struct {
84
+ name string
85
+ Address string
86
+ wantPanic bool
87
+ }{
88
+ {"empty address" , "" , true },
89
+ {"malformed address" , "invalid" , true },
90
+ {"valid address" , "cosmos1vy0ga0klndqy92ceqehfkvgmn4t94eteq4hmqv" , false },
91
+ }
92
+ for _ , tt := range tests {
93
+ tt := tt
94
+ t .Run (tt .name , func (t * testing.T ) {
95
+ b := bank.Balance {Address : tt .Address }
96
+ if tt .wantPanic {
97
+ require .Panics (t , func () { b .GetAddress () })
98
+ } else {
99
+ require .False (t , b .GetAddress ().Empty ())
100
+ }
101
+ })
102
+ }
103
+ }
0 commit comments