diff --git a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go index 3da652f6..12bfc593 100644 --- a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go +++ b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go @@ -19,7 +19,7 @@ TEST CASES - logic_end_block_handle_upload_timeout.go * First staker who joins gets automatically chosen as next uploader * Next uploader gets removed due to pool upgrading * Next uploader gets removed due to pool being disabled -* Next uploader gets removed due to pool not reaching min stake +* Next uploader gets removed due to pool not reaching min delegation * Staker is next uploader of genesis bundle and upload interval and timeout does not pass * Staker is next uploader of genesis bundle and upload timeout does not pass but upload interval passes * Staker is next uploader of genesis bundle and upload timeout does pass together with upload interval @@ -75,6 +75,17 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { PoolId: 0, Valaddress: i.VALADDRESS_0_A, }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 0, + Valaddress: i.VALADDRESS_1_A, + }) }) AfterEach(func() { @@ -104,28 +115,36 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) - It("First staker who joins gets automatically chosen as next uploader", func() { + It("Last staker who joins gets automatically chosen as next uploader", func() { // ACT s.CommitAfterSeconds(1) // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Next uploader gets removed due to pool upgrading", func() { @@ -156,11 +175,15 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Next uploader gets removed due to pool being disabled", func() { @@ -172,9 +195,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { }) pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - pool.Disabled = true - s.App().PoolKeeper.SetPool(s.Ctx(), pool) // ACT @@ -186,14 +207,18 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) - It("Next uploader gets removed due to pool not reaching min stake", func() { + It("Next uploader gets removed due to pool not reaching min delegation", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0_A, @@ -204,7 +229,13 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.RunTxDelegatorSuccess(&delegationtypes.MsgUndelegate{ Creator: i.STAKER_0, Staker: i.STAKER_0, - Amount: 50 * i.KYVE, + Amount: 80 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&delegationtypes.MsgUndelegate{ + Creator: i.STAKER_1, + Staker: i.STAKER_1, + Amount: 80 * i.KYVE, }) s.CommitAfterSeconds(s.App().DelegationKeeper.GetUnbondingDelegationTime(s.Ctx())) @@ -219,11 +250,15 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(50 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(20 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(20 * i.KYVE)) }) It("Staker is next uploader of genesis bundle and upload interval and timeout does not pass", func() { @@ -243,11 +278,15 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Staker is next uploader of genesis bundle and upload timeout does not pass but upload interval passes", func() { @@ -268,11 +307,15 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Staker is next uploader of genesis bundle and upload timeout does pass together with upload interval", func() { @@ -290,12 +333,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.StorageId).To(BeEmpty()) // check if next uploader got not removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) // check if next uploader received a point valaccount, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) @@ -304,7 +347,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed expectedBalance := 100 * i.KYVE @@ -335,20 +378,32 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + // ACT s.CommitAfterSeconds(1) // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Staker is next uploader of bundle proposal and upload timeout does not pass", func() { @@ -375,21 +430,33 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + // ACT s.CommitAfterSeconds(60) s.CommitAfterSeconds(1) // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Staker is next uploader of bundle proposal and upload timeout passes", func() { @@ -416,6 +483,14 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + // ACT s.CommitAfterSeconds(s.App().BundlesKeeper.GetUploadTimeout(s.Ctx())) s.CommitAfterSeconds(60) @@ -428,24 +503,35 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // check if next uploader got not removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) // check if next uploader received a point - valaccount, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) + valaccount, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) Expect(valaccount.Points).To(Equal(uint64(1))) - _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed expectedBalance := 100 * i.KYVE - Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0))) + Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) }) It("Staker with already max points is next uploader of bundle proposal and upload timeout passes", func() { // ARRANGE + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_2, + PoolId: 0, + Valaddress: i.VALADDRESS_2_A, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, @@ -468,15 +554,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 50 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, }) s.CommitAfterSeconds(60) @@ -484,6 +567,11 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { maxPoints := int(s.App().BundlesKeeper.GetMaxPoints(s.Ctx())) - 1 for r := 1; r <= maxPoints; r++ { + // overwrite next uploader for test purposes + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + bundleProposal.NextUploader = i.STAKER_0 + s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, @@ -498,19 +586,22 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - // overwrite next uploader for test purposes - bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - bundleProposal.NextUploader = i.STAKER_0 - s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + Vote: bundletypes.VOTE_TYPE_VALID, + }) s.CommitAfterSeconds(60) // do not vote } - // overwrite next uploader with staker_1 + // overwrite next uploader with staker_2 bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - bundleProposal.NextUploader = i.STAKER_1 + bundleProposal.NextUploader = i.STAKER_2 s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) // ACT @@ -525,22 +616,22 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // check if next uploader got not removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) // check if next uploader received a point - _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountFound).To(BeFalse()) - _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_2) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) - expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) + expectedBalance := 100*i.KYVE - uint64(sdk.NewDec(int64(100*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) - Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) + Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2))) }) It("A bundle proposal with no quorum does not reach the upload interval", func() { @@ -567,23 +658,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, - }) - // ACT s.CommitAfterSeconds(1) // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) @@ -592,6 +672,10 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("A bundle proposal with no quorum does reach the upload interval", func() { @@ -618,17 +702,6 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, - }) - // ACT s.CommitAfterSeconds(60) s.CommitAfterSeconds(1) @@ -655,10 +728,25 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) + + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + Expect(found).To(BeTrue()) + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_1)).To(Equal(100 * i.KYVE)) }) It("Staker who just left the pool is next uploader of dropped bundle proposal and upload timeout passes", func() { // ARRANGE + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_2, + PoolId: 0, + Valaddress: i.VALADDRESS_2_A, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, @@ -681,19 +769,8 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, - }) - // remove valaccount directly from pool - s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_0) + s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_1) // ACT s.CommitAfterSeconds(60) @@ -701,26 +778,40 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.StorageId).To(BeEmpty()) // check if next uploader got removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_2) + Expect(found).To(BeTrue()) + + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed expectedBalance := 100 * i.KYVE - Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0))) + Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) }) It("Staker who just left the pool is next uploader of valid bundle proposal and upload timeout passes", func() { // ARRANGE + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_2, + PoolId: 0, + Valaddress: i.VALADDRESS_2_A, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, @@ -743,17 +834,6 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, - }) - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, @@ -762,8 +842,16 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Vote: bundletypes.VOTE_TYPE_VALID, }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + // remove valaccount directly from pool - s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_0) + s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_1) // ACT s.CommitAfterSeconds(s.App().BundlesKeeper.GetUploadTimeout(s.Ctx())) @@ -772,17 +860,20 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) // check if next uploader got removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + _, found = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_2) + Expect(found).To(BeTrue()) + + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed expectedBalance := 100 * i.KYVE @@ -792,6 +883,17 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { It("Staker who just left the pool is next uploader of invalid bundle proposal and upload timeout passes", func() { // ARRANGE + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_2, + PoolId: 0, + Valaddress: i.VALADDRESS_2_A, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, @@ -814,17 +916,6 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1_A, - }) - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, @@ -833,6 +924,14 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Vote: bundletypes.VOTE_TYPE_INVALID, }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_INVALID, + }) + // remove valaccount directly from pool s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_0) @@ -843,17 +942,17 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_2)) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) // check if next uploader got removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed expectedBalance := 100 * i.KYVE @@ -884,19 +983,31 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Amount: 100 * i.KYVE, }) + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 1, + Valaddress: i.VALADDRESS_0_B, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 1, + Valaddress: i.VALADDRESS_1_B, + }) + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 1, - Valaddress: i.VALADDRESS_1_A, + Valaddress: i.VALADDRESS_2_B, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_1_A, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, }) @@ -904,7 +1015,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1_A, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -917,15 +1028,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_2, - Amount: 50 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_2, - PoolId: 1, - Valaddress: i.VALADDRESS_2_A, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_0_B, + Staker: i.STAKER_0, + PoolId: 1, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, }) s.CommitAfterSeconds(60) @@ -933,8 +1041,13 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { maxPoints := int(s.App().BundlesKeeper.GetMaxPoints(s.Ctx())) - 1 for r := 1; r <= maxPoints; r++ { + // overwrite next uploader for test purposes + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 1) + bundleProposal.NextUploader = i.STAKER_1 + s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1_A, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -947,10 +1060,13 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { BundleSummary: "test_value", }) - // overwrite next uploader for test purposes - bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 1) - bundleProposal.NextUploader = i.STAKER_1 - s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_0_B, + Staker: i.STAKER_0, + PoolId: 1, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + Vote: bundletypes.VOTE_TYPE_VALID, + }) s.CommitAfterSeconds(60) @@ -969,12 +1085,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { // ASSERT bundleProposal, _ = s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 1) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) // check if next uploader got not removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 1) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) // check if next uploader received a point _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 1, i.STAKER_2) @@ -983,11 +1099,11 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { _, found := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_2) Expect(found).To(BeTrue()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 1)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 1)).To(Equal(200 * i.KYVE)) // check if next uploader not got slashed slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) - expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) + expectedBalance := 100*i.KYVE - uint64(sdk.NewDec(int64(100*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2))) })