Skip to content

Commit eb457fc

Browse files
committed
chore: Require -gas-fee-margin to be a non-negative integer
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
1 parent 989cbc3 commit eb457fc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

gno.land/pkg/integration/testdata/simulate_gas.txtar

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ stdout 'gas fee: 111ugnot'
2424
gnokey maketx call -pkgpath gno.land/r/simulate -func Hello -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test -simulate only -gas-fee-margin=10 test1
2525
stdout 'gas fee: 122ugnot'
2626

27+
# -gas-fee-margin should be a number
28+
! gnokey maketx call -pkgpath gno.land/r/simulate -func Hello -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test -simulate only -gas-fee-margin=zzz test1
29+
stderr 'invalid value'
30+
31+
# -gas-fee-margin should be non-negative
32+
! gnokey maketx call -pkgpath gno.land/r/simulate -func Hello -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test -simulate only -gas-fee-margin=-10 test1
33+
stderr 'invalid value'
34+
2735
-- package/package.gno --
2836
package call_package
2937

tm2/pkg/crypto/keys/client/broadcast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type BroadcastCfg struct {
2828
// If true, simulation is attempted but not printed;
2929
// the result is only returned in case of an error.
3030
testSimulate bool
31-
GasFeeMargin int64
31+
GasFeeMargin uint64
3232
}
3333

3434
func NewBroadcastCmd(rootCfg *BaseCfg, io commands.IO) *commands.Command {
@@ -144,7 +144,7 @@ func BroadcastHandler(cfg *BroadcastCfg) (*ctypes.ResultBroadcastTxCommit, error
144144
return bres, nil
145145
}
146146

147-
func estimateGasFee(cli client.ABCIClient, bres *ctypes.ResultBroadcastTxCommit, gasFeeMargin int64) error {
147+
func estimateGasFee(cli client.ABCIClient, bres *ctypes.ResultBroadcastTxCommit, gasFeeMargin uint64) error {
148148
gp := std.GasPrice{}
149149
qres, err := cli.ABCIQuery(context.Background(), "auth/gasprice", []byte{})
150150
if err != nil {
@@ -162,7 +162,7 @@ func estimateGasFee(cli client.ABCIClient, bres *ctypes.ResultBroadcastTxCommit,
162162
fee := bres.DeliverTx.GasUsed/gp.Gas + 1
163163
fee = overflow.Mulp(fee, gp.Price.Amount)
164164
// gasFeeMargin is a percentage fee buffer to cover the sudden change of gas price
165-
feeBuffer := overflow.Mulp(fee, gasFeeMargin) / 100
165+
feeBuffer := overflow.Mulp(fee, int64(gasFeeMargin)) / 100
166166
fee = overflow.Addp(fee, feeBuffer)
167167
s := fmt.Sprintf("estimated gas usage: %d, gas fee: %d%s, current gas price: %s\n", bres.DeliverTx.GasUsed, fee, gp.Price.Denom, gp.String())
168168
bres.DeliverTx.Info = s

tm2/pkg/crypto/keys/client/maketx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type MakeTxCfg struct {
2424
// Valid options are SimulateTest, SimulateSkip or SimulateOnly.
2525
Simulate string
2626
// Only used with SimulateOnly
27-
GasFeeMargin int64
27+
GasFeeMargin uint64
2828
ChainID string
2929
}
3030

@@ -105,7 +105,7 @@ func (c *MakeTxCfg) RegisterFlags(fs *flag.FlagSet) {
105105
- only: avoids broadcasting transaction (ie. dry run)`,
106106
)
107107

108-
fs.Int64Var(
108+
fs.Uint64Var(
109109
&c.GasFeeMargin,
110110
"gas-fee-margin",
111111
5,

0 commit comments

Comments
 (0)