-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use harcoded global min gas price check in ProcessProposal (#2985
) ## Overview Fixes - #1621 Introducing a global minimum gas price, a consensus change enforcing a lower bound for all transactions.
- Loading branch information
1 parent
80c3233
commit e05d105
Showing
10 changed files
with
266 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package ante_test | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/ante" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
"github.com/celestiaorg/celestia-app/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
version "github.com/tendermint/tendermint/proto/tendermint/version" | ||
) | ||
|
||
func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { | ||
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
|
||
builder := encCfg.TxConfig.NewTxBuilder() | ||
err := builder.SetMsgs(banktypes.NewMsgSend( | ||
testnode.RandomAddress().(sdk.AccAddress), | ||
testnode.RandomAddress().(sdk.AccAddress), | ||
sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 10))), | ||
) | ||
require.NoError(t, err) | ||
|
||
feeAmount := int64(1000) | ||
|
||
ctx := sdk.Context{} | ||
|
||
testCases := []struct { | ||
name string | ||
fee sdk.Coins | ||
gasLimit uint64 | ||
appVersion uint64 | ||
expErr bool | ||
}{ | ||
{ | ||
name: "bad tx; fee below required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount-1)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "good tx; fee equal to required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; fee above required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount+1)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; with no fee (v1)", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(1), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; gas limit and fee are maximum values", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, math.MaxInt64)), | ||
gasLimit: math.MaxUint64, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "bad tx; gas limit and fee are 0", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 0)), | ||
gasLimit: 0, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; minFee = 0.8, rounds up to 1", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: 400, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
builder.SetGasLimit(tc.gasLimit) | ||
builder.SetFeeAmount(tc.fee) | ||
tx := builder.GetTx() | ||
|
||
ctx = ctx.WithBlockHeader(tmproto.Header{ | ||
Version: version.Consensus{ | ||
App: tc.appVersion, | ||
}, | ||
}) | ||
_, _, err := ante.CheckTxFeeWithGlobalMinGasPrices(ctx, tx) | ||
if tc.expErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.