Skip to content

Commit

Permalink
Increase the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech committed Apr 7, 2023
1 parent 7feb7f4 commit d4e5e6d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions x/foundation/keeper/internal/treasury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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)

Expand Down

0 comments on commit d4e5e6d

Please sign in to comment.