diff --git a/x/foundation/keeper/internal/treasury_test.go b/x/foundation/keeper/internal/treasury_test.go index 3609fe3c5c..717173d94e 100644 --- a/x/foundation/keeper/internal/treasury_test.go +++ b/x/foundation/keeper/internal/treasury_test.go @@ -7,29 +7,52 @@ import ( ) func (s *KeeperTestSuite) TestCollectFoundationTax() { + ctx, _ := s.ctx.CacheContext() + + // empty fee collector first + // send the fee to the stranger + // and get it back later if the test case requires + collector := authtypes.NewModuleAddress(authtypes.FeeCollectorName) + fees := s.bankKeeper.GetAllBalances(ctx, collector) + s.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, s.stranger, fees) + for name, tc := range map[string]struct { + fee sdk.Int taxRatio sdk.Dec tax sdk.Int valid bool }{ "common": { + fee: fees[0].Amount, taxRatio: sdk.MustNewDecFromStr("0.123456789"), tax: sdk.NewInt(121932631), valid: true, }, + "zero fee": { + fee: sdk.ZeroInt(), + taxRatio: sdk.MustNewDecFromStr("0.123456789"), + tax: sdk.ZeroInt(), + valid: true, + }, "zero ratio": { + fee: fees[0].Amount, taxRatio: sdk.ZeroDec(), tax: sdk.ZeroInt(), valid: true, }, "send fails": { + fee: fees[0].Amount, taxRatio: sdk.MustNewDecFromStr("1.00000001"), tax: sdk.NewInt(987654330), }, } { s.Run(name, func() { - ctx, _ := s.ctx.CacheContext() + ctx, _ := ctx.CacheContext() + + // set fee + s.bankKeeper.SendCoinsFromAccountToModule(ctx, s.stranger, authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin(fees[0].Denom, tc.fee))) + // set tax ratio s.impl.SetParams(ctx, foundation.Params{ FoundationTax: tc.taxRatio, }) @@ -38,7 +61,7 @@ func (s *KeeperTestSuite) TestCollectFoundationTax() { s.Require().Equal(1, len(before)) s.Require().Equal(sdk.NewDecFromInt(s.balance), before[0].Amount) - tax := sdk.NewDecFromInt(s.balance).MulTruncate(tc.taxRatio).TruncateInt() + tax := sdk.NewDecFromInt(tc.fee).MulTruncate(tc.taxRatio).TruncateInt() // ensure the behavior does not change s.Require().Equal(tc.tax, tax)