|
| 1 | +package ante_test |
| 2 | + |
| 3 | +import ( |
| 4 | + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" |
| 5 | + "github.com/cosmos/cosmos-sdk/testutil/testdata" |
| 6 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 7 | + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" |
| 8 | + |
| 9 | + "github.com/terra-money/core/custom/auth/ante" |
| 10 | + core "github.com/terra-money/core/types" |
| 11 | + "github.com/cosmos/cosmos-sdk/types/query" |
| 12 | + "github.com/cosmos/cosmos-sdk/x/auth/types" |
| 13 | + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" |
| 14 | +) |
| 15 | + |
| 16 | +func (suite *AnteTestSuite) TestEnsureBurnTaxModule() { |
| 17 | + suite.SetupTest(true) // setup |
| 18 | + suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() |
| 19 | + |
| 20 | + mfd := ante.NewBurnTaxFeeDecorator(suite.app.TreasuryKeeper, suite.app.BankKeeper) |
| 21 | + antehandler := sdk.ChainAnteDecorators(mfd) |
| 22 | + |
| 23 | + // keys and addresses |
| 24 | + priv1, _, addr1 := testdata.KeyTestPubAddr() |
| 25 | + |
| 26 | + // msg and signatures |
| 27 | + sendAmount := int64(1000000) |
| 28 | + sendCoins := sdk.NewCoins(sdk.NewInt64Coin(core.MicroSDRDenom, sendAmount)) |
| 29 | + msg := banktypes.NewMsgSend(addr1, addr1, sendCoins) |
| 30 | + |
| 31 | + feeAmount := testdata.NewTestFeeAmount() |
| 32 | + gasLimit := testdata.NewTestGasLimit() |
| 33 | + suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) |
| 34 | + suite.txBuilder.SetFeeAmount(feeAmount) |
| 35 | + suite.txBuilder.SetGasLimit(gasLimit) |
| 36 | + |
| 37 | + privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} |
| 38 | + tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) |
| 39 | + suite.Require().NoError(err) |
| 40 | + |
| 41 | + // set zero gas prices |
| 42 | + suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins()) |
| 43 | + |
| 44 | + // Set IsCheckTx to true |
| 45 | + suite.ctx = suite.ctx.WithIsCheckTx(true) |
| 46 | + |
| 47 | + // Luna must pass without burn before the specified tax block height |
| 48 | + _, err = antehandler(suite.ctx, tx, false) |
| 49 | + suite.Require().NoError(err, "Decorator should not have errored when block height is 1") |
| 50 | + |
| 51 | + // Set the blockheight past the tax height block |
| 52 | + suite.ctx = suite.ctx.WithBlockHeight(10000000) |
| 53 | + // antehandler errors with insufficient fees due to tax |
| 54 | + _, err = antehandler(suite.ctx, tx, false) |
| 55 | + suite.Require().Error(err, "Decorator should errored on low fee for local gasPrice + tax") |
| 56 | + |
| 57 | + tk := suite.app.TreasuryKeeper |
| 58 | + expectedTax := tk.GetTaxRate(suite.ctx).MulInt64(sendAmount).TruncateInt() |
| 59 | + if taxCap := tk.GetTaxCap(suite.ctx, core.MicroSDRDenom); expectedTax.GT(taxCap) { |
| 60 | + expectedTax = taxCap |
| 61 | + } |
| 62 | + |
| 63 | + taxes := sdk.NewCoins(sdk.NewInt64Coin(core.MicroSDRDenom, expectedTax.Int64())) |
| 64 | + |
| 65 | + bk := suite.app.BankKeeper |
| 66 | + bk.MintCoins(suite.ctx, minttypes.ModuleName, sendCoins) |
| 67 | + |
| 68 | + // Populate the FeeCollector module with taxes |
| 69 | + bk.SendCoinsFromModuleToModule(suite.ctx, minttypes.ModuleName, types.FeeCollectorName, taxes) |
| 70 | + feeCollector := suite.app.AccountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) |
| 71 | + |
| 72 | + amountFee := bk.GetAllBalances(suite.ctx, feeCollector.GetAddress()) |
| 73 | + suite.Require().Equal(amountFee, taxes) |
| 74 | + totalSupply, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{}) |
| 75 | + |
| 76 | + // must pass with tax and burn |
| 77 | + _, err = antehandler(suite.ctx, tx, false) |
| 78 | + suite.Require().NoError(err, "Decorator should not have errored on fee higher than local gasPrice") |
| 79 | + |
| 80 | + // Burn the taxes |
| 81 | + tk.BurnCoinsFromBurnAccount(suite.ctx) |
| 82 | + suite.Require().NoError(err) |
| 83 | + |
| 84 | + supplyAfterBurn, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{}) |
| 85 | + |
| 86 | + // Total supply should have decreased by the tax amount |
| 87 | + suite.Require().Equal(taxes, totalSupply.Sub(supplyAfterBurn)) |
| 88 | + |
| 89 | + |
| 90 | +} |
| 91 | + |
0 commit comments