Skip to content

Commit

Permalink
fix: distribution hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Feb 17, 2025
1 parent d610339 commit 4d7bec9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/upgrades/v2_0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2_0
import (
"context"
"fmt"

poolTypes "github.com/KYVENetwork/chain/x/pool/types"

poolkeeper "github.com/KYVENetwork/chain/x/pool/keeper"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// use KYVE-flavored Cosmos SDK
github.com/cosmos/cosmos-sdk => github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc2
github.com/cosmos/cosmos-sdk => github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc4

// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rW
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0 h1:+r1rSv4gvYn0wmRjC8X7IAzX8QezqtFV9m0MUHFJgts=
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0/go.mod h1:b3g59n2Y+T5xmcxJL+UEG2f8cQploZm1mR/v6BW0mU0=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc2 h1:K+nJMDTcieqzb+H8+nkMI0uD6UvKYu+zi3jCYh7AOHk=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc2/go.mod h1:hrWEFMU1eoXqLJeE6VVESpJDQH67FS1nnMrQIjO2daw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
Expand Down
4 changes: 4 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM=
github.com/Joker/jade v1.1.3 h1:Qbeh12Vq6BxURXT1qZBRHsDxeURB8ztcL6f3EXSGeHk=
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc3 h1:ZB/j9Ec6PsHAAoKAH2PyydA05dU76jmmQhxRGXQtcbg=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc3/go.mod h1:hrWEFMU1eoXqLJeE6VVESpJDQH67FS1nnMrQIjO2daw=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc4 h1:uAASSxJKFEw5UuDcnY6oUEGQTmJltcW94g/vXMF5RHQ=
github.com/KYVENetwork/cosmos-sdk v0.50.11-kyve-rc4/go.mod h1:hrWEFMU1eoXqLJeE6VVESpJDQH67FS1nnMrQIjO2daw=
github.com/KYVENetwork/interchaintest/v8 v8.0.0-20240520124515-fd4cc797e6fd h1:lKJ7X9Q+KbQviDxpY4OaalC8/oZ64rXfTNTny4jfuE0=
github.com/KYVENetwork/interchaintest/v8 v8.0.0-20240520124515-fd4cc797e6fd/go.mod h1:pupV0YN3A56/u9kHj9U1F8MdDUEolBIn05F0W1q/0oI=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
Expand Down
32 changes: 32 additions & 0 deletions x/multi_coin_rewards/keeper/msg_server_toggle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package keeper_test
import (
"cosmossdk.io/math"
multicoinrewardstypes "github.com/KYVENetwork/chain/x/multi_coin_rewards/types"
sdk "github.com/cosmos/cosmos-sdk/types"
distributionTypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -25,6 +27,7 @@ TEST CASES - msg_server_leave_pool.go
* MultiCoin claim pending rewards
* MultiCoin enabled, claim, disable, claim again
* Claim after period is over
* Claim rewards indirectly by delegation
*/

Expand Down Expand Up @@ -307,4 +310,33 @@ var _ = Describe("msg_server_toggle_test.go", Ordered, func() {
Expect(s.GetCoinsFromModule(multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName).String()).To(Equal("100acoin,50bcoin"))
Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), validator1.Address, validator1.Address)).To(BeEmpty())
})

It("Claim rewards indirectly through another delegation", func() {
// Arrange
payoutRewards(s, validator1.Address, i.KYVECoins(200*i.T_KYVE))
payoutRewards(s, validator1.Address, i.ACoins(100))
payoutRewards(s, validator1.Address, i.BCoins(50))

Expect(s.App().BankKeeper.GetAllBalances(s.Ctx(), validator1.AccAddress).String()).To(Equal("10000000000acoin,10000000000bcoin,10000000000ccoin,9000000000tkyve"))
Expect(s.GetCoinsFromModule(multicoinrewardstypes.ModuleName).String()).To(BeEmpty())
Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), validator1.Address, validator1.Address).String()).To(Equal("100acoin,50bcoin,200000000tkyve"))

// ACT
s.CommitAfterSeconds(s.App().MultiCoinRewardsKeeper.GetParams(s.Ctx()).MultiCoinDistributionPendingTime)
s.CommitAfterSeconds(1)
s.RunTxSuccess(&stakingTypes.MsgDelegate{
DelegatorAddress: validator1.Address,
ValidatorAddress: validator1.ValAddress,
Amount: i.KYVECoin(400 * i.T_KYVE),
})

// ASSERT
// 9,000 + 200 (rewards) - 400 (delegation) = 8,800
Expect(s.App().BankKeeper.GetAllBalances(s.Ctx(), validator1.AccAddress).String()).To(Equal("10000000000acoin,10000000000bcoin,10000000000ccoin,8800000000tkyve"))
cosmosValidator, _ := s.App().StakingKeeper.GetValidator(s.Ctx(), sdk.ValAddress(validator1.AccAddress))
Expect(cosmosValidator.Tokens.Int64()).To(Equal(1400 * i.T_KYVE))
Expect(s.GetCoinsFromModule(multicoinrewardstypes.ModuleName).String()).To(Equal("100acoin,50bcoin"))
Expect(s.GetCoinsFromModule(multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName).String()).To(BeEmpty())
Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), validator1.Address, validator1.Address)).To(BeEmpty())
})
})

0 comments on commit 4d7bec9

Please sign in to comment.