diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go index c9835fec..5df7d785 100644 --- a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -335,7 +335,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with no funders and 100% inflation splitting", func() { + It("Produce a valid bundle with no funders and 100% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("1") @@ -399,20 +399,20 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 49433483tkyve + // inflation payout is 49440tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (49440 - (49433483 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + // (49440 - (49440 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ // Due to cosmos rounding, the result is a little off. - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(4_893_963).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(4_939).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (49433483 - (49433483 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + // (49440 - (49440 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) // Due to cosmos rounding, the result is a little off. - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(44_045_220).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(44_007).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -525,7 +525,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2)) }) - PIt("Produce a valid bundle with sufficient funders and 10% inflation splitting", func() { + It("Produce a valid bundle with sufficient funders and 10% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0.1") @@ -603,18 +603,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 10_000 - ((7_415_009 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(735_121).String())) + // (7410 + 10_000 - ((7410 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(1768).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 10_000 - ((7_415_009 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_615_642).String())) + // (7410 + 10_000 - ((7410 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(15_468).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -623,7 +623,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2)) }) - PIt("Produce a valid bundle with sufficient funders and 100% inflation splitting", func() { + It("Produce a valid bundle with sufficient funders and 100% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("1") @@ -701,17 +701,17 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (2_471_6741 + 10_000 - ((2_471_6741 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_994).String())) + // (24720 + 10_000 - ((24720 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(3482).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (2_471_6741 + 10_000 - ((2_471_6741 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_031_498).String())) + // (24720 + 10_000 - ((24720 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(30891).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -823,7 +823,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with insufficient funders and 30% inflation splitting", func() { + It("Produce a valid bundle with insufficient funders and 30% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0.1") @@ -901,18 +901,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7_415_009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 300 - ((7_415_009 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(734_161).String())) + // (7410 + 300 - ((7410 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(808).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 300 - ((7_415_009 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_606_999).String())) + // (7410 + 300 - ((7410 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6825).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -921,7 +921,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with insufficient funders and 10% inflation splitting", func() { + It("Produce a valid bundle with insufficient funders and 10% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("1") @@ -999,18 +999,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (24_716_741 + 300 - ((24_716_741 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_033).String())) + // (24720 + 300 - ((24720 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2522).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (24_716_741 + 300 - ((24_716_741 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_022_856).String())) + // (24720 + 300 - ((24720 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_248).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1019,7 +1019,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with some insufficient funders and 0% inflation splitting", func() { + It("Produce a valid bundle with some insufficient funders and 0% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0") @@ -1122,7 +1122,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) }) - PIt("Produce a valid bundle with some insufficient funders and 30% inflation splitting", func() { + It("Produce a valid bundle with some insufficient funders and 30% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0.1") @@ -1200,18 +1200,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 5_000 + 200 - ((7_415_009 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(734_646).String())) + // (7410 + 5_000 + 200 - ((7410 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(1293).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 5_000 + 200 - ((7_415_009 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_611_365).String())) + // (7410 + 5_000 + 200 - ((7410 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(11_191).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1220,7 +1220,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) }) - PIt("Produce a valid bundle with some insufficient funders and 100% inflation splitting", func() { + It("Produce a valid bundle with some insufficient funders and 100% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("1") @@ -1298,18 +1298,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (24_716_741 + 5_000 + 200 - ((24_716_741 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_519).String())) + // (24720 + 5_000 + 200 - ((24720 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(3007).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (24_716_741 + 5_000 + 200 - ((24_716_741 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_027_221).String())) + // (24720 + 5_000 + 200 - ((24720 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(26_614).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1421,7 +1421,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2)) }) - PIt("Produce a valid bundle with multiple coins funded and 10% inflation splitting", func() { + It("Produce a valid bundle with multiple coins funded and 10% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0.1") @@ -1500,22 +1500,22 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // for kyve coin (7_415_009 - (7_415_009 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ + // for kyve coin (7410 - (7410 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for bcoin coins (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * 0.1 + _((100 * 0.5) / (3 * 2))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(734_100), i.ACoin(1004), i.BCoin(1987)).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(748), i.ACoin(1004), i.BCoin(1987)).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // for kyve coin (7_415_009 - (7_415_009 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) + // for kyve coin (7410 - (7410 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for bcoin (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(6_606_763), i.ACoin(8896), i.BCoin(17813)).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(6588), i.ACoin(8896), i.BCoin(17813)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1531,7 +1531,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2)) }) - PIt("Produce a valid bundle with multiple coins funded and 100% inflation splitting", func() { + It("Produce a valid bundle with multiple coins funded and 100% inflation splitting", func() { // ARRANGE params := pooltypes.DefaultParams() params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("1") @@ -1610,22 +1610,22 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // for kyve coin (24_716_741 - (24_716_741 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ + // for kyve coin (24720 - (24720 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for bcoin coins (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * 0.1 + _((100 * 0.5) / (3 * 2))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(2_446_973), i.ACoin(1004), i.BCoin(1987)).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(2461), i.ACoin(1004), i.BCoin(1987)).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // for kyve coin (24_716_741 - (24_716_741 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) + // for kyve coin (24720 - (24720 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for bcoin (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(22_022_619), i.ACoin(8896), i.BCoin(17813)).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(22012), i.ACoin(8896), i.BCoin(17813)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1724,7 +1724,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with no funders, 10% inflation splitting and pool-0 = 0.1 weight and pool-1 = 1.0 weight", func() { + It("Produce a valid bundle with no funders, 10% inflation splitting and pool-0 = 0.1 weight and pool-1 = 1.0 weight", func() { // ARRANGE // Enable inflation share for pools @@ -1828,10 +1828,10 @@ var _ = Describe("inflation splitting", Ordered, func() { inflationAmount := postMineBalance.Sub(preMineBalance) // Reward calculation: // (inflationAmount - teamRewards) * protocolInflationShare -> Both pools equally - // (340112587966tkyve - 847940tkyve) * 0.1 -> rewards for both pools, but it is split according to the different weights + // (340112417tkyve - 800tkyve) * 0.1 -> rewards for both pools, but it is split according to the different weights // teamAuthority rewards are hard to set to zero from this test-suite without using reflection. // therefore we ignore the small amount. - Expect(inflationAmount.String()).To(Equal("340112587966tkyve")) + Expect(inflationAmount.String()).To(Equal("340112417tkyve")) // assert if bundle go finalized pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -1844,21 +1844,21 @@ var _ = Describe("inflation splitting", Ordered, func() { // First pool has weight: 0.1, second pool has weight 1 // additionally, pool-0 produced a bundle -> subtract PoolInflationPayoutRate (1 - 0.1 = 0.9) // formula: (inflation - teamRewards) * inflationShare * inflationShareWeighOfPool * (1-PoolInflationPayoutRate) - // (340112587966 - 847940) * 0.1 * 1 / 11 * 0.9 - // Evaluates to 2782732418, however due to multiple roundings to actual amount is 2782732144 + // (340112417 - 800) * 0.1 * 1 / 11 * 0.9 + // Evaluates to 2782731, however due to multiple roundings to actual amount is 2782690 // second pool - // (340112587966 - 847940) * 0.1 * 10 / 11 - // Evaluates to 30919249093 - Expect(finalBalancePool0).To(Equal(uint64(2782732144))) - Expect(finalBalancePool1).To(Equal(uint64(30919246548))) + // (340112417 - 800) * 0.1 * 10 / 11 + // Evaluates to 30919237 + Expect(finalBalancePool0).To(Equal(uint64(2782690))) + Expect(finalBalancePool1).To(Equal(uint64(30919140))) // assert bundle reward // the total payout is here just the inflation payout // (inflation - teamRewards)*inflationShare - balancePool0 - balancePool1 - // (340112344399 - 847940) * 0.1 * 1 / 11 * 0.1 - // evaluates to 309192269, due to multiple rounding (and : 309192460 - totalPayout := math.LegacyNewDec(309192460) + // (340112417 - 800) * 0.1 * 1 / 11 * 0.1 + // evaluates to 309192 + totalPayout := math.LegacyNewDec(309192) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := totalPayout.Mul(networkFee).TruncateDec() @@ -1871,9 +1871,9 @@ var _ = Describe("inflation splitting", Ordered, func() { // assert commission rewards // Due to rounding in the cosmos Allocate tokens the amount is off by one. (This does not affect the total rewards // only the commission-rewards distribution) - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).AmountOf(globalTypes.Denom).String()).To(Equal(uploaderPayoutReward.Add(storageReward).RoundInt().String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).AmountOf(globalTypes.Denom).String()).To(Equal(uploaderPayoutReward.Add(storageReward).RoundInt().SubRaw(1).String())) // assert uploader self delegation rewards - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).ToLegacyDec().String()).To(Equal(uploaderDelegationReward.String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).ToLegacyDec().String()).To(Equal(uploaderDelegationReward.Sub(math.LegacyNewDec(4)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1882,7 +1882,7 @@ var _ = Describe("inflation splitting", Ordered, func() { Expect(fundingState.ActiveFunderAddresses).To(BeEmpty()) }) - PIt("Produce a valid bundle with no funders, 10% inflation splitting and pool-0 = 1.0 weight and pool-1 = 1.0 weight", func() { + It("Produce a valid bundle with no funders, 10% inflation splitting and pool-0 = 1.0 weight and pool-1 = 1.0 weight", func() { // ARRANGE // Enable inflation share for pools @@ -1990,10 +1990,10 @@ var _ = Describe("inflation splitting", Ordered, func() { inflationAmount := postMineBalance.Sub(preMineBalance) // Reward calculation: // (inflationAmount - teamRewards) * protocolInflationShare -> Both pools equally - // (340112587966tkyve - 847940tkyve) * 0.1 -> (//2) -> 17005574822 for both pools + // (340112417tkyve - 800tkyve) * 0.1 -> (//2) -> 17005580 for both pools // teamAuthority rewards are hard to set to zero from this test-suite without using reflection. // therefore we ignore the small amount. - Expect(inflationAmount.String()).To(Equal("340112587966tkyve")) + Expect(inflationAmount.String()).To(Equal("340112417tkyve")) // assert if bundle go finalized pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -2005,14 +2005,14 @@ var _ = Describe("inflation splitting", Ordered, func() { finalBalancePool1 := s.GetBalanceFromPool(1) // Both pools have inflation-weight 1 // however, pool-0 produced a bundle -> subtract PoolInflationPayoutRate (1 - 0.2 = 0.8) - // 17005574822 * 0.8 - Expect(finalBalancePool0).To(Equal(uint64(13604468481))) - Expect(finalBalancePool1).To(Equal(uint64(17005585601))) + // 17005534 * 0.8 + Expect(finalBalancePool0).To(Equal(uint64(13604428))) + Expect(finalBalancePool1).To(Equal(uint64(17005534))) // assert bundle reward // the total payout is here just the inflation payout - totalPayout := math.LegacyNewDec(17005585601 - 13604468481) + totalPayout := math.LegacyNewDec(17005534 - 13604428) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := totalPayout.Mul(networkFee).TruncateDec() diff --git a/x/stakers/keeper/keeper_suite_protocol_bridge_test.go b/x/stakers/keeper/keeper_suite_protocol_bridge_test.go new file mode 100644 index 00000000..f580324b --- /dev/null +++ b/x/stakers/keeper/keeper_suite_protocol_bridge_test.go @@ -0,0 +1,219 @@ +package keeper_test + +import ( + "fmt" + + "cosmossdk.io/math" + + stakertypes "github.com/KYVENetwork/chain/x/stakers/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + i "github.com/KYVENetwork/chain/testutil/integration" + pooltypes "github.com/KYVENetwork/chain/x/pool/types" +) + +/* + +TEST CASES - msg_server_join_pool.go + +* Consensus slash leads to removal from pool +* Consensus slash leads to removal from all pool +* Getting pushed out of the active set leads to removal from pool +* Unbonded validator can not join a pool + +*/ + +var _ = Describe("keeper_suite_protocol_bridge.go", Ordered, func() { + s := i.NewCleanChain() + + gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String() + + validator1 := s.CreateNewValidator("Staker-0", 1000*i.KYVE) + + BeforeEach(func() { + // init new clean chain + s = i.NewCleanChain() + + // create pool + msg := &pooltypes.MsgCreatePool{ + Authority: gov, + UploadInterval: 60, + MaxBundleSize: 100, + InflationShareWeight: math.LegacyZeroDec(), + Binaries: "{}", + } + s.RunTxPoolSuccess(msg) + + s.SetMaxVotingPower("1") + + validator1 = s.CreateNewValidator("Staker-0", 1000*i.KYVE) + }) + + AfterEach(func() { + s.PerformValidityChecks() + }) + + It("Consensus slash leads to removal from pool", func() { + // Arrange + params, _ := s.App().SlashingKeeper.GetParams(s.Ctx()) + params.MinSignedPerWindow = math.LegacyMustNewDecFromStr("1") + params.SignedBlocksWindow = 1 + _ = s.App().SlashingKeeper.SetParams(s.Ctx(), params) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + // Make validator not participate in block votes to have him kicked out + s.AddAbciAbsentVote(validator1.ConsAccAddress) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(2)) + + // Act + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(1)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Consensus slash leads to removal from all pool", func() { + // Arrange + params, _ := s.App().SlashingKeeper.GetParams(s.Ctx()) + params.MinSignedPerWindow = math.LegacyMustNewDecFromStr("1") + params.SignedBlocksWindow = 1 + _ = s.App().SlashingKeeper.SetParams(s.Ctx(), params) + + for k := 1; k < 10; k++ { + msg := &pooltypes.MsgCreatePool{ + Authority: gov, + UploadInterval: 60, + MaxBundleSize: 100, + InflationShareWeight: math.LegacyZeroDec(), + Binaries: "{}", + } + s.RunTxPoolSuccess(msg) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: uint64(k), + PoolAddress: validator1.PoolAccount[k], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + } + + // Make validator not participate in block votes to have him kicked out + s.AddAbciAbsentVote(validator1.ConsAccAddress) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(2)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(9)) + + // Act + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + for k := 1; k < 10; k++ { + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + } + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(1)) + + poolAccounts = s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Getting pushed out of the active set leads to removal from pool", func() { + // Arrange + + // There are 51 validator slots (1 is occupied by the default validator (1 $KYVE) and another one by validator1) + for k := 0; k < 50; k++ { + s.CreateNewValidator(fmt.Sprintf("val-%d", k), 10000*i.KYVE) + } + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(51)) + + // Act + + // Create one more validator to kick out validator1 + s.CreateNewValidator(fmt.Sprintf("val-%d", 51), 10000*i.KYVE) + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(51)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Unbonded validator can not join a pool", func() { + // Arrange + + // There are 51 validator slots (1 is occupied by the default validator (1 $KYVE) and another one by validator1) + // This will kick out validator1 + for k := 0; k < 51; k++ { + s.CreateNewValidator(fmt.Sprintf("val-%d", k), 10000*i.KYVE) + } + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(51)) + + // Act + _, err := s.RunTx(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + // Assert + Expect(err.Error()).To(Equal("validator not in active set")) + + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(51)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) +}) diff --git a/x/stakers/keeper/keeper_suite_slash_test.go b/x/stakers/keeper/keeper_suite_slash_test.go deleted file mode 100644 index 2ad0f3b8..00000000 --- a/x/stakers/keeper/keeper_suite_slash_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package keeper_test - -import ( - "cosmossdk.io/math" - stakertypes "github.com/KYVENetwork/chain/x/stakers/types" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - i "github.com/KYVENetwork/chain/testutil/integration" - pooltypes "github.com/KYVENetwork/chain/x/pool/types" -) - -/* - -TEST CASES - msg_server_join_pool.go - -* Consensus Slash leads to removal from pool - -*/ - -var _ = Describe("msg_server_join_pool.go", Ordered, func() { - s := i.NewCleanChain() - - gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String() - - validator1 := s.CreateNewValidator("Staker-0", 1000*i.KYVE) - - BeforeEach(func() { - // init new clean chain - s = i.NewCleanChain() - - // create pool - msg := &pooltypes.MsgCreatePool{ - Authority: gov, - UploadInterval: 60, - MaxBundleSize: 100, - InflationShareWeight: math.LegacyZeroDec(), - Binaries: "{}", - } - s.RunTxPoolSuccess(msg) - - s.SetMaxVotingPower("1") - - validator1 = s.CreateNewValidator("Staker-0", 1000*i.KYVE) - }) - - AfterEach(func() { - s.PerformValidityChecks() - }) - - It("Consensus Slash leads to removal from pool", func() { - // Arrange - params, _ := s.App().SlashingKeeper.GetParams(s.Ctx()) - params.MinSignedPerWindow = math.LegacyMustNewDecFromStr("1") - params.SignedBlocksWindow = 1 - _ = s.App().SlashingKeeper.SetParams(s.Ctx(), params) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: validator1.Address, - PoolId: 0, - PoolAddress: validator1.PoolAccount[0], - Commission: math.LegacyMustNewDecFromStr("0.1"), - StakeFraction: math.LegacyMustNewDecFromStr("1"), - }) - - // Make validator not participate in block votes to have him kicked out - s.AddAbciAbsentVote(validator1.ConsAccAddress) - - preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) - Expect(preBonded).To(HaveLen(2)) - - // Act - s.CommitAfterSeconds(1) - s.CommitAfterSeconds(1) - - // Assert - poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) - Expect(poolMembersCount).To(Equal(uint64(0))) - - postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) - Expect(postBonded).To(HaveLen(1)) - - poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) - Expect(poolAccounts).To(HaveLen(0)) - }) -}) diff --git a/x/stakers/keeper/msg_server_join_pool.go b/x/stakers/keeper/msg_server_join_pool.go index 5870e836..359d2623 100644 --- a/x/stakers/keeper/msg_server_join_pool.go +++ b/x/stakers/keeper/msg_server_join_pool.go @@ -39,7 +39,7 @@ func (k msgServer) JoinPool(goCtx context.Context, msg *types.MsgJoinPool) (*typ // Validator must be in the active set. if !validator.IsBonded() { - return nil, errors.Wrapf(errorsTypes.ErrNotFound, types.ErrValidatorJailed.Error()) + return nil, types.ErrValidatorNotInActiveSet } // Validators are not allowed to use their own address, to prevent diff --git a/x/stakers/types/errors.go b/x/stakers/types/errors.go index ee8493d6..8269dccd 100644 --- a/x/stakers/types/errors.go +++ b/x/stakers/types/errors.go @@ -21,6 +21,6 @@ var ( ErrPoolLeaveAlreadyInProgress = errors.Register(ModuleName, 1117, "Pool leave is already in progress") ErrPoolAccountUnauthorized = errors.Register(ModuleName, 1118, "pool account unauthorized") - ErrValidatorJailed = errors.Register(ModuleName, 1119, "validator jailed") + ErrValidatorNotInActiveSet = errors.Register(ModuleName, 1119, "validator not in active set") ErrNoPoolAccount = errors.Register(ModuleName, 1120, "sender has no pool account") )