From 627dd7698812bae147d1d3ce2e9f704ce618daf2 Mon Sep 17 00:00:00 2001 From: Troy Kessler Date: Fri, 27 Oct 2023 13:39:09 +0200 Subject: [PATCH] test: adjusted keeper_suite_points_test.go in bundles module --- x/bundles/keeper/keeper_suite_points_test.go | 185 ++++++++++++------- 1 file changed, 114 insertions(+), 71 deletions(-) diff --git a/x/bundles/keeper/keeper_suite_points_test.go b/x/bundles/keeper/keeper_suite_points_test.go index 536e75bf..4251501b 100644 --- a/x/bundles/keeper/keeper_suite_points_test.go +++ b/x/bundles/keeper/keeper_suite_points_test.go @@ -75,6 +75,17 @@ var _ = Describe("points", Ordered, func() { Valaddress: i.VALADDRESS_1_A, }) + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_2, + Amount: 50 * 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, @@ -105,17 +116,6 @@ var _ = Describe("points", Ordered, func() { Vote: bundletypes.VOTE_TYPE_VALID, }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_2, - Amount: 50 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_2, - PoolId: 0, - Valaddress: i.VALADDRESS_2_A, - }) - s.CommitAfterSeconds(60) }) @@ -128,8 +128,8 @@ var _ = Describe("points", Ordered, func() { // do not vote s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0_A, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -142,7 +142,7 @@ var _ = Describe("points", Ordered, func() { }) // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountVoter.Points).To(Equal(uint64(1))) }) @@ -151,8 +151,8 @@ var _ = Describe("points", Ordered, func() { // do not vote s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0_A, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -164,15 +164,10 @@ var _ = Describe("points", 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) - // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1_A, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", Vote: bundletypes.VOTE_TYPE_VALID, @@ -195,13 +190,18 @@ var _ = Describe("points", Ordered, func() { }) // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountVoter.Points).To(BeZero()) }) It("One validator does not vote for multiple proposals in a row", func() { // ACT for r := 1; r <= 3; 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, @@ -216,24 +216,32 @@ var _ = Describe("points", 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 with voter 3 - // do not vote + s.CommitAfterSeconds(60) } // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountVoter.Points).To(Equal(uint64(3))) }) It("One validator votes after having not voted previously multiple times", func() { // ARRANGE for r := 1; r <= 3; 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, @@ -248,10 +256,13 @@ var _ = Describe("points", 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) @@ -260,8 +271,8 @@ var _ = Describe("points", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1_A, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", Vote: bundletypes.VOTE_TYPE_VALID, @@ -270,8 +281,8 @@ var _ = Describe("points", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0_A, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -284,7 +295,7 @@ var _ = Describe("points", Ordered, func() { }) // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountVoter.Points).To(BeZero()) }) @@ -294,6 +305,11 @@ var _ = Describe("points", Ordered, func() { // ACT 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, @@ -308,10 +324,13 @@ var _ = Describe("points", 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) @@ -320,24 +339,29 @@ var _ = Describe("points", Ordered, func() { // ASSERT poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) - _, stakerFound := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) + _, stakerFound := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_2) Expect(stakerFound).To(BeTrue()) - _, 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()) // check if voter got slashed slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*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("One validator does not vote for multiple proposals and submits a bundle proposal", func() { // ARRANGE for r := 1; r <= 3; 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, @@ -352,10 +376,13 @@ var _ = Describe("points", 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) @@ -365,12 +392,12 @@ var _ = Describe("points", Ordered, func() { // ACT // overwrite next uploader for test purposes 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) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1_A, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -383,7 +410,7 @@ var _ = Describe("points", Ordered, func() { }) // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) // points are instantly 1 because node did not vote on this bundle, too Expect(valaccountVoter.Points).To(Equal(uint64(1))) }) @@ -391,6 +418,11 @@ var _ = Describe("points", Ordered, func() { It("One validator does not vote for multiple proposals and skip the uploader role", func() { // ARRANGE for r := 1; r <= 3; 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, @@ -405,10 +437,13 @@ var _ = Describe("points", 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) @@ -418,12 +453,12 @@ var _ = Describe("points", Ordered, func() { // ACT // overwrite next uploader for test purposes 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) s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_1_A, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, FromIndex: 400, }) @@ -438,6 +473,11 @@ var _ = Describe("points", 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, @@ -452,10 +492,13 @@ var _ = Describe("points", 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) @@ -465,12 +508,12 @@ var _ = Describe("points", Ordered, func() { // ACT // overwrite next uploader for test purposes 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) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1_A, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -483,7 +526,7 @@ var _ = Describe("points", Ordered, func() { }) // ASSERT - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) // points are instantly 1 because node did not vote on this bundle, too Expect(valaccountVoter.Points).To(Equal(uint64(1))) })