From 7599d9b894161f211f1df09a15124b07f86e2dc3 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 27 Feb 2024 00:36:09 -0500 Subject: [PATCH] add more tests for end blocker --- x/emissions/abci_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/x/emissions/abci_test.go b/x/emissions/abci_test.go index 669fe5b53a..247a682879 100644 --- a/x/emissions/abci_test.go +++ b/x/emissions/abci_test.go @@ -87,6 +87,7 @@ func TestEndBlocker(t *testing.T) { observerPoolBalances := sk.BankKeeper.GetBalance(ctx, undistributedObserverPoolAddress, config.BaseDenom).Amount require.Equal(t, emissions[unsuccessfulIndex].Amount.String(), observerPoolBalances.String()) }) + t.Run("unable to process withdraw if address is invalid", func(t *testing.T) { k, ctx, sk, _ := keepertest.EmissionsKeeper(t) undistributedObserverPoolAddress := sk.AuthKeeper.GetModuleAccount(ctx, emissionstypes.UndistributedObserverRewardsPool).GetAddress() @@ -105,6 +106,39 @@ func TestEndBlocker(t *testing.T) { require.Empty(t, k.GetAllWithdrawEmissions(ctx)) require.Equal(t, emission.Amount.String(), sk.BankKeeper.GetBalance(ctx, undistributedObserverPoolAddress, config.BaseDenom).Amount.String()) }) + + t.Run("unable to process withdraw if amount is more than available emission", func(t *testing.T) { + k, ctx, sk, _ := keepertest.EmissionsKeeper(t) + undistributedObserverPoolAddress := sk.AuthKeeper.GetModuleAccount(ctx, emissionstypes.UndistributedObserverRewardsPool).GetAddress() + + emission := sample.WithdrawEmission(t) + k.SetWithdrawEmissions(ctx, emission) + k.SetWithdrawableEmission(ctx, emissionstypes.WithdrawableEmissions{ + Address: emission.Address, + Amount: emission.Amount.Sub(sdkmath.NewInt(1)), + }) + + err := sk.BankKeeper.MintCoins(ctx, emissionstypes.UndistributedObserverRewardsPool, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, emission.Amount))) + require.NoError(t, err) + emissionsModule.EndBlocker(ctx, *k) + require.Empty(t, k.GetAllWithdrawEmissions(ctx)) + require.Equal(t, emission.Amount.String(), sk.BankKeeper.GetBalance(ctx, undistributedObserverPoolAddress, config.BaseDenom).Amount.String()) + }) + + t.Run("unable to process withdraw if UndistributedObserverRewardsPool does not have enough balance", func(t *testing.T) { + k, ctx, sk, _ := keepertest.EmissionsKeeper(t) + + emission := sample.WithdrawEmission(t) + k.SetWithdrawEmissions(ctx, emission) + k.SetWithdrawableEmission(ctx, emissionstypes.WithdrawableEmissions{ + Address: emission.Address, + Amount: emission.Amount, + }) + + emissionsModule.EndBlocker(ctx, *k) + require.Empty(t, k.GetAllWithdrawEmissions(ctx)) + require.Equal(t, sdkmath.ZeroInt().String(), sk.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(emission.Address), config.BaseDenom).Amount.String()) + }) } func TestBeginBlocker(t *testing.T) { t.Run("no observer distribution happens if emissions module account is empty", func(t *testing.T) {