-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: configurable fee collector for DeductFeeDecorator #407
Changes from 2 commits
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |||||||||||||||||||||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||||||||||||||||||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||||||||||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||||||||||||||||||||||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||||||||||||||||||||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil" | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -146,3 +147,47 @@ func (s *AnteTestSuite) TestDeductFees() { | |||||||||||||||||||||
|
||||||||||||||||||||||
s.Require().Nil(err, "Tx errored after account has been set with sufficient funds") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (s *AnteTestSuite) TestDeductFees_WithName() { | ||||||||||||||||||||||
s.SetupTest(false) // setup | ||||||||||||||||||||||
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder() | ||||||||||||||||||||||
|
||||||||||||||||||||||
// keys and addresses | ||||||||||||||||||||||
priv1, _, addr1 := testdata.KeyTestPubAddr() | ||||||||||||||||||||||
|
||||||||||||||||||||||
// msg and signatures | ||||||||||||||||||||||
msg := testdata.NewTestMsg(addr1) | ||||||||||||||||||||||
feeAmount := testdata.NewTestFeeAmount() | ||||||||||||||||||||||
gasLimit := testdata.NewTestGasLimit() | ||||||||||||||||||||||
s.Require().NoError(s.txBuilder.SetMsgs(msg)) | ||||||||||||||||||||||
s.txBuilder.SetFeeAmount(feeAmount) | ||||||||||||||||||||||
s.txBuilder.SetGasLimit(gasLimit) | ||||||||||||||||||||||
|
||||||||||||||||||||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} | ||||||||||||||||||||||
tx, err := s.CreateTestTx(privs, accNums, accSeqs, s.ctx.ChainID()) | ||||||||||||||||||||||
s.Require().NoError(err) | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Set account with sufficient funds | ||||||||||||||||||||||
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.
Suggested change
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. Done. |
||||||||||||||||||||||
acc := s.app.AccountKeeper.NewAccountWithAddress(s.ctx, addr1) | ||||||||||||||||||||||
s.app.AccountKeeper.SetAccount(s.ctx, acc) | ||||||||||||||||||||||
coins := sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(200))) | ||||||||||||||||||||||
err = testutil.FundAccount(s.app.BankKeeper, s.ctx, addr1, coins) | ||||||||||||||||||||||
s.Require().NoError(err) | ||||||||||||||||||||||
|
||||||||||||||||||||||
feeCollectorAcc := s.app.AccountKeeper.GetModuleAccount(s.ctx, types.FeeCollectorName) | ||||||||||||||||||||||
// pick a simapp module account | ||||||||||||||||||||||
altCollectorName := "distribution" | ||||||||||||||||||||||
altCollectorAcc := s.app.AccountKeeper.GetModuleAccount(s.ctx, altCollectorName) | ||||||||||||||||||||||
s.Require().True(s.app.BankKeeper.GetAllBalances(s.ctx, feeCollectorAcc.GetAddress()).Empty()) | ||||||||||||||||||||||
altBalance := s.app.BankKeeper.GetAllBalances(s.ctx, altCollectorAcc.GetAddress()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
dfd := ante.NewDeductFeeDecoratorWithName(s.app.AccountKeeper, s.app.BankKeeper, nil, nil, altCollectorName) | ||||||||||||||||||||||
antehandler := sdk.ChainAnteDecorators(dfd) | ||||||||||||||||||||||
|
||||||||||||||||||||||
_, err = antehandler(s.ctx, tx, false) | ||||||||||||||||||||||
s.Require().NoError(err) | ||||||||||||||||||||||
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.
Suggested change
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. Done. |
||||||||||||||||||||||
|
||||||||||||||||||||||
s.Require().True(s.app.BankKeeper.GetAllBalances(s.ctx, feeCollectorAcc.GetAddress()).Empty()) | ||||||||||||||||||||||
newAltBalance := s.app.BankKeeper.GetAllBalances(s.ctx, altCollectorAcc.GetAddress()) | ||||||||||||||||||||||
s.Require().True(newAltBalance.IsAllGTE(altBalance)) | ||||||||||||||||||||||
Comment on lines
+190
to
+192
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.
Suggested change
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. Done. |
||||||||||||||||||||||
} |
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.
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.
Oops, done.