Skip to content

Commit d316097

Browse files
committed
feat: added a validation for gas_fee_used if success is true
1 parent 96d64ac commit d316097

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

test/integration/uexecutor/gas_fee_refund_test.go

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,28 @@ import (
1313

1414
func TestGasFeeRefund(t *testing.T) {
1515

16-
t.Run("no refund when gasFeeUsed is empty", func(t *testing.T) {
16+
t.Run("success vote with empty gasFeeUsed is rejected", func(t *testing.T) {
1717
app, ctx, vals, utxId, outbound, coreVals :=
1818
setupOutboundVotingTest(t, 4)
1919

20-
for i := 0; i < 3; i++ {
21-
valAddr, err := sdk.ValAddressFromBech32(coreVals[i].OperatorAddress)
22-
require.NoError(t, err)
23-
coreAcc := sdk.AccAddress(valAddr).String()
24-
25-
err = utils.ExecVoteOutbound(
26-
t,
27-
ctx,
28-
app,
29-
vals[i],
30-
coreAcc,
31-
utxId,
32-
outbound,
33-
true,
34-
"",
35-
"", // gasFeeUsed empty → no refund
36-
)
37-
require.NoError(t, err)
38-
}
39-
40-
utx, _, err := app.UexecutorKeeper.GetUniversalTx(ctx, utxId)
20+
valAddr, err := sdk.ValAddressFromBech32(coreVals[0].OperatorAddress)
4121
require.NoError(t, err)
42-
43-
ob := utx.OutboundTx[0]
44-
require.Equal(t, uexecutortypes.Status_OBSERVED, ob.OutboundStatus)
45-
require.True(t, ob.ObservedTx.Success)
46-
// No refund should be triggered
47-
require.Nil(t, ob.PcRefundExecution, "no refund expected when gasFeeUsed is empty")
48-
require.Empty(t, ob.RefundSwapError)
22+
coreAcc := sdk.AccAddress(valAddr).String()
23+
24+
err = utils.ExecVoteOutbound(
25+
t,
26+
ctx,
27+
app,
28+
vals[0],
29+
coreAcc,
30+
utxId,
31+
outbound,
32+
true,
33+
"",
34+
"", // gas_fee_used required when success=true → must be rejected
35+
)
36+
require.Error(t, err)
37+
require.Contains(t, err.Error(), "gas_fee_used required when success=true")
4938
})
5039

5140
t.Run("no refund when gasFeeUsed equals gasFee", func(t *testing.T) {

test/integration/uexecutor/vote_outbound_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestOutboundVoting(t *testing.T) {
9494
outbound,
9595
true,
9696
"",
97-
"",
97+
outbound.GasFee,
9898
)
9999
require.NoError(t, err)
100100

@@ -126,7 +126,7 @@ func TestOutboundVoting(t *testing.T) {
126126
outbound,
127127
true,
128128
"",
129-
"",
129+
outbound.GasFee,
130130
)
131131
require.NoError(t, err)
132132
}
@@ -157,7 +157,7 @@ func TestOutboundVoting(t *testing.T) {
157157
outbound,
158158
true,
159159
"",
160-
"",
160+
outbound.GasFee,
161161
)
162162
require.NoError(t, err)
163163

@@ -171,7 +171,7 @@ func TestOutboundVoting(t *testing.T) {
171171
outbound,
172172
true,
173173
"",
174-
"",
174+
outbound.GasFee,
175175
)
176176
require.Error(t, err)
177177
require.Contains(t, err.Error(), "already voted")
@@ -196,7 +196,7 @@ func TestOutboundVoting(t *testing.T) {
196196
outbound,
197197
true,
198198
"",
199-
"",
199+
outbound.GasFee,
200200
)
201201
require.NoError(t, err)
202202
}
@@ -215,7 +215,7 @@ func TestOutboundVoting(t *testing.T) {
215215
outbound,
216216
true,
217217
"",
218-
"",
218+
outbound.GasFee,
219219
)
220220
require.Error(t, err)
221221
require.Contains(t, err.Error(), "already finalized")
@@ -320,7 +320,7 @@ func TestOutboundVoting(t *testing.T) {
320320
&prefixedOutbound,
321321
true,
322322
"",
323-
"",
323+
outbound.GasFee,
324324
)
325325
require.NoError(t, err)
326326
}
@@ -351,7 +351,7 @@ func TestOutboundVoting(t *testing.T) {
351351
outbound,
352352
true,
353353
"",
354-
"",
354+
outbound.GasFee,
355355
)
356356
require.Error(t, err)
357357
require.Contains(t, err.Error(), "not found")
@@ -377,7 +377,7 @@ func TestOutboundVoting(t *testing.T) {
377377
&badOutbound,
378378
true,
379379
"",
380-
"",
380+
outbound.GasFee,
381381
)
382382
require.Error(t, err)
383383
require.Contains(t, err.Error(), "not found")

x/uexecutor/types/msg_vote_outbound.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (msg *MsgVoteOutbound) ValidateBasic() error {
6969
obs := msg.ObservedTx
7070

7171
if obs.Success {
72-
// Success requires tx_hash AND block_height > 0
72+
// Success requires tx_hash AND block_height > 0 AND gas_fee_used
7373
if strings.TrimSpace(obs.TxHash) == "" {
7474
return errors.Wrap(sdkerrors.ErrInvalidRequest,
7575
"observed_tx.tx_hash required when success=true")
@@ -78,6 +78,10 @@ func (msg *MsgVoteOutbound) ValidateBasic() error {
7878
return errors.Wrap(sdkerrors.ErrInvalidRequest,
7979
"observed_tx.block_height must be > 0 when success=true")
8080
}
81+
if strings.TrimSpace(obs.GasFeeUsed) == "" {
82+
return errors.Wrap(sdkerrors.ErrInvalidRequest,
83+
"observed_tx.gas_fee_used required when success=true")
84+
}
8185

8286
} else {
8387
// Failure case:

0 commit comments

Comments
 (0)