@@ -35,6 +35,11 @@ func (m *protoFeeMockFeeTx) FeeGranter() []byte { return nil
3535// protoFeeMockBankKeeper implements feeaddress.ProtocolFeeBankKeeper for testing.
3636type protoFeeMockBankKeeper struct {
3737 sentToModule map [string ]sdk.Coins
38+ balance sdk.Coin // balance to return from GetBalance
39+ }
40+
41+ func (m * protoFeeMockBankKeeper ) GetBalance (_ context.Context , _ sdk.AccAddress , _ string ) sdk.Coin {
42+ return m .balance
3843}
3944
4045func (m * protoFeeMockBankKeeper ) SendCoinsFromAccountToModule (_ context.Context , _ sdk.AccAddress , recipientModule string , amt sdk.Coins ) error {
@@ -56,7 +61,12 @@ func (m *protoFeeMockNonFeeTx) ValidateBasic() error { return n
5661
5762// protoFeeMockBankKeeperWithError implements feeaddress.ProtocolFeeBankKeeper and returns an error.
5863type protoFeeMockBankKeeperWithError struct {
59- err error
64+ err error
65+ balance sdk.Coin
66+ }
67+
68+ func (m * protoFeeMockBankKeeperWithError ) GetBalance (_ context.Context , _ sdk.AccAddress , _ string ) sdk.Coin {
69+ return m .balance
6070}
6171
6272func (m * protoFeeMockBankKeeperWithError ) SendCoinsFromAccountToModule (_ context.Context , _ sdk.AccAddress , _ string , _ sdk.Coins ) error {
@@ -68,12 +78,13 @@ func protoFeeNextAnteHandler(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, er
6878}
6979
7080func TestProtocolFeeTerminatorRejectsUserSubmittedTx (t * testing.T ) {
71- bankKeeper := & protoFeeMockBankKeeper {}
81+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
82+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
7283 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
7384
7485 msg := feeaddress .NewMsgPayProtocolFee ()
75- fee := sdk .NewCoins (sdk . NewCoin ( appconsts . BondDenom , math . NewInt ( 1000 )) )
76- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
86+ fee := sdk .NewCoins (balance )
87+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
7788
7889 // Create CheckTx context - this simulates a user submitting the tx
7990 ctx := sdk .NewContext (nil , tmproto.Header {}, true , log .NewNopLogger ()) // isCheckTx = true
@@ -85,12 +96,13 @@ func TestProtocolFeeTerminatorRejectsUserSubmittedTx(t *testing.T) {
8596}
8697
8798func TestProtocolFeeTerminatorRejectsReCheckTx (t * testing.T ) {
88- bankKeeper := & protoFeeMockBankKeeper {}
99+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
100+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
89101 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
90102
91103 msg := feeaddress .NewMsgPayProtocolFee ()
92- fee := sdk .NewCoins (sdk . NewCoin ( appconsts . BondDenom , math . NewInt ( 1000 )) )
93- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
104+ fee := sdk .NewCoins (balance )
105+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
94106
95107 // Create ReCheckTx context
96108 ctx := sdk .NewContext (nil , tmproto.Header {}, true , log .NewNopLogger ()).WithIsReCheckTx (true )
@@ -102,7 +114,8 @@ func TestProtocolFeeTerminatorRejectsReCheckTx(t *testing.T) {
102114}
103115
104116func TestProtocolFeeTerminatorValidatesSingleDenom (t * testing.T ) {
105- bankKeeper := & protoFeeMockBankKeeper {}
117+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
118+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
106119 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
107120
108121 msg := feeaddress .NewMsgPayProtocolFee ()
@@ -111,7 +124,7 @@ func TestProtocolFeeTerminatorValidatesSingleDenom(t *testing.T) {
111124 sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 )),
112125 sdk .NewCoin ("otherdenom" , math .NewInt (500 )),
113126 )
114- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
127+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
115128
116129 // Create DeliverTx context (not CheckTx)
117130 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -123,13 +136,14 @@ func TestProtocolFeeTerminatorValidatesSingleDenom(t *testing.T) {
123136}
124137
125138func TestProtocolFeeTerminatorRejectsWrongDenom (t * testing.T ) {
126- bankKeeper := & protoFeeMockBankKeeper {}
139+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
140+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
127141 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
128142
129143 msg := feeaddress .NewMsgPayProtocolFee ()
130144 // Wrong denom - should be rejected
131145 fee := sdk .NewCoins (sdk .NewCoin ("wrongdenom" , math .NewInt (1000 )))
132- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
146+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
133147
134148 // Create DeliverTx context (not CheckTx)
135149 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -141,12 +155,13 @@ func TestProtocolFeeTerminatorRejectsWrongDenom(t *testing.T) {
141155}
142156
143157func TestProtocolFeeTerminatorSuccess (t * testing.T ) {
144- bankKeeper := & protoFeeMockBankKeeper {}
158+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
159+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
145160 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
146161
147162 msg := feeaddress .NewMsgPayProtocolFee ()
148- fee := sdk .NewCoins (sdk . NewCoin ( appconsts . BondDenom , math . NewInt ( 1000 )) )
149- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
163+ fee := sdk .NewCoins (balance )
164+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
150165
151166 // Create DeliverTx context (not CheckTx)
152167 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -159,12 +174,13 @@ func TestProtocolFeeTerminatorSuccess(t *testing.T) {
159174}
160175
161176func TestProtocolFeeTerminatorRejectsSimulation (t * testing.T ) {
162- bankKeeper := & protoFeeMockBankKeeper {}
177+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
178+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
163179 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
164180
165181 msg := feeaddress .NewMsgPayProtocolFee ()
166- fee := sdk .NewCoins (sdk . NewCoin ( appconsts . BondDenom , math . NewInt ( 1000 )) )
167- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
182+ fee := sdk .NewCoins (balance )
183+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
168184
169185 // Create DeliverTx context but pass simulate=true
170186 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -176,7 +192,8 @@ func TestProtocolFeeTerminatorRejectsSimulation(t *testing.T) {
176192}
177193
178194func TestProtocolFeeTerminatorRejectsNonFeeTx (t * testing.T ) {
179- bankKeeper := & protoFeeMockBankKeeper {}
195+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
196+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
180197 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
181198
182199 msg := feeaddress .NewMsgPayProtocolFee ()
@@ -192,12 +209,13 @@ func TestProtocolFeeTerminatorRejectsNonFeeTx(t *testing.T) {
192209}
193210
194211func TestProtocolFeeTerminatorBankTransferFailure (t * testing.T ) {
195- bankKeeper := & protoFeeMockBankKeeperWithError {err : sdkerrors .ErrInsufficientFunds }
212+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
213+ bankKeeper := & protoFeeMockBankKeeperWithError {err : sdkerrors .ErrInsufficientFunds , balance : balance }
196214 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
197215
198216 msg := feeaddress .NewMsgPayProtocolFee ()
199- fee := sdk .NewCoins (sdk . NewCoin ( appconsts . BondDenom , math . NewInt ( 1000 )) )
200- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : 50000 }
217+ fee := sdk .NewCoins (balance )
218+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress . ProtocolFeeGasLimit }
201219
202220 // Create DeliverTx context (not CheckTx)
203221 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -209,12 +227,13 @@ func TestProtocolFeeTerminatorBankTransferFailure(t *testing.T) {
209227}
210228
211229func TestProtocolFeeTerminatorZeroFeeRejected (t * testing.T ) {
212- bankKeeper := & protoFeeMockBankKeeper {}
230+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
231+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
213232 decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
214233
215234 msg := feeaddress .NewMsgPayProtocolFee ()
216235 // Zero fee should be rejected
217- tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : sdk.Coins {}, gas : 50000 }
236+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : sdk.Coins {}, gas : feeaddress . ProtocolFeeGasLimit }
218237
219238 // Create DeliverTx context (not CheckTx)
220239 ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
@@ -224,3 +243,42 @@ func TestProtocolFeeTerminatorZeroFeeRejected(t *testing.T) {
224243 require .Error (t , err )
225244 require .ErrorContains (t , err , "protocol fee tx requires exactly one fee coin" )
226245}
246+
247+ func TestProtocolFeeTerminatorRejectsFeeNotEqualToBalance (t * testing.T ) {
248+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
249+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
250+ decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
251+
252+ msg := feeaddress .NewMsgPayProtocolFee ()
253+ // Fee is less than balance - should be rejected
254+ fee := sdk .NewCoins (sdk .NewCoin (appconsts .BondDenom , math .NewInt (500 )))
255+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress .ProtocolFeeGasLimit }
256+
257+ // Create DeliverTx context (not CheckTx)
258+ ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
259+
260+ _ , err := decorator .AnteHandle (ctx , tx , false , protoFeeNextAnteHandler )
261+
262+ require .Error (t , err )
263+ require .ErrorContains (t , err , "does not equal expected fee" )
264+ }
265+
266+ func TestProtocolFeeTerminatorRejectsWrongGasLimit (t * testing.T ) {
267+ balance := sdk .NewCoin (appconsts .BondDenom , math .NewInt (1000 ))
268+ bankKeeper := & protoFeeMockBankKeeper {balance : balance }
269+ decorator := ante .NewProtocolFeeTerminatorDecorator (bankKeeper )
270+
271+ msg := feeaddress .NewMsgPayProtocolFee ()
272+ fee := sdk .NewCoins (balance )
273+ // Wrong gas limit - should be rejected
274+ tx := & protoFeeMockFeeTx {msgs : []sdk.Msg {msg }, fee : fee , gas : feeaddress .ProtocolFeeGasLimit * 2 }
275+
276+ // Create DeliverTx context (not CheckTx)
277+ ctx := sdk .NewContext (nil , tmproto.Header {}, false , log .NewNopLogger ())
278+
279+ _ , err := decorator .AnteHandle (ctx , tx , false , protoFeeNextAnteHandler )
280+
281+ require .Error (t , err )
282+ require .ErrorContains (t , err , "gas limit" )
283+ require .ErrorContains (t , err , "does not match expected" )
284+ }
0 commit comments