@@ -3,25 +3,28 @@ package keeper_test
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/golang/mock/gomock"
7
+ "github.com/stretchr/testify/suite"
8
+
6
9
"github.com/cosmos/cosmos-sdk/testutil"
7
10
sdk "github.com/cosmos/cosmos-sdk/types"
8
11
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
9
12
"github.com/cosmos/cosmos-sdk/x/crisis"
10
13
"github.com/cosmos/cosmos-sdk/x/crisis/keeper"
11
14
crisistestutil "github.com/cosmos/cosmos-sdk/x/crisis/testutil"
12
15
"github.com/cosmos/cosmos-sdk/x/crisis/types"
13
- "github.com/golang/mock/gomock"
14
- "github.com/stretchr/testify/suite"
15
16
)
16
17
17
18
type KeeperTestSuite struct {
18
19
suite.Suite
19
20
20
- ctx sdk.Context
21
- keeper * keeper.Keeper
21
+ ctx sdk.Context
22
+ authKeeper * crisistestutil.MockSupplyKeeper
23
+ keeper * keeper.Keeper
22
24
}
23
25
24
26
func (s * KeeperTestSuite ) SetupTest () {
27
+ // gomock initializations
25
28
ctrl := gomock .NewController (s .T ())
26
29
supplyKeeper := crisistestutil .NewMockSupplyKeeper (ctrl )
27
30
@@ -32,6 +35,79 @@ func (s *KeeperTestSuite) SetupTest() {
32
35
33
36
s .ctx = testCtx .Ctx
34
37
s .keeper = keeper
38
+ s .authKeeper = supplyKeeper
39
+ }
40
+
41
+ func (s * KeeperTestSuite ) TestMsgVerifyInvariant () {
42
+ // default params
43
+ constantFee := sdk .NewCoin (sdk .DefaultBondDenom , sdk .NewInt (1000 ))
44
+ err := s .keeper .SetConstantFee (s .ctx , constantFee )
45
+ s .Require ().NoError (err )
46
+
47
+ sender := sdk .AccAddress ([]byte ("addr1_______________" ))
48
+
49
+ s .authKeeper .EXPECT ().SendCoinsFromAccountToModule (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).Times (2 )
50
+ s .keeper .RegisterRoute ("bank" , "total-supply" , func (sdk.Context ) (string , bool ) { return "" , false })
51
+
52
+ testCases := []struct {
53
+ name string
54
+ input * types.MsgVerifyInvariant
55
+ expErr bool
56
+ expErrMsg string
57
+ }{
58
+ {
59
+ name : "empty sender not allowed" ,
60
+ input : & types.MsgVerifyInvariant {
61
+ Sender : "" ,
62
+ InvariantModuleName : "bank" ,
63
+ InvariantRoute : "total-supply" ,
64
+ },
65
+ expErr : true ,
66
+ expErrMsg : "empty address string is not allowed" ,
67
+ },
68
+ {
69
+ name : "invalid sender address" ,
70
+ input : & types.MsgVerifyInvariant {
71
+ Sender : "invalid address" ,
72
+ InvariantModuleName : "bank" ,
73
+ InvariantRoute : "total-supply" ,
74
+ },
75
+ expErr : true ,
76
+ expErrMsg : "decoding bech32 failed" ,
77
+ },
78
+ {
79
+ name : "unregistered invariant route" ,
80
+ input : & types.MsgVerifyInvariant {
81
+ Sender : sender .String (),
82
+ InvariantModuleName : "module" ,
83
+ InvariantRoute : "invalidroute" ,
84
+ },
85
+ expErr : true ,
86
+ expErrMsg : "unknown invariant" ,
87
+ },
88
+ {
89
+ name : "valid invariant" ,
90
+ input : & types.MsgVerifyInvariant {
91
+ Sender : sender .String (),
92
+ InvariantModuleName : "bank" ,
93
+ InvariantRoute : "total-supply" ,
94
+ },
95
+ expErr : false ,
96
+ },
97
+ }
98
+
99
+ for _ , tc := range testCases {
100
+ tc := tc
101
+ s .Run (tc .name , func () {
102
+ _ , err = s .keeper .VerifyInvariant (s .ctx , tc .input )
103
+ if tc .expErr {
104
+ s .Require ().Error (err )
105
+ s .Require ().Contains (err .Error (), tc .expErrMsg )
106
+ } else {
107
+ s .Require ().NoError (err )
108
+ }
109
+ })
110
+ }
35
111
}
36
112
37
113
func (s * KeeperTestSuite ) TestMsgUpdateParams () {
0 commit comments