@@ -18,10 +18,9 @@ import (
1818
1919func TestDeductCoins (t * testing.T ) {
2020 tests := []struct {
21- name string
22- coins sdk.Coins
23- wantErr bool
24- invalidCoin bool
21+ name string
22+ coins sdk.Coins
23+ wantErr bool
2524 }{
2625 {
2726 name : "valid" ,
@@ -34,25 +33,16 @@ func TestDeductCoins(t *testing.T) {
3433 wantErr : false ,
3534 },
3635 {
37- name : "invalid coins negative amount" ,
38- coins : sdk.Coins {sdk.Coin {Denom : "test" , Amount : math .NewInt (- 1 )}},
39- wantErr : true ,
40- invalidCoin : true ,
41- },
42- {
43- name : "invalid coins invalid denom" ,
44- coins : sdk.Coins {sdk.Coin {Amount : math .NewInt (1 )}},
45- wantErr : true ,
46- invalidCoin : true ,
36+ name : "valid zero coin" ,
37+ coins : sdk .NewCoins (sdk .NewCoin ("test" , math .ZeroInt ())),
38+ wantErr : false ,
4739 },
4840 }
4941 for _ , tc := range tests {
5042 t .Run (fmt .Sprintf ("Case %s" , tc .name ), func (t * testing.T ) {
5143 s := antesuite .SetupTestSuite (t , true )
5244 acc := s .CreateTestAccounts (1 )[0 ]
53- if ! tc .invalidCoin {
54- s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , s .Ctx , acc .Account .GetAddress (), types .FeeCollectorName , tc .coins ).Return (nil ).Once ()
55- }
45+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , s .Ctx , acc .Account .GetAddress (), types .FeeCollectorName , tc .coins ).Return (nil ).Once ()
5646
5747 if err := post .DeductCoins (s .MockBankKeeper , s .Ctx , acc .Account , tc .coins , false ); (err != nil ) != tc .wantErr {
5848 s .Errorf (err , "DeductCoins() error = %v, wantErr %v" , err , tc .wantErr )
@@ -63,10 +53,9 @@ func TestDeductCoins(t *testing.T) {
6353
6454func TestDeductCoinsAndDistribute (t * testing.T ) {
6555 tests := []struct {
66- name string
67- coins sdk.Coins
68- wantErr bool
69- invalidCoin bool
56+ name string
57+ coins sdk.Coins
58+ wantErr bool
7059 }{
7160 {
7261 name : "valid" ,
@@ -79,25 +68,16 @@ func TestDeductCoinsAndDistribute(t *testing.T) {
7968 wantErr : false ,
8069 },
8170 {
82- name : "invalid coins negative amount" ,
83- coins : sdk.Coins {sdk.Coin {Denom : "test" , Amount : math .NewInt (- 1 )}},
84- wantErr : true ,
85- invalidCoin : true ,
86- },
87- {
88- name : "invalid coins invalid denom" ,
89- coins : sdk.Coins {sdk.Coin {Amount : math .NewInt (1 )}},
90- wantErr : true ,
91- invalidCoin : true ,
71+ name : "valid zero coin" ,
72+ coins : sdk .NewCoins (sdk .NewCoin ("test" , math .ZeroInt ())),
73+ wantErr : false ,
9274 },
9375 }
9476 for _ , tc := range tests {
9577 t .Run (fmt .Sprintf ("Case %s" , tc .name ), func (t * testing.T ) {
9678 s := antesuite .SetupTestSuite (t , true )
9779 acc := s .CreateTestAccounts (1 )[0 ]
98- if ! tc .invalidCoin {
99- s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , s .Ctx , acc .Account .GetAddress (), authtypes .FeeCollectorName , tc .coins ).Return (nil ).Once ()
100- }
80+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , s .Ctx , acc .Account .GetAddress (), authtypes .FeeCollectorName , tc .coins ).Return (nil ).Once ()
10181
10282 if err := post .DeductCoins (s .MockBankKeeper , s .Ctx , acc .Account , tc .coins , true ); (err != nil ) != tc .wantErr {
10383 s .Errorf (err , "DeductCoins() error = %v, wantErr %v" , err , tc .wantErr )
@@ -108,10 +88,9 @@ func TestDeductCoinsAndDistribute(t *testing.T) {
10888
10989func TestSendTip (t * testing.T ) {
11090 tests := []struct {
111- name string
112- coins sdk.Coins
113- wantErr bool
114- invalidCoin bool
91+ name string
92+ coins sdk.Coins
93+ wantErr bool
11594 }{
11695 {
11796 name : "valid" ,
@@ -124,19 +103,16 @@ func TestSendTip(t *testing.T) {
124103 wantErr : false ,
125104 },
126105 {
127- name : "invalid coins" ,
128- coins : sdk.Coins {sdk.Coin {Amount : math .NewInt (- 1 )}},
129- wantErr : true ,
130- invalidCoin : true ,
106+ name : "valid zero coin" ,
107+ coins : sdk .NewCoins (sdk .NewCoin ("test" , math .ZeroInt ())),
108+ wantErr : false ,
131109 },
132110 }
133111 for _ , tc := range tests {
134112 t .Run (fmt .Sprintf ("Case %s" , tc .name ), func (t * testing.T ) {
135113 s := antesuite .SetupTestSuite (t , true )
136114 accs := s .CreateTestAccounts (2 )
137- if ! tc .invalidCoin {
138- s .MockBankKeeper .On ("SendCoins" , s .Ctx , mock .Anything , mock .Anything , tc .coins ).Return (nil ).Once ()
139- }
115+ s .MockBankKeeper .On ("SendCoins" , s .Ctx , mock .Anything , mock .Anything , tc .coins ).Return (nil ).Once ()
140116
141117 if err := post .SendTip (s .MockBankKeeper , s .Ctx , accs [0 ].Account .GetAddress (), accs [1 ].Account .GetAddress (), tc .coins ); (err != nil ) != tc .wantErr {
142118 s .Errorf (err , "SendTip() error = %v, wantErr %v" , err , tc .wantErr )
@@ -180,10 +156,28 @@ func TestPostHandle(t *testing.T) {
180156 ExpPass : false ,
181157 ExpErr : sdkerrors .ErrInsufficientFunds ,
182158 },
159+ {
160+ Name : "signer has no funds - simulate" ,
161+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
162+ accs := s .CreateTestAccounts (1 )
163+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (sdkerrors .ErrInsufficientFunds )
164+
165+ return antesuite.TestCaseArgs {
166+ Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
167+ GasLimit : gasLimit ,
168+ FeeAmount : validFee ,
169+ }
170+ },
171+ RunAnte : true ,
172+ RunPost : true ,
173+ Simulate : true ,
174+ ExpPass : false ,
175+ ExpErr : sdkerrors .ErrInsufficientFunds ,
176+ },
183177 {
184178 Name : "0 gas given should fail" ,
185- Malleate : func (suite * antesuite.TestSuite ) antesuite.TestCaseArgs {
186- accs := suite .CreateTestAccounts (1 )
179+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
180+ accs := s .CreateTestAccounts (1 )
187181
188182 return antesuite.TestCaseArgs {
189183 Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
@@ -197,11 +191,31 @@ func TestPostHandle(t *testing.T) {
197191 ExpPass : false ,
198192 ExpErr : sdkerrors .ErrInvalidGasLimit ,
199193 },
194+ {
195+ Name : "0 gas given should pass - simulate" ,
196+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
197+ accs := s .CreateTestAccounts (1 )
198+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
199+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
200+
201+ return antesuite.TestCaseArgs {
202+ Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
203+ GasLimit : 0 ,
204+ FeeAmount : validFee ,
205+ }
206+ },
207+ RunAnte : true ,
208+ RunPost : true ,
209+ Simulate : true ,
210+ ExpPass : true ,
211+ ExpErr : nil ,
212+ },
200213 {
201214 Name : "signer has enough funds, should pass, no tip" ,
202215 Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
203216 accs := s .CreateTestAccounts (1 )
204217 s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
218+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
205219
206220 return antesuite.TestCaseArgs {
207221 Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
@@ -234,11 +248,31 @@ func TestPostHandle(t *testing.T) {
234248 ExpPass : true ,
235249 ExpErr : nil ,
236250 },
251+ {
252+ Name : "signer has enough funds, should pass with tip - simulate" ,
253+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
254+ accs := s .CreateTestAccounts (1 )
255+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
256+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
257+
258+ return antesuite.TestCaseArgs {
259+ Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
260+ GasLimit : gasLimit ,
261+ FeeAmount : validFeeWithTip ,
262+ }
263+ },
264+ RunAnte : true ,
265+ RunPost : true ,
266+ Simulate : true ,
267+ ExpPass : true ,
268+ ExpErr : nil ,
269+ },
237270 {
238271 Name : "signer has enough funds, should pass, no tip - resolvable denom" ,
239272 Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
240273 accs := s .CreateTestAccounts (1 )
241274 s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
275+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
242276
243277 return antesuite.TestCaseArgs {
244278 Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
@@ -252,6 +286,25 @@ func TestPostHandle(t *testing.T) {
252286 ExpPass : true ,
253287 ExpErr : nil ,
254288 },
289+ {
290+ Name : "signer has enough funds, should pass, no tip - resolvable denom - simulate" ,
291+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
292+ accs := s .CreateTestAccounts (1 )
293+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
294+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
295+
296+ return antesuite.TestCaseArgs {
297+ Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
298+ GasLimit : gasLimit ,
299+ FeeAmount : validResolvableFee ,
300+ }
301+ },
302+ RunAnte : true ,
303+ RunPost : true ,
304+ Simulate : true ,
305+ ExpPass : true ,
306+ ExpErr : nil ,
307+ },
255308 {
256309 Name : "signer has enough funds, should pass with tip - resolvable denom" ,
257310 Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
@@ -271,6 +324,25 @@ func TestPostHandle(t *testing.T) {
271324 ExpPass : true ,
272325 ExpErr : nil ,
273326 },
327+ {
328+ Name : "signer has enough funds, should pass with tip - resolvable denom - simulate" ,
329+ Malleate : func (s * antesuite.TestSuite ) antesuite.TestCaseArgs {
330+ accs := s .CreateTestAccounts (1 )
331+ s .MockBankKeeper .On ("SendCoinsFromAccountToModule" , mock .Anything , accs [0 ].Account .GetAddress (), types .FeeCollectorName , mock .Anything ).Return (nil )
332+ s .MockBankKeeper .On ("SendCoins" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Once ()
333+
334+ return antesuite.TestCaseArgs {
335+ Msgs : []sdk.Msg {testdata .NewTestMsg (accs [0 ].Account .GetAddress ())},
336+ GasLimit : gasLimit ,
337+ FeeAmount : validResolvableFeeWithTip ,
338+ }
339+ },
340+ RunAnte : true ,
341+ RunPost : true ,
342+ Simulate : true ,
343+ ExpPass : true ,
344+ ExpErr : nil ,
345+ },
274346 }
275347
276348 for _ , tc := range testCases {
0 commit comments