Skip to content

Commit

Permalink
add more tests for end blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 27, 2024
1 parent f86c782 commit 7599d9b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions x/emissions/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 7599d9b

Please sign in to comment.