-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consensus min gas fee of .0025 uosmo #4244
Changes from 6 commits
dfe43ca
38946b7
c676d48
923b45e
7a82e14
125d59d
13679ce
295aebb
a374529
8c7f27d
e42e675
f40b0c7
b278a48
5db078c
a8b5c4c
275cfb8
e7db7e1
1896d2e
f3ffdcb
bf1b8bc
81ea3fd
efe1326
540eaff
63c07fa
af6f4a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
clienttx "github.com/cosmos/cosmos-sdk/client/tx" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
|
@@ -19,137 +21,92 @@ func (suite *KeeperTestSuite) TestFeeDecorator() { | |
mempoolFeeOpts := types.NewDefaultMempoolFeeOptions() | ||
mempoolFeeOpts.MinGasPriceForHighGasTx = sdk.MustNewDecFromStr("0.0025") | ||
baseDenom, _ := suite.App.TxFeesKeeper.GetBaseDenom(suite.Ctx) | ||
baseGas := uint64(10000) | ||
consensusMinFeeAmt := int64(25) | ||
|
||
// uion is setup with a relative price of 1:1 | ||
uion := "uion" | ||
|
||
uionPoolId := suite.PrepareBalancerPoolWithCoins( | ||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 500), | ||
sdk.NewInt64Coin(uion, 500), | ||
) | ||
suite.ExecuteUpgradeFeeTokenProposal(uion, uionPoolId) | ||
|
||
tests := []struct { | ||
type testcase struct { | ||
name string | ||
txFee sdk.Coins | ||
minGasPrices sdk.DecCoins | ||
gasRequested uint64 | ||
minGasPrices sdk.DecCoins // if blank, set to 0 | ||
gasRequested uint64 // if blank, set to base gas | ||
isCheckTx bool | ||
expectPass bool | ||
baseDenomGas bool | ||
}{ | ||
{ | ||
name: "no min gas price - checktx", | ||
txFee: sdk.NewCoins(), | ||
minGasPrices: sdk.NewDecCoins(), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: true, | ||
baseDenomGas: true, | ||
}, | ||
{ | ||
name: "no min gas price - delivertx", | ||
txFee: sdk.NewCoins(), | ||
minGasPrices: sdk.NewDecCoins(), | ||
gasRequested: 10000, | ||
isCheckTx: false, | ||
expectPass: true, | ||
baseDenomGas: true, | ||
}, | ||
} | ||
|
||
tests := []testcase{} | ||
txType := []string{"delivertx", "checktx"} | ||
succesType := []string{"does", "doesn't"} | ||
for isCheckTx := 0; isCheckTx <= 1; isCheckTx++ { | ||
mattverse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tests = append(tests, []testcase{ | ||
{ | ||
name: fmt.Sprintf("no min gas price - %s. Fails w/ consensus minimum", txType[isCheckTx]), | ||
txFee: sdk.NewCoins(), | ||
isCheckTx: isCheckTx == 1, | ||
expectPass: false, | ||
}, | ||
{ | ||
name: fmt.Sprintf("Consensus min gas price - %s", txType[isCheckTx]), | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, consensusMinFeeAmt)), | ||
isCheckTx: isCheckTx == 1, | ||
expectPass: true, | ||
}, | ||
{ | ||
name: fmt.Sprintf("multiple fee coins - %s", txType[isCheckTx]), | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1), sdk.NewInt64Coin(uion, 1)), | ||
isCheckTx: isCheckTx == 1, | ||
expectPass: false, | ||
}, | ||
{ | ||
name: fmt.Sprintf("%s work with insufficient mempool fee in %s", succesType[isCheckTx], txType[isCheckTx]), | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, consensusMinFeeAmt)), // consensus minimum | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
isCheckTx: isCheckTx == 1, | ||
expectPass: isCheckTx != 1, | ||
}, | ||
{ | ||
name: fmt.Sprintf("%s work with insufficient converted mempool fee in %s", succesType[isCheckTx], txType[isCheckTx]), | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 25)), // consensus minimum | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
isCheckTx: isCheckTx == 1, | ||
expectPass: isCheckTx != 1, | ||
}, | ||
}...) | ||
} | ||
|
||
custTests := []testcase{ | ||
{ | ||
name: "works with valid basedenom fee", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1000)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: true, | ||
baseDenomGas: true, | ||
}, | ||
{ | ||
name: "doesn't work with not enough fee in checktx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: false, | ||
baseDenomGas: true, | ||
}, | ||
{ | ||
name: "works with not enough fee in delivertx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: false, | ||
expectPass: true, | ||
baseDenomGas: true, | ||
isCheckTx: true, | ||
expectPass: true, | ||
ValarDragon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deduplicated above |
||
{ | ||
name: "works with valid converted fee", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 1000)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: true, | ||
baseDenomGas: false, | ||
isCheckTx: true, | ||
expectPass: true, | ||
}, | ||
{ | ||
name: "doesn't work with not enough converted fee in checktx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 1)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "works with not enough converted fee in delivertx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 1)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, | ||
sdk.MustNewDecFromStr("0.1"))), | ||
gasRequested: 10000, | ||
isCheckTx: false, | ||
expectPass: true, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "multiple fee coins - checktx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1), sdk.NewInt64Coin(uion, 1)), | ||
minGasPrices: sdk.NewDecCoins(), | ||
gasRequested: 10000, | ||
isCheckTx: true, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "multiple fee coins - delivertx", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(baseDenom, 1), sdk.NewInt64Coin(uion, 1)), | ||
minGasPrices: sdk.NewDecCoins(), | ||
gasRequested: 10000, | ||
isCheckTx: false, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
}, | ||
Comment on lines
-99
to
-135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to be deduplicated across check/deliver |
||
{ | ||
name: "invalid fee denom", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin("moo", 1)), | ||
minGasPrices: sdk.NewDecCoins(), | ||
gasRequested: 10000, | ||
isCheckTx: false, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
name: "invalid fee denom", | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin("moooooo", 1000)), | ||
isCheckTx: false, | ||
expectPass: false, | ||
}, | ||
{ | ||
name: "mingasprice not containing basedenom gets treated as min gas price 0", | ||
ValarDragon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 100000000)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewInt64DecCoin(uion, 1)), | ||
gasRequested: 10000, | ||
txFee: sdk.NewCoins(sdk.NewInt64Coin(uion, 1000)), | ||
minGasPrices: sdk.NewDecCoins(sdk.NewInt64DecCoin(uion, 1000000)), | ||
isCheckTx: true, | ||
expectPass: true, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "tx with gas wanted more than allowed should not pass", | ||
|
@@ -158,7 +115,6 @@ func (suite *KeeperTestSuite) TestFeeDecorator() { | |
gasRequested: mempoolFeeOpts.MaxGasWantedPerTx + 1, | ||
isCheckTx: true, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "tx with high gas and not enough fee should no pass", | ||
|
@@ -167,7 +123,6 @@ func (suite *KeeperTestSuite) TestFeeDecorator() { | |
gasRequested: mempoolFeeOpts.HighGasTxThreshold, | ||
isCheckTx: true, | ||
expectPass: false, | ||
baseDenomGas: false, | ||
}, | ||
{ | ||
name: "tx with high gas and enough fee should pass", | ||
|
@@ -176,23 +131,31 @@ func (suite *KeeperTestSuite) TestFeeDecorator() { | |
gasRequested: mempoolFeeOpts.HighGasTxThreshold, | ||
isCheckTx: true, | ||
expectPass: true, | ||
baseDenomGas: false, | ||
}, | ||
} | ||
tests = append(tests, custTests...) | ||
|
||
for _, tc := range tests { | ||
// reset pool and accounts for each test | ||
suite.SetupTest(false) | ||
suite.Run(tc.name, func() { | ||
// setup uion with 1:1 fee | ||
uionPoolId := suite.PrepareBalancerPoolWithCoins( | ||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 500), | ||
sdk.NewInt64Coin(uion, 500), | ||
) | ||
suite.ExecuteUpgradeFeeTokenProposal(uion, uionPoolId) | ||
|
||
if tc.minGasPrices == nil { | ||
tc.minGasPrices = sdk.NewDecCoins() | ||
} | ||
if tc.gasRequested == 0 { | ||
tc.gasRequested = baseGas | ||
} | ||
suite.Ctx = suite.Ctx.WithIsCheckTx(tc.isCheckTx).WithMinGasPrices(tc.minGasPrices) | ||
suite.Ctx = suite.Ctx.WithMinGasPrices(tc.minGasPrices) | ||
|
||
// TODO: Cleanup this code. | ||
// TxBuilder components reset for every test case | ||
txBuilder := suite.clientCtx.TxConfig.NewTxBuilder() | ||
priv0, _, addr0 := testdata.KeyTestPubAddr() | ||
|
@@ -226,11 +189,13 @@ func (suite *KeeperTestSuite) TestFeeDecorator() { | |
_, err := antehandlerMFD(suite.Ctx, tx, false) | ||
|
||
if tc.expectPass { | ||
if tc.baseDenomGas && !tc.txFee.IsZero() { | ||
moduleAddr := suite.App.AccountKeeper.GetModuleAddress(types.FeeCollectorName) | ||
suite.Require().Equal(tc.txFee[0], suite.App.BankKeeper.GetBalance(suite.Ctx, moduleAddr, baseDenom), tc.name) | ||
} else if !tc.txFee.IsZero() { | ||
moduleAddr := suite.App.AccountKeeper.GetModuleAddress(types.NonNativeFeeCollectorName) | ||
// ensure fee was collected | ||
if !tc.txFee.IsZero() { | ||
moduleName := types.FeeCollectorName | ||
if tc.txFee[0].Denom != baseDenom { | ||
moduleName = types.NonNativeFeeCollectorName | ||
} | ||
Comment on lines
+198
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Base denom gas was an unnecessary field, its role is automated with this if statement. |
||
moduleAddr := suite.App.AccountKeeper.GetModuleAddress(moduleName) | ||
suite.Require().Equal(tc.txFee[0], suite.App.BankKeeper.GetBalance(suite.Ctx, moduleAddr, tc.txFee[0].Denom), tc.name) | ||
} | ||
suite.Require().NoError(err, "test: %s", tc.name) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to be consensus min gas failure tests.