Skip to content

Commit

Permalink
chore: backport withdraw emissions update (#2143)
Browse files Browse the repository at this point in the history
* test: disable header proof test in local upgrade test E2E test (#2051)

* add skip header option

* use option for migration test

* move bitcoin addresses tests to advanced

* show cctx in logs

* update version

* fix verification flags error

* add changes to v16

---------

Co-authored-by: Lucas Bertrand <[email protected]>
  • Loading branch information
kingpinXD and lumtis authored May 8, 2024
1 parent b05c2fa commit 0e45a72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
19 changes: 19 additions & 0 deletions x/emissions/keeper/msg_server_withdraw_emissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,24 @@ func TestMsgServer_WithdrawEmission(t *testing.T) {
balance := sk.BankKeeper.GetBalance(ctx, sdk.MustAccAddressFromBech32(withdrawableEmission.Address), config.BaseDenom).Amount.String()
require.Equal(t, sdk.ZeroInt().String(), balance)
})
t.Run("unable to withdraw emissions if amount requested is more that available", func(t *testing.T) {
k, ctx, sk, _ := keepertest.EmissionsKeeper(t)

msgServer := keeper.NewMsgServerImpl(*k)
withdrawableEmission := sample.WithdrawableEmissions(t)
k.SetWithdrawableEmission(ctx, withdrawableEmission)
withdrawAmount := withdrawableEmission.Amount.Add(sdkmath.OneInt())
err := sk.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, withdrawAmount)))
require.NoError(t, err)
err = sk.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, types.UndistributedObserverRewardsPool, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, withdrawAmount)))
require.NoError(t, err)

_, err = msgServer.WithdrawEmission(ctx, &types.MsgWithdrawEmission{
Creator: withdrawableEmission.Address,
Amount: withdrawAmount,
})
require.ErrorIs(t, err, types.ErrUnableToWithdrawEmissions)
require.ErrorContains(t, err, "amount to be removed is greater than the available withdrawable emission")
})

}
4 changes: 2 additions & 2 deletions x/emissions/keeper/withdrawable_emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func (k Keeper) RemoveWithdrawableEmission(ctx sdk.Context, address string, amou
return types.ErrEmissionsNotFound
}
if amount.IsNegative() || amount.IsZero() {
return types.ErrInvalidAmount
return types.ErrInvalidAmount.Wrap("amount to be removed is negative or zero")
}
if amount.GT(we.Amount) {
amount = we.Amount
return types.ErrInvalidAmount.Wrap("amount to be removed is greater than the available withdrawable emission")
}
we.Amount = we.Amount.Sub(amount)
k.SetWithdrawableEmission(ctx, we)
Expand Down
9 changes: 3 additions & 6 deletions x/emissions/keeper/withdrawable_emissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,14 @@ func TestKeeper_RemoveObserverEmission(t *testing.T) {
require.Equal(t, sdkmath.ZeroInt(), we2.Amount)
})

t.Run("remove all observer emission successfully using amount higher that available", func(t *testing.T) {
t.Run("unable to remove observer emission if requested amount is higher than available", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionsKeeper(t)
we := sample.WithdrawableEmissions(t)
k.SetWithdrawableEmission(ctx, we)
err := k.RemoveWithdrawableEmission(ctx, we.Address, we.Amount.Add(sdkmath.OneInt()))
require.NoError(t, err)
we2, found := k.GetWithdrawableEmission(ctx, we.Address)
require.True(t, found)
require.Equal(t, sdkmath.ZeroInt(), we2.Amount)
require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount)
require.ErrorContains(t, err, "amount to be removed is greater than the available withdrawable emission")
})

t.Run("unable to remove non-existent emission ", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionsKeeper(t)
address := sample.AccAddress()
Expand Down

0 comments on commit 0e45a72

Please sign in to comment.