diff --git a/CHANGELOG.md b/CHANGELOG.md index 5606ef3a..a281a0f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ An '!' indicates a state machine breaking change. ### Improvements +- ! (`x/bundles`) [#142](https://github.com/KYVENetwork/chain/pull/142) Halt the pool if a single validator has more than 50% voting power. - (deps) [#33](https://github.com/KYVENetwork/chain/pull/33) Upgrade Cosmos SDK to [v0.47.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.5) ([`v0.47.5-kyve`](https://github.com/KYVENetwork/cosmos-sdk/releases/tag/v0.47.5-kyve-rc0)). ## [v1.3.1](https://github.com/KYVENetwork/chain/releases/tag/v1.3.1) - 2023-08-02 diff --git a/docs/swagger.yml b/docs/swagger.yml index ad6f0ddf..f175be1e 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -683,6 +683,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -1083,6 +1084,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED title: >- BasicPool contains the necessary properties need for a @@ -3949,6 +3951,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -4999,6 +5002,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED account: type: string @@ -5515,6 +5519,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED account: type: string @@ -5992,6 +5997,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -6421,6 +6427,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -6962,6 +6969,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -7434,6 +7442,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VOTING_POWER_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string diff --git a/proto/kyve/pool/v1beta1/pool.proto b/proto/kyve/pool/v1beta1/pool.proto index 77541e34..ac286ec3 100644 --- a/proto/kyve/pool/v1beta1/pool.proto +++ b/proto/kyve/pool/v1beta1/pool.proto @@ -10,18 +10,28 @@ option go_package = "github.com/KYVENetwork/chain/x/pool/types"; enum PoolStatus { option (gogoproto.goproto_enum_prefix) = false; - // POOL_STATUS_UNSPECIFIED ... + // POOL_STATUS_UNSPECIFIED indicates an unknown status, likely + // due to an error POOL_STATUS_UNSPECIFIED = 0; - // POOL_STATUS_ACTIVE ... + // POOL_STATUS_ACTIVE indicates, that the pool is running + // normally POOL_STATUS_ACTIVE = 1; - // POOL_STATUS_DISABLED ... + // POOL_STATUS_DISABLED indicates, that the pool was disabled + // by the governance and does not continue until it is enabled + // by the governance again POOL_STATUS_DISABLED = 2; - // POOL_STATUS_NO_FUNDS ... + // POOL_STATUS_NO_FUNDS indicates, that the pool currently has no + // funds, but is continuing normally anyway, due to inflation splitting POOL_STATUS_NO_FUNDS = 3; - // POOL_STATUS_NOT_ENOUGH_DELEGATION ... + // POOL_STATUS_NOT_ENOUGH_DELEGATION indicates, that the min delegation + // requirement has not been met and that the pool is halted POOL_STATUS_NOT_ENOUGH_DELEGATION = 4; - // POOL_STATUS_UPGRADING ... + // POOL_STATUS_UPGRADING indicates, that the runtime is currently + // being upgraded and that the pool is halted POOL_STATUS_UPGRADING = 5; + // POOL_STATUS_VOTING_POWER_TOO_HIGH indicates, that one validator + // has more than 50% voting power and that the pool is halted + POOL_STATUS_VOTING_POWER_TOO_HIGH = 6; } // Protocol holds all info about the current pool version and the diff --git a/testutil/integration/helpers.go b/testutil/integration/helpers.go index 8c691815..418bc540 100644 --- a/testutil/integration/helpers.go +++ b/testutil/integration/helpers.go @@ -36,13 +36,13 @@ func (suite *KeeperTestSuite) GetNextUploader() (nextStaker string, nextValaddre switch bundleProposal.NextUploader { case STAKER_0: nextStaker = STAKER_0 - nextValaddress = VALADDRESS_0 + nextValaddress = VALADDRESS_0_A case STAKER_1: nextStaker = STAKER_1 - nextValaddress = VALADDRESS_1 + nextValaddress = VALADDRESS_1_A case STAKER_2: nextStaker = STAKER_2 - nextValaddress = VALADDRESS_2 + nextValaddress = VALADDRESS_2_A default: nextStaker = "" nextValaddress = "" diff --git a/testutil/integration/integration.go b/testutil/integration/integration.go index 2464188d..93b65684 100644 --- a/testutil/integration/integration.go +++ b/testutil/integration/integration.go @@ -27,15 +27,27 @@ const ( ALICE = "kyve1jq304cthpx0lwhpqzrdjrcza559ukyy3zsl2vd" BOB = "kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq" CHARLIE = "kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s" + DAVID = "kyve1jxa7kp37jlm8hzwgc5qprquv9k7vawq79qhctt" - STAKER_0 = "kyve1htgfatqevuvfzvl0sxp97ywteqhg5leha9emf4" - VALADDRESS_0 = "kyve1qnf86dkvvtpdukx30r3vajav7rdq8snktm90hm" + STAKER_0 = "kyve1htgfatqevuvfzvl0sxp97ywteqhg5leha9emf4" + VALADDRESS_0_A = "kyve1qnf86dkvvtpdukx30r3vajav7rdq8snktm90hm" + VALADDRESS_0_B = "kyve10t8gnqjnem7tsu09erzswj3zm8599lsnex79rz" + VALADDRESS_0_C = "kyve13ztkcm2pket6mrmxj8rrmwc6supw7aqakg3uu3" - STAKER_1 = "kyve1gnr35rwn8rmflnlzs6nn5hhkmzzkxg9ap8xepw" - VALADDRESS_1 = "kyve1hpjgzljglmv00nstk3jvcw0zzq94nu0cuxv5ga" + STAKER_1 = "kyve1gnr35rwn8rmflnlzs6nn5hhkmzzkxg9ap8xepw" + VALADDRESS_1_A = "kyve1hpjgzljglmv00nstk3jvcw0zzq94nu0cuxv5ga" + VALADDRESS_1_B = "kyve14runw9qkltpz2mcx3gsfmlqyyvdzkt3rq3w6fm" + VALADDRESS_1_C = "kyve15w9m7zpq9ctsxsveqaqkp4uuvw98z5vct6s9g9" - STAKER_2 = "kyve1xsemlxghgvusumhqzm2ztjw7dz9krvu3de54e2" - VALADDRESS_2 = "kyve1u0870dkae6ql63hxvy9y7g65c0y8csfh8allzl" + STAKER_2 = "kyve1xsemlxghgvusumhqzm2ztjw7dz9krvu3de54e2" + VALADDRESS_2_A = "kyve1u0870dkae6ql63hxvy9y7g65c0y8csfh8allzl" + VALADDRESS_2_B = "kyve16g3utghkvvlz53jk0fq96zwrhxmqfu36ue965q" + VALADDRESS_2_C = "kyve18gjtzsn6jme3qsczj9q7wefymlkfu7ngyq5f9c" + + STAKER_3 = "kyve1ca7rzyrxfpdm7j8jgccq4rduuf4sxpq0dhmwm4" + VALADDRESS_3_A = "kyve1d2clkfrw0r99ctgmkjvluzn6xm98yls06mnxv8" + VALADDRESS_3_B = "kyve1f36cvde6jnygcrz2yas4acp0akn9cw7vp5ze0w" + VALADDRESS_3_C = "kyve1gcnd8gya2ysfur6d6z4wpl9z54zadg7qzk8uyc" // To avoid giving burner permissions to a module for the tests BURNER = "kyve1ld23ktfwc9zstaq8aanwkkj8cf0ru6adtz59y5" @@ -71,15 +83,27 @@ func (suite *KeeperTestSuite) initDummyAccounts() { _ = suite.Mint(ALICE, 1000*KYVE) _ = suite.Mint(BOB, 1000*KYVE) _ = suite.Mint(CHARLIE, 1000*KYVE) + _ = suite.Mint(DAVID, 1000*KYVE) _ = suite.Mint(STAKER_0, 1000*KYVE) - _ = suite.Mint(VALADDRESS_0, 1000*KYVE) + _ = suite.Mint(VALADDRESS_0_A, 1000*KYVE) + _ = suite.Mint(VALADDRESS_0_B, 1000*KYVE) + _ = suite.Mint(VALADDRESS_0_C, 1000*KYVE) _ = suite.Mint(STAKER_1, 1000*KYVE) - _ = suite.Mint(VALADDRESS_1, 1000*KYVE) + _ = suite.Mint(VALADDRESS_1_A, 1000*KYVE) + _ = suite.Mint(VALADDRESS_1_B, 1000*KYVE) + _ = suite.Mint(VALADDRESS_1_C, 1000*KYVE) _ = suite.Mint(STAKER_2, 1000*KYVE) - _ = suite.Mint(VALADDRESS_2, 1000*KYVE) + _ = suite.Mint(VALADDRESS_2_A, 1000*KYVE) + _ = suite.Mint(VALADDRESS_2_B, 1000*KYVE) + _ = suite.Mint(VALADDRESS_2_C, 1000*KYVE) + + _ = suite.Mint(STAKER_3, 1000*KYVE) + _ = suite.Mint(VALADDRESS_3_A, 1000*KYVE) + _ = suite.Mint(VALADDRESS_3_B, 1000*KYVE) + _ = suite.Mint(VALADDRESS_3_C, 1000*KYVE) DUMMY = make([]string, 50) diff --git a/x/bundles/keeper/abci_protocol_split_test.go b/x/bundles/keeper/abci_protocol_split_test.go index bfcf0ad1..4ee4ba3e 100644 --- a/x/bundles/keeper/abci_protocol_split_test.go +++ b/x/bundles/keeper/abci_protocol_split_test.go @@ -80,7 +80,18 @@ var _ = Describe("abci.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) b1, b2 := uint64(0), uint64(0) @@ -119,21 +130,33 @@ var _ = Describe("abci.go", Ordered, func() { Amount: 100 * i.KYVE, }) + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 100 * i.KYVE, + }) + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, + }) + + 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, + Valaddress: i.VALADDRESS_1_B, }) // ACT @@ -174,7 +197,18 @@ var _ = Describe("abci.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) // ACT diff --git a/x/bundles/keeper/keeper_suite_dropped_bundles_test.go b/x/bundles/keeper/keeper_suite_dropped_bundles_test.go index f59064dd..bc548eb3 100644 --- a/x/bundles/keeper/keeper_suite_dropped_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_dropped_bundles_test.go @@ -22,10 +22,10 @@ var _ = Describe("dropped bundles", Ordered, func() { s := i.NewCleanChain() initialBalanceStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) BeforeEach(func() { // init new clean chain @@ -60,20 +60,31 @@ var _ = Describe("dropped bundles", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) }) @@ -84,22 +95,21 @@ var _ = Describe("dropped bundles", Ordered, func() { It("Produce a dropped bundle because not enough validators voted", func() { // ARRANGE - // stake a bit more than first node so >50% is reached s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) + initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_2) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", diff --git a/x/bundles/keeper/keeper_suite_funding_bundles_test.go b/x/bundles/keeper/keeper_suite_funding_bundles_test.go index 36f10c8a..ad16c345 100644 --- a/x/bundles/keeper/keeper_suite_funding_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_funding_bundles_test.go @@ -58,7 +58,24 @@ var _ = Describe("funding bundles", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, }) }) @@ -74,16 +91,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -96,12 +107,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -148,16 +167,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -170,12 +183,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -229,16 +250,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 50 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -251,12 +266,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -310,16 +333,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -332,12 +349,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -380,16 +405,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 10, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -402,12 +421,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -449,16 +476,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 10, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -471,12 +492,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -521,16 +550,10 @@ var _ = Describe("funding bundles", Ordered, func() { Amount: 20, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -543,12 +566,20 @@ var _ = Describe("funding bundles", 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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -581,16 +612,10 @@ var _ = Describe("funding bundles", Ordered, func() { It("Produce a valid bundle although there are no funders at all", func() { // ARRANGE - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -603,6 +628,14 @@ var _ = Describe("funding bundles", 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: 1, + }) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) // assert total pool funds @@ -613,8 +646,8 @@ var _ = Describe("funding bundles", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go index 500aa90a..877d1e16 100644 --- a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -62,11 +62,22 @@ var _ = Describe("inflation splitting", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -91,7 +102,7 @@ var _ = Describe("inflation splitting", Ordered, func() { } s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -104,14 +115,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -161,7 +180,7 @@ var _ = Describe("inflation splitting", Ordered, func() { } s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -174,14 +193,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -244,7 +271,7 @@ var _ = Describe("inflation splitting", Ordered, func() { } s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -257,14 +284,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -339,7 +374,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -352,14 +387,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -433,7 +476,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -446,14 +489,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -528,7 +579,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -541,14 +592,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -623,7 +682,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -636,14 +695,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -716,7 +783,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -729,14 +796,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -811,7 +886,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -824,14 +899,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -906,7 +989,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -919,14 +1002,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -999,7 +1090,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -1012,14 +1103,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -1094,7 +1193,7 @@ var _ = Describe("inflation splitting", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -1107,14 +1206,22 @@ var _ = Describe("inflation splitting", 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: 1, + }) + s.CommitAfterSeconds(60) b1 := s.GetBalanceFromPool(0) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, diff --git a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go index 8dfc69c4..ab3f20e5 100644 --- a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go @@ -26,13 +26,13 @@ var _ = Describe("invalid bundles", Ordered, func() { s := i.NewCleanChain() initialBalanceStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) initialBalanceStaker2 := s.GetBalanceFromAddress(i.STAKER_2) - initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2) + initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2_A) BeforeEach(func() { // init new clean chain @@ -67,23 +67,34 @@ var _ = Describe("invalid bundles", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) initialBalanceStaker2 = s.GetBalanceFromAddress(i.STAKER_2) - initialBalanceValaddress2 = s.GetBalanceFromAddress(i.VALADDRESS_2) + initialBalanceValaddress2 = s.GetBalanceFromAddress(i.VALADDRESS_2_A) s.CommitAfterSeconds(60) }) @@ -95,7 +106,7 @@ var _ = Describe("invalid bundles", Ordered, func() { It("Produce an invalid bundle with multiple validators and no foreign delegations", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -108,34 +119,41 @@ var _ = Describe("invalid bundles", Ordered, func() { BundleSummary: "test_value", }) - // stake a bit more than first node so >50% is reached s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) + initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_2) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", 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, + }) + s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -184,7 +202,7 @@ var _ = Describe("invalid bundles", Ordered, func() { _, valaccountUploaderFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountUploaderFound).To(BeFalse()) - balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) @@ -214,6 +232,18 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + // check voter 2 status + valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) + Expect(valaccountVoter.Points).To(BeZero()) + + balanceVoterValaddress = s.GetBalanceFromAddress(valaccountVoter.Valaddress) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + + balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) + + Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeZero()) + // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -226,11 +256,34 @@ var _ = Describe("invalid bundles", Ordered, func() { s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ Creator: i.ALICE, Staker: i.STAKER_0, - Amount: 300 * i.KYVE, + Amount: 100 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 100 * i.KYVE, + }) + + 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.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.CHARLIE, + Staker: i.STAKER_2, + Amount: 100 * i.KYVE, }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -243,40 +296,30 @@ var _ = Describe("invalid bundles", Ordered, func() { BundleSummary: "test_value", }) - // stake a bit more than first node so >50% is reached - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, - }) - - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 300 * i.KYVE, - }) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", 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, + }) + s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -325,7 +368,7 @@ var _ = Describe("invalid bundles", Ordered, func() { _, valaccountUploaderFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountUploaderFound).To(BeFalse()) - balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) @@ -340,12 +383,12 @@ var _ = Describe("invalid bundles", Ordered, func() { // calculate uploader slashes fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmountUploader := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) - slashAmountDelegator := uint64(sdk.NewDec(int64(300 * i.KYVE)).Mul(fraction).TruncateInt64()) + slashAmountDelegator := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100*i.KYVE - slashAmountUploader)) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(300*i.KYVE - slashAmountDelegator)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(100*i.KYVE - slashAmountDelegator)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(500 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(400 * i.KYVE)) // check voter status valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -359,6 +402,18 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + // check voter 2 status + valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + Expect(valaccountVoter.Points).To(BeZero()) + + balanceVoterValaddress = s.GetBalanceFromAddress(valaccountVoter.Valaddress) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + + balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) + Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -374,54 +429,59 @@ var _ = Describe("invalid bundles", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - DataSize: 100, - DataHash: "test_hash", - FromIndex: 0, - BundleSize: 100, - FromKey: "0", - ToKey: "99", - BundleSummary: "test_value", + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 100 * i.KYVE, }) - // stake a bit more than first node so >50% is reached 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: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 500 * i.KYVE, + Creator: i.CHARLIE, + Staker: i.STAKER_2, + Amount: 100 * i.KYVE, }) - // stake less so quorum is not that affected s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_2, + Creator: i.STAKER_3, Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_2, + Creator: i.STAKER_3, PoolId: 0, - Valaddress: i.VALADDRESS_2, + Valaddress: i.VALADDRESS_3_A, }) + // delegate a bit more so invalid voters have more than 50% s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.CHARLIE, - Staker: i.STAKER_2, - Amount: 100 * i.KYVE, + Creator: i.DAVID, + Staker: i.STAKER_3, + Amount: 150 * i.KYVE, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) @@ -429,26 +489,34 @@ var _ = Describe("invalid bundles", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: bundletypes.VOTE_TYPE_INVALID, + Vote: bundletypes.VOTE_TYPE_VALID, }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_2, + Creator: i.VALADDRESS_2_A, Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: bundletypes.VOTE_TYPE_VALID, + Vote: bundletypes.VOTE_TYPE_INVALID, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_3_A, + Staker: i.STAKER_3, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_INVALID, }) s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_3_A, + Staker: i.STAKER_3, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -497,7 +565,7 @@ var _ = Describe("invalid bundles", Ordered, func() { _, valaccountUploaderFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountUploaderFound).To(BeFalse()) - balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) @@ -522,35 +590,47 @@ var _ = Describe("invalid bundles", Ordered, func() { slashAmountVoter := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) slashAmountDelegator2 := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(Equal(100*i.KYVE - slashAmountVoter)) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(Equal(100*i.KYVE - slashAmountDelegator2)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(100*i.KYVE - slashAmountVoter)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.BOB)).To(Equal(100*i.KYVE - slashAmountDelegator2)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(600 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(450 * i.KYVE)) // check voter status - valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) - Expect(valaccountVoter.Points).To(BeZero()) + _, valaccountVoterFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + Expect(valaccountVoterFound).To(BeFalse()) - balanceVoterValaddress := s.GetBalanceFromAddress(valaccountVoter.Valaddress) - Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + balanceVoterValaddress := s.GetBalanceFromAddress(i.VALADDRESS_1_A) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress2)) - balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) - Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) + Expect(balanceVoter).To(Equal(initialBalanceStaker2)) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) // check voter2 status - _, valaccountVoterFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) - Expect(valaccountVoterFound).To(BeFalse()) + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) + Expect(valaccountVoter.Points).To(BeZero()) - balanceVoterValaddress = s.GetBalanceFromAddress(i.VALADDRESS_2) - Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress2)) + balanceVoterValaddress = s.GetBalanceFromAddress(valaccountVoter.Valaddress) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) - balanceVoter = s.GetBalanceFromAddress(i.STAKER_2) - Expect(balanceVoter).To(Equal(initialBalanceStaker2)) + balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) + Expect(balanceVoter).To(Equal(initialBalanceStaker1)) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeZero()) Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) + // check voter3 status + valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_3) + Expect(valaccountVoter.Points).To(BeZero()) + + balanceVoterValaddress = s.GetBalanceFromAddress(valaccountVoter.Valaddress) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + + balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) + Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.STAKER_3)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.DAVID)).To(BeZero()) + // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_points_test.go b/x/bundles/keeper/keeper_suite_points_test.go index 0fe53c3f..4251501b 100644 --- a/x/bundles/keeper/keeper_suite_points_test.go +++ b/x/bundles/keeper/keeper_suite_points_test.go @@ -61,11 +61,33 @@ var _ = Describe("points", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, + }) + + 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -73,7 +95,7 @@ var _ = Describe("points", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -86,15 +108,12 @@ var _ = Describe("points", 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, + 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) @@ -109,8 +128,8 @@ var _ = Describe("points", Ordered, func() { // do not vote s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -123,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))) }) @@ -132,8 +151,8 @@ var _ = Describe("points", Ordered, func() { // do not vote s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -145,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, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", Vote: bundletypes.VOTE_TYPE_VALID, @@ -162,7 +176,7 @@ var _ = Describe("points", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", @@ -176,15 +190,20 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -197,26 +216,34 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -229,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) @@ -241,8 +271,8 @@ var _ = Describe("points", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", Vote: bundletypes.VOTE_TYPE_VALID, @@ -251,8 +281,8 @@ var _ = Describe("points", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -265,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()) }) @@ -275,8 +305,13 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -289,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) @@ -301,26 +339,31 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -333,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) @@ -346,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, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -364,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))) }) @@ -372,8 +418,13 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -386,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) @@ -399,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, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, FromIndex: 400, }) @@ -419,8 +473,13 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -433,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) @@ -446,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, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -464,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))) }) diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index 6250d77f..5a8af7ca 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -27,13 +27,13 @@ var _ = Describe("stakers leave", Ordered, func() { s := i.NewCleanChain() initialBalanceStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - //initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + //initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) // initialBalanceStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - //initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + //initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) // //initialBalanceStaker2 := s.GetBalanceFromAddress(i.STAKER_2) - //initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2) + //initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2_A) BeforeEach(func() { // init new clean chain @@ -68,23 +68,28 @@ var _ = Describe("stakers leave", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - //initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) - // initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - //initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) - // - //initialBalanceStaker2 = s.GetBalanceFromAddress(i.STAKER_2) - //initialBalanceValaddress2 = s.GetBalanceFromAddress(i.VALADDRESS_2) }) AfterEach(func() { @@ -94,14 +99,14 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he is the next uploader and runs into the upload timeout", func() { // ARRANGE s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 50 * i.KYVE, + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) // ACT @@ -120,13 +125,13 @@ var _ = Describe("stakers leave", Ordered, func() { // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_1)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountFound).To(BeFalse()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(50 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader got not slashed Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100 * i.KYVE)) @@ -134,10 +139,21 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he was the uploader of the previous round and should receive the uploader reward", 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.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -150,20 +166,17 @@ var _ = Describe("stakers leave", 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, + 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.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_VALID, @@ -181,7 +194,7 @@ var _ = Describe("stakers leave", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", @@ -196,18 +209,18 @@ var _ = Describe("stakers leave", 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("18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4")) // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_1)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountFound).To(BeFalse()) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(50 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader got not slashed Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100 * i.KYVE)) @@ -236,10 +249,21 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he was the uploader of the previous round and should get slashed", 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.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -252,20 +276,17 @@ var _ = Describe("stakers leave", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_INVALID, }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_INVALID, @@ -283,7 +304,7 @@ var _ = Describe("stakers leave", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", @@ -303,7 +324,7 @@ var _ = Describe("stakers leave", Ordered, func() { // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_1)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) @@ -327,10 +348,21 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he was a voter in the previous round and should get slashed", 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.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -343,41 +375,38 @@ var _ = Describe("stakers leave", 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, - }) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", 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_VALID, + }) + // leave pool s.App().StakersKeeper.RemoveValaccountFromPool(s.Ctx(), 0, i.STAKER_1) // overwrite next uploader for test purposes bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - bundleProposal.NextUploader = i.STAKER_0 + bundleProposal.NextUploader = i.STAKER_2 s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) // ACT s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", DataSize: 100, @@ -396,7 +425,7 @@ var _ = Describe("stakers leave", Ordered, func() { // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_0)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -404,10 +433,10 @@ var _ = Describe("stakers leave", Ordered, func() { // check if voter got slashed fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) - slashAmount := uint64(sdk.NewDec(int64(50 * i.KYVE)).Mul(fraction).TruncateInt64()) + slashAmount := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(50*i.KYVE - slashAmount)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(100*i.KYVE - slashAmount)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader did not receive any rewards balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) @@ -420,10 +449,21 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he was a voter in the previous round and should get a point", 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.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -436,15 +476,12 @@ var _ = Describe("stakers leave", 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, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) @@ -463,7 +500,7 @@ var _ = Describe("stakers leave", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", @@ -483,7 +520,7 @@ var _ = Describe("stakers leave", Ordered, func() { // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_0)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -491,8 +528,8 @@ var _ = Describe("stakers leave", Ordered, func() { // check if voter status - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(50 * i.KYVE)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader did not receive any rewards balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) @@ -506,14 +543,14 @@ var _ = Describe("stakers leave", Ordered, func() { It("Staker leaves, although he was a voter who did not vote max points in a row should not get slashed", func() { // ARRANGE s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 50 * i.KYVE, + Creator: i.STAKER_2, + Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) s.CommitAfterSeconds(60) @@ -521,8 +558,13 @@ var _ = Describe("stakers leave", Ordered, func() { maxPoints := int(s.App().BundlesKeeper.GetMaxPoints(s.Ctx())) for r := 0; 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -535,10 +577,13 @@ var _ = Describe("stakers leave", 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_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + Vote: bundletypes.VOTE_TYPE_VALID, + }) s.CommitAfterSeconds(60) @@ -552,7 +597,7 @@ var _ = Describe("stakers leave", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4", @@ -567,20 +612,20 @@ var _ = Describe("stakers leave", 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_2)) Expect(bundleProposal.StorageId).To(Equal("18SRvVuCrB8vy_OCLBaNbXONMVGeflGcw4gGTZ1oUt4")) // check if next uploader is still removed from pool poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) - Expect(poolStakers).To(HaveLen(1)) + Expect(poolStakers).To(HaveLen(2)) Expect(poolStakers[0]).To(Equal(i.STAKER_0)) _, valaccountFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) Expect(valaccountFound).To(BeFalse()) // check if voter not got slashed - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(50 * i.KYVE)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(100 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200 * i.KYVE)) // check if next uploader did not receive any rewards balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index 007f40ca..0d7000ae 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -16,8 +16,6 @@ import ( TEST CASES - valid bundles -* Produce a valid bundle with one validator and no foreign delegations -* Produce a valid bundle with one validator and foreign delegations * Produce a valid bundle with multiple validators and no foreign delegations * Produce a valid bundle with multiple validators and foreign delegations * Produce a valid bundle with multiple validators and foreign delegation although some did not vote at all @@ -30,10 +28,13 @@ var _ = Describe("valid bundles", Ordered, func() { s := i.NewCleanChain() initialBalanceStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) + + initialBalanceStaker2 := s.GetBalanceFromAddress(i.STAKER_2) + initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2_A) BeforeEach(func() { // init new clean chain @@ -68,20 +69,31 @@ var _ = Describe("valid bundles", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) }) @@ -90,246 +102,10 @@ var _ = Describe("valid bundles", Ordered, func() { s.PerformValidityChecks() }) - It("Produce a valid bundle with one validator and no foreign delegations", func() { - // ARRANGE - s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - DataSize: 100, - DataHash: "test_hash", - FromIndex: 0, - BundleSize: 100, - FromKey: "0", - ToKey: "99", - BundleSummary: "test_value", - }) - - s.CommitAfterSeconds(60) - - // ACT - s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", - DataSize: 100, - DataHash: "test_hash2", - FromIndex: 100, - BundleSize: 100, - FromKey: "100", - ToKey: "199", - BundleSummary: "test_value2", - }) - - // ASSERT - // check if bundle got finalized on pool - pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - Expect(poolFound).To(BeTrue()) - - Expect(pool.CurrentKey).To(Equal("99")) - Expect(pool.CurrentSummary).To(Equal("test_value")) - Expect(pool.CurrentIndex).To(Equal(uint64(100))) - Expect(pool.TotalBundles).To(Equal(uint64(1))) - - // check if finalized bundle got saved - finalizedBundle, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) - Expect(finalizedBundleFound).To(BeTrue()) - - Expect(finalizedBundle.PoolId).To(Equal(uint64(0))) - Expect(finalizedBundle.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(finalizedBundle.Uploader).To(Equal(i.STAKER_0)) - Expect(finalizedBundle.FromIndex).To(Equal(uint64(0))) - Expect(finalizedBundle.ToIndex).To(Equal(uint64(100))) - Expect(finalizedBundle.FromKey).To(Equal("0")) - Expect(finalizedBundle.ToKey).To(Equal("99")) - Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) - Expect(finalizedBundle.DataHash).To(Equal("test_hash")) - Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(100 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(100 * i.KYVE)) - - // check if next bundle proposal got registered - bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposalFound).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash2")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("100")) - Expect(bundleProposal.ToKey).To(Equal("199")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // check uploader status - valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) - Expect(valaccountUploader.Points).To(BeZero()) - - balanceValaddress := s.GetBalanceFromAddress(valaccountUploader.Valaddress) - Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) - - balanceUploader := s.GetBalanceFromAddress(valaccountUploader.Staker) - uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) - - // calculate uploader rewards - networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) - totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) - uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward - - // assert payout transfer - Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - // assert commission rewards - Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) - // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) - - // check pool funds - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) - - Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) - }) - - It("Produce a valid bundle with one validator and foreign delegations", func() { - // ARRANGE - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.ALICE, - Staker: i.STAKER_0, - Amount: 300 * i.KYVE, - }) - - s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - DataSize: 100, - DataHash: "test_hash", - FromIndex: 0, - BundleSize: 100, - FromKey: "0", - ToKey: "99", - BundleSummary: "test_value", - }) - - s.CommitAfterSeconds(60) - - // ACT - s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", - DataSize: 100, - DataHash: "test_hash2", - FromIndex: 100, - BundleSize: 100, - FromKey: "100", - ToKey: "199", - BundleSummary: "test_value2", - }) - - // ASSERT - // check if bundle got finalized on pool - pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - Expect(poolFound).To(BeTrue()) - - Expect(pool.CurrentKey).To(Equal("99")) - Expect(pool.CurrentSummary).To(Equal("test_value")) - Expect(pool.CurrentIndex).To(Equal(uint64(100))) - Expect(pool.TotalBundles).To(Equal(uint64(1))) - - // check if finalized bundle got saved - finalizedBundle, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) - Expect(finalizedBundleFound).To(BeTrue()) - - Expect(finalizedBundle.PoolId).To(Equal(uint64(0))) - Expect(finalizedBundle.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(finalizedBundle.Uploader).To(Equal(i.STAKER_0)) - Expect(finalizedBundle.FromIndex).To(Equal(uint64(0))) - Expect(finalizedBundle.ToIndex).To(Equal(uint64(100))) - Expect(finalizedBundle.FromKey).To(Equal("0")) - Expect(finalizedBundle.ToKey).To(Equal("99")) - Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) - Expect(finalizedBundle.DataHash).To(Equal("test_hash")) - Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(400 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(400 * i.KYVE)) - - // check if next bundle proposal got registered - bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposalFound).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash2")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("100")) - Expect(bundleProposal.ToKey).To(Equal("199")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // check uploader status - valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) - Expect(valaccountUploader.Points).To(BeZero()) - - balanceValaddress := s.GetBalanceFromAddress(valaccountUploader.Valaddress) - Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) - - balanceUploader := s.GetBalanceFromAddress(valaccountUploader.Staker) - uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) - - // calculate uploader rewards - networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) - totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) - totalDelegationReward := totalUploaderReward - uploaderPayoutReward - - // divide with 4 because uploader only has 25% of total delegation - uploaderDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(4)).TruncateInt64()) - delegatorDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(4)).Mul(sdk.NewDec(3)).TruncateInt64()) - - // assert payout transfer - Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - // assert commission rewards - Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) - // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) - // assert delegator delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) - - // check pool funds - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) - - Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) - }) - It("Produce a valid bundle with multiple validators and no foreign delegations", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -342,19 +118,8 @@ var _ = Describe("valid bundles", 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, - }) - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -362,14 +127,14 @@ var _ = Describe("valid bundles", Ordered, func() { }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -414,7 +179,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.NextUploader).NotTo(BeEmpty()) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) @@ -423,7 +188,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) @@ -471,16 +236,22 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) - It("Produce a valid bundle with one validator and foreign delegations", func() { + It("Produce a valid bundle with multiple validators and foreign delegations", func() { // ARRANGE s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ Creator: i.ALICE, Staker: i.STAKER_0, - Amount: 200 * i.KYVE, + Amount: 300 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 300 * i.KYVE, }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -493,25 +264,8 @@ var _ = Describe("valid bundles", 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, - }) - - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 300 * i.KYVE, - }) - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -519,14 +273,14 @@ var _ = Describe("valid bundles", Ordered, func() { }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -562,8 +316,8 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) Expect(finalizedBundle.DataHash).To(Equal("test_hash")) Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(700 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(700 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(800 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(800 * i.KYVE)) // check if next bundle proposal got registered bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) @@ -571,7 +325,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.NextUploader).NotTo(BeEmpty()) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) @@ -580,7 +334,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) @@ -614,8 +368,8 @@ var _ = Describe("valid bundles", Ordered, func() { totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation - uploaderDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(3)).TruncateInt64()) - delegatorDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(3)).Mul(sdk.NewDec(2)).TruncateInt64()) + uploaderDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(4)).TruncateInt64()) + delegatorDelegationReward := uint64(sdk.NewDec(int64(totalDelegationReward)).Quo(sdk.NewDec(4)).Mul(sdk.NewDec(3)).TruncateInt64()) // assert payout transfer Expect(balanceUploader).To(Equal(initialBalanceStaker0)) @@ -651,8 +405,31 @@ var _ = Describe("valid bundles", Ordered, func() { Amount: 300 * i.KYVE, }) + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 300 * i.KYVE, + }) + + 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.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.CHARLIE, + Staker: i.STAKER_2, + Amount: 300 * i.KYVE, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -665,32 +442,23 @@ var _ = Describe("valid bundles", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, - }) - - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 100 * i.KYVE, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -726,8 +494,8 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) Expect(finalizedBundle.DataHash).To(Equal("test_hash")) Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(400 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(700 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(800 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(1200 * i.KYVE)) // check if next bundle proposal got registered bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) @@ -735,7 +503,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) @@ -744,7 +512,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) @@ -759,7 +527,7 @@ var _ = Describe("valid bundles", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) // check voter status - 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))) balanceVoterValaddress := s.GetBalanceFromAddress(valaccountVoter.Valaddress) @@ -768,7 +536,6 @@ var _ = Describe("valid bundles", Ordered, func() { balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - // calculate uploader rewards // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) @@ -792,7 +559,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -809,8 +576,31 @@ var _ = Describe("valid bundles", Ordered, func() { Amount: 300 * i.KYVE, }) + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 300 * i.KYVE, + }) + + 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.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.CHARLIE, + Staker: i.STAKER_2, + Amount: 300 * i.KYVE, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -823,40 +613,31 @@ var _ = Describe("valid bundles", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, - }) - - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 100 * i.KYVE, + 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.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_ABSTAIN, }) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -892,8 +673,8 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) Expect(finalizedBundle.DataHash).To(Equal("test_hash")) Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(400 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(700 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(800 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(1200 * i.KYVE)) // check if next bundle proposal got registered bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) @@ -901,7 +682,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) @@ -910,7 +691,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) @@ -958,7 +739,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -975,8 +756,31 @@ var _ = Describe("valid bundles", Ordered, func() { Amount: 300 * i.KYVE, }) + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.BOB, + Staker: i.STAKER_1, + Amount: 300 * i.KYVE, + }) + + 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.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.CHARLIE, + Staker: i.STAKER_2, + Amount: 300 * i.KYVE, + }) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -989,40 +793,31 @@ var _ = Describe("valid bundles", Ordered, func() { BundleSummary: "test_value", }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, - }) - - s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ - Creator: i.BOB, - Staker: i.STAKER_1, - Amount: 100 * i.KYVE, + 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.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_INVALID, }) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceStaker2 = s.GetBalanceFromAddress(i.STAKER_2) + initialBalanceValaddress2 = s.GetBalanceFromAddress(i.VALADDRESS_2_A) s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -1058,8 +853,8 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) Expect(finalizedBundle.DataHash).To(Equal("test_hash")) Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) - Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(400 * i.KYVE)) - Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(700 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(800 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(1200 * i.KYVE)) // check if next bundle proposal got registered bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) @@ -1067,8 +862,8 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).NotTo(BeEmpty()) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -1076,7 +871,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) @@ -1092,25 +887,24 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate voter slashes fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) - slashAmountVoter := uint64(sdk.NewDec(int64(200 * i.KYVE)).Mul(fraction).TruncateInt64()) - slashAmountDelegator := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) + slashAmountVoter := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) + slashAmountDelegator := uint64(sdk.NewDec(int64(300 * i.KYVE)).Mul(fraction).TruncateInt64()) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(200*i.KYVE - slashAmountVoter)) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.BOB)).To(Equal(100*i.KYVE - slashAmountDelegator)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(Equal(100*i.KYVE - slashAmountVoter)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(Equal(300*i.KYVE - slashAmountDelegator)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(400 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(800 * i.KYVE)) // check voter status - _, valaccountVoterFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + _, valaccountVoterFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) Expect(valaccountVoterFound).To(BeFalse()) - balanceVoterValaddress := s.GetBalanceFromAddress(i.VALADDRESS_1) - Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + balanceVoterValaddress := s.GetBalanceFromAddress(i.VALADDRESS_2_A) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress2)) - balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) - Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + balanceVoter := s.GetBalanceFromAddress(i.STAKER_2) + Expect(balanceVoter).To(Equal(initialBalanceStaker2)) - // calculate uploader rewards // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) @@ -1134,7 +928,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 79504765..92068a9d 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -27,10 +27,13 @@ var _ = Describe("zero delegation", Ordered, func() { s := i.NewCleanChain() initialBalanceStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) + + // initialBalanceStaker2 := s.GetBalanceFromAddress(i.STAKER_2) + // initialBalanceValaddress2 := s.GetBalanceFromAddress(i.VALADDRESS_2_A) BeforeEach(func() { // init new clean chain @@ -75,11 +78,22 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -87,7 +101,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -100,22 +114,30 @@ var _ = Describe("zero delegation", 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, + }) + // create zero delegation validator s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, Amount: 0 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_VALID, @@ -123,15 +145,15 @@ var _ = Describe("zero delegation", Ordered, func() { bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersInvalid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_1)) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_2)) + Expect(bundleProposal.VotersInvalid).NotTo(ContainElement(i.STAKER_2)) + Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_2)) s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", DataSize: 100, @@ -160,11 +182,22 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -172,7 +205,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -187,36 +220,44 @@ var _ = Describe("zero delegation", Ordered, func() { // create zero delegation validator s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, Amount: 0 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_2_A, }) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + 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_INVALID, }) bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.VotersValid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersInvalid).To(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_1)) + Expect(bundleProposal.VotersValid).NotTo(ContainElement(i.STAKER_2)) + Expect(bundleProposal.VotersInvalid).To(ContainElement(i.STAKER_2)) + Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_2)) s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", DataSize: 100, @@ -236,9 +277,9 @@ var _ = Describe("zero delegation", Ordered, func() { // calculate voter slashes fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) slashAmountVoter := uint64(sdk.NewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) - Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(0*i.KYVE - slashAmountVoter)) + Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(Equal(0*i.KYVE - slashAmountVoter)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100*i.KYVE - slashAmountVoter)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200*i.KYVE - slashAmountVoter)) }) It("Staker submit bundle proposal with zero delegation", func() { @@ -252,7 +293,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) // create normal validator @@ -264,11 +305,23 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, + }) + + // create normal validator + 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -276,7 +329,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -290,24 +343,32 @@ var _ = Describe("zero delegation", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", 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, + }) + s.CommitAfterSeconds(60) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -352,7 +413,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_2)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -416,7 +477,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) // create normal validator @@ -428,11 +489,23 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, + }) + + // create normal validator + 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -440,7 +513,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -454,24 +527,32 @@ var _ = Describe("zero delegation", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", 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, + }) + s.CommitAfterSeconds(60) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -521,7 +602,7 @@ var _ = Describe("zero delegation", Ordered, func() { _, valaccountUploaderFound := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) Expect(valaccountUploaderFound).To(BeFalse()) - balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceValaddress := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(balanceValaddress).To(Equal(initialBalanceValaddress0)) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) @@ -536,7 +617,7 @@ var _ = Describe("zero delegation", Ordered, func() { slashAmount := uint64(sdk.NewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(0*i.KYVE - slashAmount)) - Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100*i.KYVE - slashAmount)) + Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(200*i.KYVE - slashAmount)) // check voter status valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -568,11 +649,35 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + }) + + // create zero delegation validator + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 0 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 0, + Valaddress: i.VALADDRESS_1_A, + }) + + // create normal validator + 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -580,7 +685,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -593,16 +698,12 @@ var _ = Describe("zero delegation", Ordered, func() { BundleSummary: "test_value", }) - // create zero delegation validator - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 0 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, }) s.CommitAfterSeconds(60) @@ -611,8 +712,13 @@ var _ = Describe("zero delegation", Ordered, func() { maxPoints := int(s.App().BundlesKeeper.GetMaxPoints(s.Ctx())) 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -625,10 +731,13 @@ var _ = Describe("zero delegation", 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_2_A, + Staker: i.STAKER_2, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + Vote: bundletypes.VOTE_TYPE_VALID, + }) s.CommitAfterSeconds(60) @@ -637,7 +746,7 @@ var _ = Describe("zero delegation", 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) Expect(stakerFound).To(BeTrue()) @@ -662,7 +771,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ @@ -673,11 +782,11 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -685,7 +794,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -699,7 +808,7 @@ var _ = Describe("zero delegation", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -707,10 +816,10 @@ var _ = Describe("zero delegation", Ordered, func() { }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) // manually set next staker bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index f29812c4..9a726bd1 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -28,11 +28,19 @@ func (k Keeper) AssertPoolCanRun(ctx sdk.Context, poolId uint64) error { return types.ErrPoolDisabled } + // Get the total and the highest delegation of a single validator in the pool + totalDelegation, highestDelegation := k.delegationKeeper.GetTotalAndHighestDelegationOfPool(ctx, poolId) + // Error if min delegation is not reached - if k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) < pool.MinDelegation { + if totalDelegation < pool.MinDelegation { return types.ErrMinDelegationNotReached } + // Error if the top staker has more than 50% + if highestDelegation*2 > totalDelegation { + return types.ErrVotingPowerTooHigh + } + return nil } diff --git a/x/bundles/keeper/logic_bundles_test.go b/x/bundles/keeper/logic_bundles_test.go index a4c4a98a..4eb58182 100644 --- a/x/bundles/keeper/logic_bundles_test.go +++ b/x/bundles/keeper/logic_bundles_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "cosmossdk.io/errors" i "github.com/KYVENetwork/chain/testutil/integration" bundlesTypes "github.com/KYVENetwork/chain/x/bundles/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" @@ -16,6 +17,7 @@ TEST CASES - logic_bundles.go * Assert pool can run while pool is upgrading * Assert pool can run while pool is disabled * Assert pool can run while min delegation is not reached +* Assert pool can run while voting power of one node is too high * Assert pool can run * Assert pool can run while pool has no funds @@ -83,7 +85,19 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) @@ -91,7 +105,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrPoolCurrentlyUpgrading)) }) It("Assert pool can run while pool is disabled", func() { @@ -102,7 +116,6 @@ var _ = Describe("logic_bundles.go", Ordered, func() { OperatingCost: 2 * i.KYVE, MinDelegation: 100 * i.KYVE, MaxBundleSize: 100, - Disabled: true, Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", @@ -122,11 +135,35 @@ var _ = Describe("logic_bundles.go", Ordered, func() { Amount: 100 * i.KYVE, }) + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, + Amount: 0, + }) + + // disable pool + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + pool.Disabled = true + s.App().PoolKeeper.SetPool(s.Ctx(), pool) + // ACT err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrPoolDisabled)) }) It("Assert pool can run while min delegation is not reached", func() { @@ -153,13 +190,25 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_0, - Amount: 99 * i.KYVE, + Amount: 20 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 20 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 0, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) @@ -167,10 +216,10 @@ var _ = Describe("logic_bundles.go", Ordered, func() { err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrMinDelegationNotReached)) }) - It("Assert pool can run", func() { + It("Assert pool can run while voting power of one node is too high", func() { // ASSERT s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ Name: "PoolTest", @@ -200,7 +249,72 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 101 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 0, + Valaddress: i.VALADDRESS_1_A, + Amount: 0, + }) + + // ACT + err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0) + + // ASSERT + Expect(err).To(Equal(bundlesTypes.ErrVotingPowerTooHigh)) + }) + + It("Assert pool can run", func() { + // ASSERT + s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ + Name: "PoolTest", + UploadInterval: 60, + OperatingCost: 2 * i.KYVE, + MinDelegation: 100 * i.KYVE, + MaxBundleSize: 100, + Protocol: &pooltypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &pooltypes.UpgradePlan{}, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_0, + Amount: 50 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) @@ -235,7 +349,19 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) @@ -278,12 +404,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -291,7 +429,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -307,15 +445,15 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, + Creator: i.STAKER_2, Amount: 100 * i.KYVE, }) // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_2, i.VALADDRESS_2_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(stakertypes.ErrValaccountUnauthorized)) }) It("Assert can vote if bundle is dropped", func() { @@ -348,12 +486,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -361,7 +511,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -374,27 +524,15 @@ var _ = Describe("logic_bundles.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, - Amount: 0, - }) - s.CommitAfterSeconds(60) s.CommitAfterSeconds(s.App().BundlesKeeper.GetUploadTimeout(s.Ctx())) s.CommitAfterSeconds(1) // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrBundleDropped)) }) It("Assert can vote if storage id does not match", func() { @@ -427,12 +565,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -440,7 +590,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "another_storage_id", @@ -455,23 +605,11 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) - 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, - Amount: 0, - }) - // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrInvalidStorageId)) }) It("Assert can vote if sender has already voted valid", func() { @@ -504,12 +642,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -517,7 +667,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -532,31 +682,19 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) - 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, - Amount: 0, - }) - s.RunTxBundlesSuccess(&bundlesTypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: 1, + Vote: bundlesTypes.VOTE_TYPE_VALID, }) // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrAlreadyVotedValid)) }) It("Assert can vote if sender has already voted invalid", func() { @@ -589,12 +727,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -602,7 +752,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -617,31 +767,19 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) - 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, - Amount: 0, - }) - s.RunTxBundlesSuccess(&bundlesTypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: 2, + Vote: bundlesTypes.VOTE_TYPE_INVALID, }) // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(bundlesTypes.ErrAlreadyVotedInvalid)) }) It("Assert can vote", func() { @@ -674,12 +812,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -687,7 +837,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundlesTypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -702,20 +852,8 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) - 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, - Amount: 0, - }) - // ACT - err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") + err := s.App().BundlesKeeper.AssertCanVote(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI") // ASSERT Expect(err).NotTo(HaveOccurred()) @@ -753,12 +891,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -766,10 +916,10 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) // ACT - err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, 0) + err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_2, i.VALADDRESS_2_A, 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(stakertypes.ErrValaccountUnauthorized)) }) It("Assert can propose if sender is not next uploader", func() { @@ -802,16 +952,10 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) - s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_1, Amount: 100 * i.KYVE, @@ -820,17 +964,23 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) + s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, + }) + s.CommitAfterSeconds(60) // ACT - err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1, 0) + err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_1, i.VALADDRESS_1_A, 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(errors.Wrapf(bundlesTypes.ErrNotDesignatedUploader, "expected %v received %v", i.STAKER_0, i.STAKER_1).Error())) }) It("Assert can propose if upload interval has not passed", func() { @@ -863,12 +1013,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -876,10 +1038,13 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(30) // ACT - err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0, 0) + err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0_A, 0) // ASSERT - Expect(err).To(HaveOccurred()) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + + Expect(err.Error()).To(Equal(errors.Wrapf(bundlesTypes.ErrUploadInterval, "expected %v < %v", s.Ctx().BlockTime().Unix(), bundleProposal.UpdatedAt+pool.UploadInterval).Error())) }) It("Assert can propose if index does not match", func() { @@ -912,12 +1077,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -925,10 +1102,13 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) // ACT - err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0, 1000) + err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0_A, 1000) // ASSERT - Expect(err).To(HaveOccurred()) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + + Expect(err.Error()).To(Equal(errors.Wrapf(bundlesTypes.ErrFromIndex, "expected %v received %v", pool.CurrentIndex+bundleProposal.BundleSize, 1000).Error())) }) It("Assert can propose", func() { @@ -961,12 +1141,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundlesTypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -974,7 +1166,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.CommitAfterSeconds(60) // ACT - err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0, 0) + err := s.App().BundlesKeeper.AssertCanPropose(s.Ctx(), 0, i.STAKER_0, i.VALADDRESS_0_A, 0) // ASSERT Expect(err).NotTo(HaveOccurred()) 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 d78ce528..b024e258 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,8 @@ 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 +* Next uploader gets removed due to pool having one node with more than 50% voting power * 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 @@ -73,7 +74,18 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) }) @@ -84,7 +96,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { It("Next uploader can stay although pool ran out of funds", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -104,34 +116,42 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -156,25 +176,27 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - pool.Disabled = true - s.App().PoolKeeper.SetPool(s.Ctx(), pool) // ACT @@ -186,17 +208,21 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -204,7 +230,50 @@ 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())) + s.CommitAfterSeconds(1) + + // ACT + s.CommitAfterSeconds(1) + + // ASSERT + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + Expect(bundleProposal.NextUploader).To(BeEmpty()) + Expect(bundleProposal.StorageId).To(BeEmpty()) + + poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) + 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(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("Next uploader gets removed due to pool having one node with more than 50% voting power", func() { + // ARRANGE + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, + }) + + s.RunTxDelegatorSuccess(&delegationtypes.MsgDelegate{ + Creator: i.STAKER_0, + Staker: i.STAKER_0, + Amount: 1 * i.KYVE, }) s.CommitAfterSeconds(s.App().DelegationKeeper.GetUnbondingDelegationTime(s.Ctx())) @@ -219,17 +288,21 @@ 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(101 * 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 interval and timeout does not pass", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -243,17 +316,21 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -268,17 +345,21 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -290,12 +371,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 +385,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 @@ -314,7 +395,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { It("Staker is next uploader of bundle proposal and upload interval does not pass", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -322,7 +403,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -335,26 +416,38 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -362,7 +455,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -375,27 +468,39 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -403,7 +508,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -416,6 +521,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,26 +541,37 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -455,7 +579,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -468,15 +592,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, + 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,8 +605,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(), 0) + bundleProposal.NextUploader = i.STAKER_0 + s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -498,19 +624,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,28 +654,28 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -554,7 +683,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -567,23 +696,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, - }) - // 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,12 +710,16 @@ 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() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -605,7 +727,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -618,17 +740,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, - }) - // ACT s.CommitAfterSeconds(60) s.CommitAfterSeconds(1) @@ -655,12 +766,27 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -668,7 +794,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -681,19 +807,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, - }) - // 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,28 +816,42 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -730,7 +859,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -743,27 +872,24 @@ 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, + 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.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + 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 +898,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,8 +921,19 @@ 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, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -801,7 +941,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -814,20 +954,17 @@ 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, + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_INVALID, }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_INVALID, @@ -843,17 +980,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 +1021,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, + Valaddress: i.VALADDRESS_2_B, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, }) @@ -904,7 +1053,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -917,15 +1066,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, + 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 +1079,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, + Creator: i.VALADDRESS_1_B, Staker: i.STAKER_1, PoolId: 1, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", @@ -947,10 +1098,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 +1123,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 +1137,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))) }) diff --git a/x/bundles/keeper/msg_server_claim_uploader_role_test.go b/x/bundles/keeper/msg_server_claim_uploader_role_test.go index eec9c553..ea2f9d08 100644 --- a/x/bundles/keeper/msg_server_claim_uploader_role_test.go +++ b/x/bundles/keeper/msg_server_claim_uploader_role_test.go @@ -39,14 +39,7 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { }, UpgradePlan: &pooltypes.UpgradePlan{}, }) - }) - - AfterEach(func() { - s.PerformValidityChecks() - }) - It("Try to claim uploader role without pool being funded", func() { - // ARRANGE s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_0, Amount: 100 * i.KYVE, @@ -55,12 +48,31 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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() { + s.PerformValidityChecks() + }) + + It("Try to claim uploader role without pool being funded", func() { + // ARRANGE // ACT s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -80,8 +92,8 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_2_A, + Staker: i.STAKER_2, PoolId: 0, }) @@ -98,20 +110,9 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_0, - PoolId: 0, - Valaddress: i.VALADDRESS_0, - }) - // ACT s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -144,20 +145,9 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_0, - PoolId: 0, - Valaddress: i.VALADDRESS_0, - }) - // ACT s.RunTxBundlesError(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -185,20 +175,15 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { UpgradePlan: &pooltypes.UpgradePlan{}, }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, - }) - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_B, }) // ACT s.RunTxBundlesError(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_B, Staker: i.STAKER_0, PoolId: 0, }) @@ -216,37 +201,15 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_0, - PoolId: 0, - Valaddress: i.VALADDRESS_0, - }) - - 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, - }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) // ACT s.RunTxBundlesError(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, }) diff --git a/x/bundles/keeper/msg_server_skip_uploader_role_test.go b/x/bundles/keeper/msg_server_skip_uploader_role_test.go index d06df361..1a01a3f4 100644 --- a/x/bundles/keeper/msg_server_skip_uploader_role_test.go +++ b/x/bundles/keeper/msg_server_skip_uploader_role_test.go @@ -15,7 +15,6 @@ TEST CASES - msg_server_skip_uploader_role.go * Skip uploader role on data bundle if staker is next uploader * Skip uploader on data bundle after uploader role has already been skipped -* Skip uploader on data bundle if staker is the only staker in pool * Skip uploader role on dropped bundle */ @@ -55,11 +54,22 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -67,7 +77,7 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -87,23 +97,12 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { It("Skip uploader role on data bundle if staker is next uploader", func() { // ARRANGE - 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, - }) - s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, FromIndex: 100, }) @@ -127,70 +126,25 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { Expect(bundleProposal.VotersAbstain).To(BeEmpty()) // here the next uploader should be always be different after skipping - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) }) It("Skip uploader on data bundle after uploader role has already been skipped", func() { // ARRANGE - 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, - }) - - s.CommitAfterSeconds(60) - - s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - FromIndex: 100, - }) - s.CommitAfterSeconds(60) - // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, FromIndex: 100, }) - // ASSERT - bundleProposal, found := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(found).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("0")) - Expect(bundleProposal.ToKey).To(Equal("99")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // here the next uploader should be always be different after skipping - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - }) - - It("Skip uploader on data bundle if staker is the only staker in pool", func() { - // ARRANGE s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, FromIndex: 100, @@ -214,22 +168,12 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + // here the next uploader should be always be different after skipping + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) }) It("Skip uploader role on dropped bundle", func() { // ARRANGE - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ - Creator: i.STAKER_1, - Amount: 200 * i.KYVE, - }) - - s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, - PoolId: 0, - Valaddress: i.VALADDRESS_1, - }) - // create dropped bundle s.CommitAfterSeconds(60) s.CommitAfterSeconds(1) @@ -239,7 +183,7 @@ var _ = Describe("msg_server_skip_uploader_role.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSkipUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, FromIndex: 0, diff --git a/x/bundles/keeper/msg_server_submit_bundle_proposal_test.go b/x/bundles/keeper/msg_server_submit_bundle_proposal_test.go index afc891ba..32e3fcae 100644 --- a/x/bundles/keeper/msg_server_submit_bundle_proposal_test.go +++ b/x/bundles/keeper/msg_server_submit_bundle_proposal_test.go @@ -62,11 +62,22 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -82,7 +93,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "", @@ -108,7 +119,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -134,7 +145,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -160,7 +171,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -186,7 +197,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -212,7 +223,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -238,7 +249,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -258,7 +269,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.DataSize).To(BeZero()) Expect(bundleProposal.DataHash).To(Equal("test_hash")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -277,7 +288,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -297,7 +308,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(BeEmpty()) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -316,7 +327,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -336,7 +347,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -355,7 +366,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -375,7 +386,7 @@ var _ = Describe("msg_server_submit_bundle_proposal.go", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) diff --git a/x/bundles/keeper/msg_server_vote_bundle_proposal_test.go b/x/bundles/keeper/msg_server_vote_bundle_proposal_test.go index 082983ce..9db0c936 100644 --- a/x/bundles/keeper/msg_server_vote_bundle_proposal_test.go +++ b/x/bundles/keeper/msg_server_vote_bundle_proposal_test.go @@ -14,9 +14,6 @@ import ( TEST CASES - msg_server_vote_bundle_proposal.go -* Try to vote valid as the only voter on bundle proposal -* Try to vote invalid as the only voter on bundle proposal -* Try to vote abstain as the only voter on bundle proposal * Try to vote abstain on proposal again * Try to vote valid on proposal after abstain vote * Try to vote invalid on proposal after abstain vote @@ -57,17 +54,28 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -79,81 +87,16 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { ToKey: "99", 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, - }) }) AfterEach(func() { s.PerformValidityChecks() }) - It("Try to vote valid as the only voter on bundle proposal", func() { - // ACT - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: bundletypes.VOTE_TYPE_VALID, - }) - - // ASSERT - bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersInvalid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_1)) - }) - - It("Try to vote invalid as the only voter on bundle proposal", func() { - // ACT - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: bundletypes.VOTE_TYPE_INVALID, - }) - - // ASSERT - bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - - Expect(bundleProposal.VotersValid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersInvalid).To(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersAbstain).NotTo(ContainElement(i.STAKER_1)) - }) - - It("Try to vote abstain as the only voter on bundle proposal", func() { - // ACT - s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, - PoolId: 0, - StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", - Vote: bundletypes.VOTE_TYPE_ABSTAIN, - }) - - // ASSERT - bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - - Expect(bundleProposal.VotersValid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersInvalid).NotTo(ContainElement(i.STAKER_1)) - Expect(bundleProposal.VotersAbstain).To(ContainElement(i.STAKER_1)) - }) - It("Try to vote abstain on proposal again", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -162,7 +105,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesError(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -180,7 +123,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { It("Try to vote valid on proposal after abstain vote", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -189,7 +132,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -207,7 +150,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { It("Try to vote invalid on proposal after abstain vote", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -216,7 +159,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -234,7 +177,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { It("Try to vote unspecified on proposal", func() { // ACT s.RunTxBundlesError(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -259,11 +202,11 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_2, PoolId: 0, - Valaddress: i.VALADDRESS_2, + Valaddress: i.VALADDRESS_2_A, }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -272,7 +215,7 @@ var _ = Describe("msg_server_vote_bundle_proposal.go", Ordered, func() { // ACT s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_2, + Creator: i.VALADDRESS_2_A, Staker: i.STAKER_2, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", diff --git a/x/bundles/types/errors.go b/x/bundles/types/errors.go index bacc1e93..b6530677 100644 --- a/x/bundles/types/errors.go +++ b/x/bundles/types/errors.go @@ -23,4 +23,5 @@ var ( ErrAlreadyVotedValid = errors.Register(ModuleName, 1204, "already voted valid on bundle proposal") ErrAlreadyVotedInvalid = errors.Register(ModuleName, 1205, "already voted invalid on bundle proposal") ErrAlreadyVotedAbstain = errors.Register(ModuleName, 1206, "already voted abstain on bundle proposal") + ErrVotingPowerTooHigh = errors.Register(ModuleName, 1207, "staker in pool has more than 50% voting power") ) diff --git a/x/bundles/types/expected_keepers.go b/x/bundles/types/expected_keepers.go index cec3a1c1..b6102fa2 100644 --- a/x/bundles/types/expected_keepers.go +++ b/x/bundles/types/expected_keepers.go @@ -58,6 +58,7 @@ type StakerKeeper interface { type DelegationKeeper interface { GetDelegationAmount(ctx sdk.Context, staker string) uint64 GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 + GetTotalAndHighestDelegationOfPool(ctx sdk.Context, poolId uint64) (uint64, uint64) PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) error SlashDelegators(ctx sdk.Context, poolId uint64, staker string, slashType delegationTypes.SlashType) } diff --git a/x/delegation/keeper/exported_functions.go b/x/delegation/keeper/exported_functions.go index aa87037a..16bd9bc1 100644 --- a/x/delegation/keeper/exported_functions.go +++ b/x/delegation/keeper/exported_functions.go @@ -42,6 +42,22 @@ func (k Keeper) GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 { return totalDelegation } +// GetTotalAndHighestDelegationOfPool returns the total delegation amount of all validators in the given pool and +// the highest total delegation amount of a single validator in a pool +func (k Keeper) GetTotalAndHighestDelegationOfPool(ctx sdk.Context, poolId uint64) (totalDelegation, highestDelegation uint64) { + // Get the total delegation and the highest delegation of a staker in the pool + for _, address := range k.stakersKeeper.GetAllStakerAddressesOfPool(ctx, poolId) { + delegation := k.GetDelegationAmount(ctx, address) + totalDelegation += delegation + + if delegation > highestDelegation { + highestDelegation = delegation + } + } + + return +} + // PayoutRewards transfers `amount` $nKYVE from the `payerModuleName`-module to the delegation module. // It then awards these tokens internally to all delegators of staker `staker`. // Delegators can then receive these rewards if they call the `withdraw`-transaction. diff --git a/x/delegation/keeper/msg_server_redelegate_test.go b/x/delegation/keeper/msg_server_redelegate_test.go index 43dc8361..4a0d2997 100644 --- a/x/delegation/keeper/msg_server_redelegate_test.go +++ b/x/delegation/keeper/msg_server_redelegate_test.go @@ -59,7 +59,7 @@ var _ = Describe("Delegation - Redelegation", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.BOB, PoolId: 1, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) diff --git a/x/delegation/keeper/msg_server_undelegate_test.go b/x/delegation/keeper/msg_server_undelegate_test.go index f6565711..a91d99b9 100644 --- a/x/delegation/keeper/msg_server_undelegate_test.go +++ b/x/delegation/keeper/msg_server_undelegate_test.go @@ -63,7 +63,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.BOB, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) diff --git a/x/global/ante_test.go b/x/global/ante_test.go index 785407e7..b283bf50 100644 --- a/x/global/ante_test.go +++ b/x/global/ante_test.go @@ -290,7 +290,8 @@ var _ = Describe("GasAdjustmentDecorator", Ordered, func() { encodingConfig := BuildEncodingConfig() // NOTE: This will change as implementation changes. - BaseCost := 32079 + // TODO: Why does this change as the implementation changes? + BaseCost := 32109 BeforeEach(func() { s = i.NewCleanChain() diff --git a/x/pool/keeper/msg_server_disable_pool_test.go b/x/pool/keeper/msg_server_disable_pool_test.go index 25251059..1ad74def 100644 --- a/x/pool/keeper/msg_server_disable_pool_test.go +++ b/x/pool/keeper/msg_server_disable_pool_test.go @@ -350,7 +350,7 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) @@ -362,7 +362,7 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) @@ -418,14 +418,14 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_2, + Valaddress: i.VALADDRESS_2_A, Amount: 0, }) @@ -437,7 +437,7 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) @@ -493,12 +493,24 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, + Amount: 0, + }) + + 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, Amount: 0, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -506,7 +518,7 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", diff --git a/x/pool/types/pool.pb.go b/x/pool/types/pool.pb.go index 27ae02e5..11ccca00 100644 --- a/x/pool/types/pool.pb.go +++ b/x/pool/types/pool.pb.go @@ -27,18 +27,28 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type PoolStatus int32 const ( - // POOL_STATUS_UNSPECIFIED ... + // POOL_STATUS_UNSPECIFIED indicates an unknown status, likely + // due to an error POOL_STATUS_UNSPECIFIED PoolStatus = 0 - // POOL_STATUS_ACTIVE ... + // POOL_STATUS_ACTIVE indicates, that the pool is running + // normally POOL_STATUS_ACTIVE PoolStatus = 1 - // POOL_STATUS_DISABLED ... + // POOL_STATUS_DISABLED indicates, that the pool was disabled + // by the governance and does not continue until it is enabled + // by the governance again POOL_STATUS_DISABLED PoolStatus = 2 - // POOL_STATUS_NO_FUNDS ... + // POOL_STATUS_NO_FUNDS indicates, that the pool currently has no + // funds, but is continuing normally anyway, due to inflation splitting POOL_STATUS_NO_FUNDS PoolStatus = 3 - // POOL_STATUS_NOT_ENOUGH_DELEGATION ... + // POOL_STATUS_NOT_ENOUGH_DELEGATION indicates, that the min delegation + // requirement has not been met and that the pool is halted POOL_STATUS_NOT_ENOUGH_DELEGATION PoolStatus = 4 - // POOL_STATUS_UPGRADING ... + // POOL_STATUS_UPGRADING indicates, that the runtime is currently + // being upgraded and that the pool is halted POOL_STATUS_UPGRADING PoolStatus = 5 + // POOL_STATUS_VOTING_POWER_TOO_HIGH indicates, that one validator + // has more than 50% voting power and that the pool is halted + POOL_STATUS_VOTING_POWER_TOO_HIGH PoolStatus = 6 ) var PoolStatus_name = map[int32]string{ @@ -48,6 +58,7 @@ var PoolStatus_name = map[int32]string{ 3: "POOL_STATUS_NO_FUNDS", 4: "POOL_STATUS_NOT_ENOUGH_DELEGATION", 5: "POOL_STATUS_UPGRADING", + 6: "POOL_STATUS_VOTING_POWER_TOO_HIGH", } var PoolStatus_value = map[string]int32{ @@ -57,6 +68,7 @@ var PoolStatus_value = map[string]int32{ "POOL_STATUS_NO_FUNDS": 3, "POOL_STATUS_NOT_ENOUGH_DELEGATION": 4, "POOL_STATUS_UPGRADING": 5, + "POOL_STATUS_VOTING_POWER_TOO_HIGH": 6, } func (x PoolStatus) String() string { @@ -504,59 +516,60 @@ func init() { func init() { proto.RegisterFile("kyve/pool/v1beta1/pool.proto", fileDescriptor_40c1730f47ff2ef8) } var fileDescriptor_40c1730f47ff2ef8 = []byte{ - // 818 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x6f, 0xdb, 0x36, - 0x14, 0xc7, 0xad, 0xc4, 0x75, 0x6c, 0x3a, 0x71, 0x5c, 0x2e, 0xcd, 0xd8, 0x64, 0xf0, 0xdc, 0x0c, - 0xdd, 0xbc, 0x1d, 0x6c, 0xb4, 0x1d, 0x30, 0x60, 0xc0, 0x0e, 0x8e, 0xed, 0x64, 0x42, 0x03, 0xdb, - 0x90, 0xed, 0x02, 0xdb, 0x45, 0xa0, 0x45, 0x56, 0x21, 0x22, 0x91, 0x02, 0x49, 0x79, 0x71, 0x8f, - 0x3b, 0xed, 0xb8, 0xef, 0xd0, 0xcf, 0xb1, 0xfb, 0x8e, 0x3d, 0xee, 0x38, 0x24, 0x5f, 0x64, 0x20, - 0x25, 0x79, 0xee, 0xd6, 0x53, 0x6f, 0x7c, 0xbf, 0xff, 0xff, 0xe9, 0x3d, 0xf3, 0xf1, 0x19, 0x7c, - 0x76, 0xb3, 0x5e, 0xd1, 0x5e, 0x22, 0x44, 0xd4, 0x5b, 0x3d, 0x5b, 0x52, 0x8d, 0x9f, 0xd9, 0xa0, - 0x9b, 0x48, 0xa1, 0x05, 0x7c, 0x68, 0xd4, 0xae, 0x05, 0xb9, 0x7a, 0x72, 0x14, 0x8a, 0x50, 0x58, - 0xb5, 0x67, 0x4e, 0x99, 0xf1, 0x2c, 0x00, 0xd5, 0xa9, 0x39, 0x04, 0x22, 0x82, 0x08, 0xec, 0xad, - 0xa8, 0x54, 0x4c, 0x70, 0xe4, 0xb4, 0x9d, 0x4e, 0xcd, 0x2b, 0x42, 0x78, 0x02, 0xaa, 0x4b, 0xc6, - 0xb1, 0x64, 0x54, 0xa1, 0x1d, 0x2b, 0x6d, 0x62, 0xf8, 0x04, 0xec, 0x47, 0x58, 0x69, 0x3f, 0x4d, - 0x42, 0x89, 0x09, 0x45, 0xbb, 0x6d, 0xa7, 0x53, 0xf6, 0xea, 0x86, 0x2d, 0x32, 0x74, 0xf6, 0xab, - 0x03, 0xea, 0xf9, 0x79, 0x1a, 0x61, 0xfe, 0xf1, 0x85, 0x54, 0x70, 0x4d, 0x49, 0x1a, 0x51, 0xe2, - 0x63, 0x5d, 0x14, 0xda, 0xb0, 0xbe, 0x36, 0xe9, 0x24, 0x95, 0x58, 0x9b, 0x2f, 0x97, 0xad, 0xbc, - 0x89, 0xcf, 0xbe, 0x07, 0x95, 0x8b, 0x94, 0x13, 0x2a, 0x4d, 0x79, 0x4c, 0x88, 0xa4, 0x4a, 0x15, - 0xe5, 0xf3, 0x10, 0x1e, 0x83, 0x0a, 0x8e, 0x45, 0xca, 0xb5, 0x2d, 0x5e, 0xf6, 0xf2, 0xe8, 0xec, - 0x6d, 0x05, 0x94, 0xa7, 0x42, 0x44, 0xb0, 0x01, 0x76, 0x18, 0xb1, 0x59, 0x65, 0x6f, 0x87, 0x11, - 0x08, 0x41, 0x99, 0xe3, 0x98, 0xe6, 0xbd, 0xda, 0xb3, 0xf9, 0xbc, 0x4c, 0xb9, 0x66, 0x71, 0x76, - 0x17, 0x35, 0xaf, 0x08, 0x8d, 0x3b, 0x12, 0xa1, 0xb0, 0xad, 0xd5, 0x3c, 0x7b, 0x36, 0x25, 0x03, - 0xc1, 0x5f, 0xb3, 0x10, 0x3d, 0xb0, 0x34, 0x8f, 0xe0, 0x29, 0xa8, 0x29, 0x8d, 0xa5, 0xf6, 0x6f, - 0xe8, 0x1a, 0x55, 0xb2, 0xab, 0xb0, 0xe0, 0x25, 0x5d, 0xc3, 0xcf, 0x41, 0x3d, 0x48, 0xa5, 0xa4, - 0x3c, 0x93, 0xf7, 0xac, 0x0c, 0x72, 0x64, 0x0c, 0x5f, 0x81, 0xc3, 0xc2, 0xa0, 0xd2, 0x38, 0xc6, - 0x72, 0x8d, 0xaa, 0xd6, 0xd4, 0xc8, 0xf1, 0x2c, 0xa3, 0xf0, 0x0b, 0x70, 0x50, 0x18, 0x19, 0x27, - 0xf4, 0x16, 0xd5, 0xec, 0x6f, 0xdb, 0xcf, 0xa1, 0x6b, 0x98, 0x31, 0x69, 0xa1, 0x71, 0xe4, 0x2f, - 0x53, 0x4e, 0x22, 0xaa, 0x10, 0xc8, 0x4c, 0x16, 0x9e, 0x67, 0xcc, 0x94, 0x4c, 0x93, 0x48, 0x60, - 0xe2, 0x33, 0xae, 0xa9, 0x5c, 0xe1, 0x08, 0xd5, 0xad, 0xad, 0x91, 0x61, 0x37, 0xa7, 0xf0, 0x29, - 0x68, 0x88, 0x84, 0x9a, 0xa9, 0xf0, 0xd0, 0x0f, 0x84, 0xd2, 0x68, 0xdf, 0xfa, 0x0e, 0x36, 0x74, - 0x20, 0x94, 0x36, 0xb6, 0x98, 0x71, 0x9f, 0xd0, 0x88, 0x86, 0xd9, 0x44, 0x0f, 0x32, 0x5b, 0xcc, - 0xf8, 0x70, 0x03, 0xe1, 0x97, 0xe0, 0x30, 0xc6, 0xb7, 0x79, 0x67, 0xbe, 0x62, 0x6f, 0x28, 0x6a, - 0xe4, 0x3e, 0x7c, 0x9b, 0xf5, 0x36, 0x63, 0x6f, 0xa8, 0x7d, 0x1a, 0x4c, 0xe1, 0x65, 0x44, 0x09, - 0x3a, 0x6c, 0x3b, 0x9d, 0xaa, 0xb7, 0x89, 0xe1, 0x0b, 0xb0, 0xf7, 0xda, 0x3e, 0x0d, 0x85, 0x9a, - 0xed, 0xdd, 0x4e, 0xfd, 0xf9, 0xe3, 0xee, 0xff, 0xf6, 0xa7, 0x9b, 0x3d, 0x1e, 0xaf, 0x70, 0x9a, - 0x19, 0x64, 0x97, 0x62, 0x80, 0x42, 0x0f, 0x6d, 0x51, 0x60, 0x91, 0xb1, 0x2a, 0xf8, 0x1d, 0xa8, - 0x26, 0xf9, 0x6a, 0x21, 0xd8, 0x76, 0x3a, 0xf5, 0xe7, 0xa7, 0x1f, 0xf8, 0x6c, 0xb1, 0x7d, 0xde, - 0xc6, 0x0c, 0xfb, 0x60, 0x3f, 0x5f, 0x26, 0x3f, 0x89, 0x30, 0x47, 0x9f, 0xd8, 0xe4, 0xd6, 0x07, - 0x92, 0xb7, 0x96, 0xca, 0xab, 0xa7, 0x5b, 0x1b, 0xf6, 0x03, 0x38, 0xdd, 0xcc, 0x5f, 0x0b, 0x89, - 0x43, 0xea, 0x27, 0x52, 0xac, 0x18, 0xa1, 0xd2, 0x67, 0x04, 0x1d, 0xb5, 0x9d, 0xce, 0x81, 0x87, - 0x8a, 0xb7, 0x90, 0x39, 0xa6, 0xb9, 0xc1, 0x25, 0xf0, 0x5b, 0x70, 0x5c, 0xa4, 0x07, 0x22, 0x4e, - 0xcc, 0x6e, 0x30, 0xc1, 0x4d, 0xe6, 0x23, 0x9b, 0x79, 0x94, 0xab, 0x83, 0x7f, 0x45, 0x97, 0x7c, - 0xf3, 0x87, 0x03, 0x80, 0xd9, 0x92, 0x99, 0xc6, 0x3a, 0x55, 0xf0, 0x14, 0x7c, 0x3a, 0x9d, 0x4c, - 0xae, 0xfc, 0xd9, 0xbc, 0x3f, 0x5f, 0xcc, 0xfc, 0xc5, 0x78, 0x36, 0x1d, 0x0d, 0xdc, 0x0b, 0x77, - 0x34, 0x6c, 0x96, 0xe0, 0x31, 0x80, 0xdb, 0x62, 0x7f, 0x30, 0x77, 0x5f, 0x8d, 0x9a, 0x0e, 0x44, - 0xe0, 0x68, 0x9b, 0x0f, 0xdd, 0x59, 0xff, 0xfc, 0x6a, 0x34, 0x6c, 0xee, 0xfc, 0x57, 0x19, 0x4f, - 0xfc, 0x8b, 0xc5, 0x78, 0x38, 0x6b, 0xee, 0xc2, 0xa7, 0xe0, 0xc9, 0xfb, 0xca, 0xdc, 0x1f, 0x8d, - 0x27, 0x8b, 0xcb, 0x1f, 0xfd, 0xe1, 0xe8, 0x6a, 0x74, 0xd9, 0x9f, 0xbb, 0x93, 0x71, 0xb3, 0x0c, - 0x1f, 0x83, 0x47, 0xef, 0xf5, 0x33, 0xbd, 0xf4, 0xfa, 0x43, 0x77, 0x7c, 0xd9, 0x7c, 0x70, 0x52, - 0xfe, 0xed, 0x6d, 0xab, 0x74, 0x3e, 0xf8, 0xf3, 0xae, 0xe5, 0xbc, 0xbb, 0x6b, 0x39, 0x7f, 0xdf, - 0xb5, 0x9c, 0xdf, 0xef, 0x5b, 0xa5, 0x77, 0xf7, 0xad, 0xd2, 0x5f, 0xf7, 0xad, 0xd2, 0xcf, 0x5f, - 0x87, 0x4c, 0x5f, 0xa7, 0xcb, 0x6e, 0x20, 0xe2, 0xde, 0xcb, 0x9f, 0x5e, 0x8d, 0xc6, 0x54, 0xff, - 0x22, 0xe4, 0x4d, 0x2f, 0xb8, 0xc6, 0x8c, 0xf7, 0x6e, 0xb3, 0xbf, 0x61, 0xbd, 0x4e, 0xa8, 0x5a, - 0x56, 0xec, 0x18, 0x5f, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0xec, 0x2d, 0x4a, 0x94, 0xa0, 0x05, - 0x00, 0x00, + // 840 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x6f, 0x22, 0x37, + 0x14, 0xc7, 0x99, 0x84, 0x25, 0x60, 0x12, 0xc2, 0xba, 0xd9, 0xd4, 0x9b, 0x54, 0x94, 0x4d, 0xb5, + 0x2d, 0xed, 0x01, 0xb4, 0xbb, 0x95, 0x2a, 0x55, 0xea, 0x81, 0x00, 0x21, 0xa3, 0x8d, 0x00, 0x0d, + 0x90, 0xaa, 0xbd, 0x58, 0x06, 0x7b, 0x27, 0x56, 0x66, 0xec, 0xd1, 0xd8, 0x43, 0xc3, 0x1e, 0x7b, + 0xea, 0xb1, 0xdf, 0x61, 0xbf, 0x4c, 0x8f, 0x7b, 0xec, 0xb1, 0x4a, 0xfa, 0x41, 0x2a, 0x7b, 0x66, + 0x68, 0x76, 0x9b, 0x53, 0x6f, 0x7e, 0xbf, 0xff, 0xff, 0xf9, 0x3d, 0xe6, 0xf9, 0x01, 0x3e, 0xbb, + 0x5e, 0xaf, 0x58, 0x27, 0x92, 0x32, 0xe8, 0xac, 0x5e, 0x2c, 0x98, 0x26, 0x2f, 0x6c, 0xd0, 0x8e, + 0x62, 0xa9, 0x25, 0x7c, 0x6c, 0xd4, 0xb6, 0x05, 0x99, 0x7a, 0x74, 0xe0, 0x4b, 0x5f, 0x5a, 0xb5, + 0x63, 0x4e, 0xa9, 0xf1, 0x64, 0x09, 0xca, 0x13, 0x73, 0x58, 0xca, 0x00, 0x22, 0xb0, 0xb3, 0x62, + 0xb1, 0xe2, 0x52, 0x20, 0xa7, 0xe9, 0xb4, 0x2a, 0x5e, 0x1e, 0xc2, 0x23, 0x50, 0x5e, 0x70, 0x41, + 0x62, 0xce, 0x14, 0xda, 0xb2, 0xd2, 0x26, 0x86, 0xcf, 0xc0, 0x6e, 0x40, 0x94, 0xc6, 0x49, 0xe4, + 0xc7, 0x84, 0x32, 0xb4, 0xdd, 0x74, 0x5a, 0x45, 0xaf, 0x6a, 0xd8, 0x3c, 0x45, 0x27, 0xbf, 0x3a, + 0xa0, 0x9a, 0x9d, 0x27, 0x01, 0x11, 0xff, 0xbf, 0x90, 0x5a, 0x5e, 0x31, 0x9a, 0x04, 0x8c, 0x62, + 0xa2, 0xf3, 0x42, 0x1b, 0xd6, 0xd5, 0x26, 0x9d, 0x26, 0x31, 0xd1, 0xe6, 0xe6, 0xa2, 0x95, 0x37, + 0xf1, 0xc9, 0xf7, 0xa0, 0x74, 0x96, 0x08, 0xca, 0x62, 0x53, 0x9e, 0x50, 0x1a, 0x33, 0xa5, 0xf2, + 0xf2, 0x59, 0x08, 0x0f, 0x41, 0x89, 0x84, 0x32, 0x11, 0xda, 0x16, 0x2f, 0x7a, 0x59, 0x74, 0xf2, + 0xae, 0x04, 0x8a, 0x13, 0x29, 0x03, 0x58, 0x03, 0x5b, 0x9c, 0xda, 0xac, 0xa2, 0xb7, 0xc5, 0x29, + 0x84, 0xa0, 0x28, 0x48, 0xc8, 0xb2, 0x5e, 0xed, 0xd9, 0x5c, 0x1f, 0x27, 0x42, 0xf3, 0x30, 0xfd, + 0x16, 0x15, 0x2f, 0x0f, 0x8d, 0x3b, 0x90, 0xbe, 0xb4, 0xad, 0x55, 0x3c, 0x7b, 0x36, 0x25, 0x97, + 0x52, 0xbc, 0xe1, 0x3e, 0x7a, 0x64, 0x69, 0x16, 0xc1, 0x63, 0x50, 0x51, 0x9a, 0xc4, 0x1a, 0x5f, + 0xb3, 0x35, 0x2a, 0xa5, 0x9f, 0xc2, 0x82, 0xd7, 0x6c, 0x0d, 0x3f, 0x07, 0xd5, 0x65, 0x12, 0xc7, + 0x4c, 0xa4, 0xf2, 0x8e, 0x95, 0x41, 0x86, 0x8c, 0xe1, 0x2b, 0xb0, 0x9f, 0x1b, 0x54, 0x12, 0x86, + 0x24, 0x5e, 0xa3, 0xb2, 0x35, 0xd5, 0x32, 0x3c, 0x4d, 0x29, 0xfc, 0x02, 0xec, 0xe5, 0x46, 0x2e, + 0x28, 0xbb, 0x41, 0x15, 0xfb, 0xdb, 0x76, 0x33, 0xe8, 0x1a, 0x66, 0x4c, 0x5a, 0x6a, 0x12, 0xe0, + 0x45, 0x22, 0x68, 0xc0, 0x14, 0x02, 0xa9, 0xc9, 0xc2, 0xd3, 0x94, 0x99, 0x92, 0x49, 0x14, 0x48, + 0x42, 0x31, 0x17, 0x9a, 0xc5, 0x2b, 0x12, 0xa0, 0xaa, 0xb5, 0xd5, 0x52, 0xec, 0x66, 0x14, 0x3e, + 0x07, 0x35, 0x19, 0x31, 0x33, 0x15, 0xe1, 0xe3, 0xa5, 0x54, 0x1a, 0xed, 0x5a, 0xdf, 0xde, 0x86, + 0xf6, 0xa4, 0xd2, 0xc6, 0x16, 0x72, 0x81, 0x29, 0x0b, 0x98, 0x9f, 0x4e, 0x74, 0x2f, 0xb5, 0x85, + 0x5c, 0xf4, 0x37, 0x10, 0x7e, 0x09, 0xf6, 0x43, 0x72, 0x93, 0x75, 0x86, 0x15, 0x7f, 0xcb, 0x50, + 0x2d, 0xf3, 0x91, 0x9b, 0xb4, 0xb7, 0x29, 0x7f, 0xcb, 0xec, 0xd3, 0xe0, 0x8a, 0x2c, 0x02, 0x46, + 0xd1, 0x7e, 0xd3, 0x69, 0x95, 0xbd, 0x4d, 0x0c, 0x5f, 0x81, 0x9d, 0x37, 0xf6, 0x69, 0x28, 0x54, + 0x6f, 0x6e, 0xb7, 0xaa, 0x2f, 0x9f, 0xb6, 0xff, 0xb3, 0x3f, 0xed, 0xf4, 0xf1, 0x78, 0xb9, 0xd3, + 0xcc, 0x20, 0xfd, 0x28, 0x06, 0x28, 0xf4, 0xd8, 0x16, 0x05, 0x16, 0x19, 0xab, 0x82, 0xdf, 0x81, + 0x72, 0x94, 0xad, 0x16, 0x82, 0x4d, 0xa7, 0x55, 0x7d, 0x79, 0xfc, 0xc0, 0xb5, 0xf9, 0xf6, 0x79, + 0x1b, 0x33, 0xec, 0x82, 0xdd, 0x6c, 0x99, 0x70, 0x14, 0x10, 0x81, 0x3e, 0xb1, 0xc9, 0x8d, 0x07, + 0x92, 0xef, 0x2d, 0x95, 0x57, 0x4d, 0xee, 0x6d, 0xd8, 0x0f, 0xe0, 0x78, 0x33, 0x7f, 0x2d, 0x63, + 0xe2, 0x33, 0x1c, 0xc5, 0x72, 0xc5, 0x29, 0x8b, 0x31, 0xa7, 0xe8, 0xa0, 0xe9, 0xb4, 0xf6, 0x3c, + 0x94, 0xbf, 0x85, 0xd4, 0x31, 0xc9, 0x0c, 0x2e, 0x85, 0xdf, 0x82, 0xc3, 0x3c, 0x7d, 0x29, 0xc3, + 0xc8, 0xec, 0x06, 0x97, 0xc2, 0x64, 0x3e, 0xb1, 0x99, 0x07, 0x99, 0xda, 0xfb, 0x57, 0x74, 0xe9, + 0x37, 0x7f, 0x3b, 0x00, 0x98, 0x2d, 0x99, 0x6a, 0xa2, 0x13, 0x05, 0x8f, 0xc1, 0xa7, 0x93, 0xf1, + 0xf8, 0x02, 0x4f, 0x67, 0xdd, 0xd9, 0x7c, 0x8a, 0xe7, 0xa3, 0xe9, 0x64, 0xd0, 0x73, 0xcf, 0xdc, + 0x41, 0xbf, 0x5e, 0x80, 0x87, 0x00, 0xde, 0x17, 0xbb, 0xbd, 0x99, 0x7b, 0x39, 0xa8, 0x3b, 0x10, + 0x81, 0x83, 0xfb, 0xbc, 0xef, 0x4e, 0xbb, 0xa7, 0x17, 0x83, 0x7e, 0x7d, 0xeb, 0x63, 0x65, 0x34, + 0xc6, 0x67, 0xf3, 0x51, 0x7f, 0x5a, 0xdf, 0x86, 0xcf, 0xc1, 0xb3, 0x0f, 0x95, 0x19, 0x1e, 0x8c, + 0xc6, 0xf3, 0xe1, 0x39, 0xee, 0x0f, 0x2e, 0x06, 0xc3, 0xee, 0xcc, 0x1d, 0x8f, 0xea, 0x45, 0xf8, + 0x14, 0x3c, 0xf9, 0xa0, 0x9f, 0xc9, 0xd0, 0xeb, 0xf6, 0xdd, 0xd1, 0xb0, 0xfe, 0xe8, 0xe3, 0x1b, + 0x2e, 0xc7, 0x33, 0x77, 0x34, 0xc4, 0x93, 0xf1, 0x8f, 0x03, 0x0f, 0xcf, 0xc6, 0x63, 0x7c, 0xee, + 0x0e, 0xcf, 0xeb, 0xa5, 0xa3, 0xe2, 0x6f, 0xef, 0x1a, 0x85, 0xd3, 0xde, 0x1f, 0xb7, 0x0d, 0xe7, + 0xfd, 0x6d, 0xc3, 0xf9, 0xeb, 0xb6, 0xe1, 0xfc, 0x7e, 0xd7, 0x28, 0xbc, 0xbf, 0x6b, 0x14, 0xfe, + 0xbc, 0x6b, 0x14, 0x7e, 0xfe, 0xda, 0xe7, 0xfa, 0x2a, 0x59, 0xb4, 0x97, 0x32, 0xec, 0xbc, 0xfe, + 0xe9, 0x72, 0x30, 0x62, 0xfa, 0x17, 0x19, 0x5f, 0x77, 0x96, 0x57, 0x84, 0x8b, 0xce, 0x4d, 0xfa, + 0x6f, 0xad, 0xd7, 0x11, 0x53, 0x8b, 0x92, 0x9d, 0xf6, 0xab, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, + 0x80, 0x23, 0xd9, 0x4f, 0xc7, 0x05, 0x00, 0x00, } func (m *Protocol) Marshal() (dAtA []byte, err error) { diff --git a/x/query/keeper/grpc_account_redelegation_test.go b/x/query/keeper/grpc_account_redelegation_test.go index 1e8f1d9c..4799af4f 100644 --- a/x/query/keeper/grpc_account_redelegation_test.go +++ b/x/query/keeper/grpc_account_redelegation_test.go @@ -61,7 +61,7 @@ var _ = Describe("grpc_account_redelegation.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) diff --git a/x/query/keeper/grpc_query_can_propose_test.go b/x/query/keeper/grpc_query_can_propose_test.go index 963a1983..0082a047 100644 --- a/x/query/keeper/grpc_query_can_propose_test.go +++ b/x/query/keeper/grpc_query_can_propose_test.go @@ -61,7 +61,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) @@ -73,12 +73,12 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -86,7 +86,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "test_storage_id", @@ -100,7 +100,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { }) s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -119,7 +119,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 1, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -130,7 +130,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(errors.Wrapf(errorsTypes.ErrNotFound, pooltypes.ErrPoolNotFound.Error(), 1).Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 1, StorageId: "test_storage_id", @@ -163,7 +163,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -174,7 +174,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(bundletypes.ErrPoolCurrentlyUpgrading.Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -202,7 +202,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -213,7 +213,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(bundletypes.ErrPoolDisabled.Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -246,7 +246,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -257,7 +257,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(bundletypes.ErrMinDelegationNotReached.Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -279,7 +279,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_0, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -290,7 +290,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(stakertypes.ErrValaccountUnauthorized.Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "test_storage_id", @@ -319,14 +319,14 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err = s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) } else { canPropose, err = s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_0, - Proposer: i.VALADDRESS_0, + Proposer: i.VALADDRESS_0_A, FromIndex: 100, }) } @@ -346,7 +346,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { if bundleProposal.NextUploader == i.STAKER_0 { _, txErr = s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -360,7 +360,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { }) } else { _, txErr = s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "test_storage_id", @@ -390,7 +390,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -403,7 +403,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(Equal(errors.Wrapf(bundletypes.ErrUploadInterval, "expected %v < %v", s.Ctx().BlockTime().Unix(), bundleProposal.UpdatedAt+pool.UploadInterval).Error())) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -425,14 +425,14 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose_1, err_1 := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 99, }) canPropose_2, err_2 := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 101, }) @@ -450,7 +450,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose_2.Reason).To(Equal(errors.Wrapf(bundletypes.ErrFromIndex, "expected %v received %v", pool.CurrentIndex+bundleProposal.BundleSize, 101).Error())) _, txErr_1 := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -467,7 +467,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(txErr_1.Error()).To(Equal(canPropose_1.Reason)) _, txErr_2 := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -489,7 +489,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -500,7 +500,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(BeEmpty()) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -528,7 +528,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ PoolId: 0, Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, + Proposer: i.VALADDRESS_1_A, FromIndex: 100, }) @@ -539,7 +539,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(canPropose.Reason).To(BeEmpty()) _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", diff --git a/x/query/keeper/grpc_query_can_validate_test.go b/x/query/keeper/grpc_query_can_validate_test.go index 89a49c41..4a7ae15e 100644 --- a/x/query/keeper/grpc_query_can_validate_test.go +++ b/x/query/keeper/grpc_query_can_validate_test.go @@ -46,7 +46,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) @@ -67,7 +67,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 1, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) }) @@ -80,7 +80,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { // ACT canValidate, err := s.App().QueryKeeper.CanValidate(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanValidateRequest{ PoolId: 2, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) // ASSERT @@ -94,7 +94,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { // ACT canValidate, err := s.App().QueryKeeper.CanValidate(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanValidateRequest{ PoolId: 0, - Valaddress: i.VALADDRESS_2, + Valaddress: i.VALADDRESS_2_A, }) // ASSERT @@ -108,7 +108,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { // ACT canValidate, err := s.App().QueryKeeper.CanValidate(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanValidateRequest{ PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, }) // ASSERT @@ -122,7 +122,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { // ACT canValidate, err := s.App().QueryKeeper.CanValidate(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanValidateRequest{ PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) // ASSERT diff --git a/x/query/keeper/grpc_query_can_vote_test.go b/x/query/keeper/grpc_query_can_vote_test.go index 1b18563b..a6e90f72 100644 --- a/x/query/keeper/grpc_query_can_vote_test.go +++ b/x/query/keeper/grpc_query_can_vote_test.go @@ -62,7 +62,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0, }) @@ -74,12 +74,12 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, }) @@ -87,7 +87,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "test_storage_id", @@ -109,7 +109,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 1, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -120,7 +120,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(errors.Wrapf(errorsTypes.ErrNotFound, pooltypes.ErrPoolNotFound.Error(), 1).Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 1, StorageId: "test_storage_id", @@ -147,7 +147,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -158,7 +158,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrPoolCurrentlyUpgrading.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -180,7 +180,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -191,7 +191,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrPoolDisabled.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -218,7 +218,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -229,7 +229,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrMinDelegationNotReached.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -245,7 +245,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_0, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -256,7 +256,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(stakertypes.ErrValaccountUnauthorized.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "test_storage_id", @@ -277,7 +277,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -288,7 +288,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrBundleDropped.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -304,7 +304,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "another_test_storage_id", }) @@ -315,7 +315,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrInvalidStorageId.Error())) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "another_test_storage_id", @@ -329,7 +329,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { It("Call can vote if voter has already voted valid", func() { // ARRANGE _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -342,7 +342,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -353,7 +353,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrAlreadyVotedValid.Error())) _, txErr = s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -367,7 +367,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { It("Call can vote if voter has already voted invalid", func() { // ARRANGE _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -380,7 +380,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -391,7 +391,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal(bundletypes.ErrAlreadyVotedInvalid.Error())) _, txErr = s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -405,7 +405,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { It("Call can vote if voter has already voted abstain", func() { // ARRANGE _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -418,7 +418,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -429,7 +429,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(Equal("KYVE_VOTE_NO_ABSTAIN_ALLOWED")) _, txErr = s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -444,7 +444,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -455,7 +455,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(BeEmpty()) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", @@ -477,7 +477,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ PoolId: 0, Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, + Voter: i.VALADDRESS_1_A, StorageId: "test_storage_id", }) @@ -488,7 +488,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(canVote.Reason).To(BeEmpty()) _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, + Creator: i.VALADDRESS_1_A, Staker: i.STAKER_1, PoolId: 0, StorageId: "test_storage_id", diff --git a/x/query/keeper/helper.go b/x/query/keeper/helper.go index 0536becd..7c95af28 100644 --- a/x/query/keeper/helper.go +++ b/x/query/keeper/helper.go @@ -82,7 +82,8 @@ func (k Keeper) GetFullStaker(ctx sdk.Context, stakerAddress string) *types.Full } func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.PoolStatus { - totalDelegation := k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) + // Get the total and the highest delegation of a single validator in the pool + totalDelegation, highestDelegation := k.delegationKeeper.GetTotalAndHighestDelegationOfPool(ctx, pool.Id) var poolStatus pooltypes.PoolStatus @@ -92,6 +93,8 @@ func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.P poolStatus = pooltypes.POOL_STATUS_DISABLED } else if totalDelegation < pool.MinDelegation { poolStatus = pooltypes.POOL_STATUS_NOT_ENOUGH_DELEGATION + } else if highestDelegation*2 > totalDelegation { + poolStatus = pooltypes.POOL_STATUS_VOTING_POWER_TOO_HIGH } else if pool.TotalFunds == 0 { poolStatus = pooltypes.POOL_STATUS_NO_FUNDS } else { diff --git a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go index 8c9b578b..902a933c 100644 --- a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go +++ b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go @@ -56,7 +56,24 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_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, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) @@ -68,16 +85,10 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { Amount: 100 * i.KYVE, }) - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", @@ -90,12 +101,20 @@ var _ = Describe("msg_server_claim_commission_rewards.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: 1, + }) + s.CommitAfterSeconds(60) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -280,14 +299,21 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { Expect(s.GetBalanceFromAddress(i.STAKER_0)).To(Equal(initialBalanceStaker0 + 100)) // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + Vote: 1, + }) + s.CommitAfterSeconds(60) - // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_0, + Creator: i.VALADDRESS_0_A, Staker: i.STAKER_0, PoolId: 0, - StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + StorageId: "SsdTPx9adtpwAGIjiHilqVPEfoTiq7eRw6khbVxKetQ", DataSize: 100, DataHash: "test_hash3", FromIndex: 200, @@ -297,6 +323,30 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { BundleSummary: "test_value3", }) + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "SsdTPx9adtpwAGIjiHilqVPEfoTiq7eRw6khbVxKetQ", + Vote: 1, + }) + + s.CommitAfterSeconds(60) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "iW1jN99yH_gdQtRhf5J_lVwOIu8p_i7FyxEgoQAkWxU", + DataSize: 100, + DataHash: "test_hash4", + FromIndex: 300, + BundleSize: 100, + FromKey: "300", + ToKey: "399", + BundleSummary: "test_value4", + }) + _, err = s.RunTx(&stakertypes.MsgClaimCommissionRewards{ Creator: i.STAKER_0, Amount: 200, diff --git a/x/stakers/keeper/msg_server_join_pool_test.go b/x/stakers/keeper/msg_server_join_pool_test.go index 841327b5..cf7f3ec5 100644 --- a/x/stakers/keeper/msg_server_join_pool_test.go +++ b/x/stakers/keeper/msg_server_join_pool_test.go @@ -68,10 +68,10 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { }) initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0) + initialBalanceValaddress0 = s.GetBalanceFromAddress(i.VALADDRESS_0_A) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) - initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) }) AfterEach(func() { @@ -89,13 +89,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) // ASSERT balanceAfterStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(initialBalanceStaker0 - balanceAfterStaker0).To(Equal(100 * i.KYVE)) Expect(balanceAfterValaddress0 - initialBalanceValaddress0).To(Equal(100 * i.KYVE)) @@ -110,7 +110,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeFalse()) @@ -136,13 +136,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0 * i.KYVE, }) // ASSERT balanceAfterStaker1 := s.GetBalanceFromAddress(i.STAKER_1) - balanceAfterValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1) + balanceAfterValaddress1 := s.GetBalanceFromAddress(i.VALADDRESS_1_A) Expect(initialBalanceStaker1).To(Equal(balanceAfterStaker1)) Expect(initialBalanceValaddress1).To(Equal(balanceAfterValaddress1)) @@ -157,7 +157,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_1)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_1)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_1_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeFalse()) @@ -189,7 +189,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { _, err := s.RunTx(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -197,7 +197,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { // ASSERT balanceAfterStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(initialBalanceStaker0 - balanceAfterStaker0).To(Equal(0 * i.KYVE)) Expect(balanceAfterValaddress0 - initialBalanceValaddress0).To(Equal(0 * i.KYVE)) @@ -232,7 +232,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0 * i.KYVE, }) @@ -240,13 +240,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 0 * i.KYVE, }) // ASSERT balanceAfterStaker0 := s.GetBalanceFromAddress(i.STAKER_0) - balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0) + balanceAfterValaddress0 := s.GetBalanceFromAddress(i.VALADDRESS_0_A) Expect(initialBalanceStaker0 - balanceAfterStaker0).To(BeZero()) Expect(balanceAfterValaddress0 - initialBalanceValaddress0).To(BeZero()) @@ -261,7 +261,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeFalse()) @@ -281,7 +281,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -306,7 +306,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeFalse()) @@ -327,7 +327,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -335,7 +335,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -365,7 +365,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -373,7 +373,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 100 * i.KYVE, }) @@ -388,7 +388,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -406,7 +406,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -435,7 +435,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 1, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 100 * i.KYVE, }) @@ -443,7 +443,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 100 * i.KYVE, }) @@ -457,7 +457,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -470,7 +470,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -484,7 +484,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 100 * i.KYVE, }) @@ -502,7 +502,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, }) // ASSERT @@ -629,7 +629,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 1, }) @@ -658,7 +658,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 1, }) @@ -674,7 +674,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 1, }) @@ -703,7 +703,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 1, }) @@ -720,7 +720,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 1 * i.KYVE, }) @@ -755,7 +755,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 1, }) @@ -772,7 +772,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 1, }) @@ -801,7 +801,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 1, }) @@ -818,7 +818,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, Amount: 1 * i.KYVE, }) @@ -853,7 +853,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { s.RunTxStakersError(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 0, }) diff --git a/x/stakers/keeper/msg_server_leave_pool_test.go b/x/stakers/keeper/msg_server_leave_pool_test.go index bc05b851..9df61b6e 100644 --- a/x/stakers/keeper/msg_server_leave_pool_test.go +++ b/x/stakers/keeper/msg_server_leave_pool_test.go @@ -49,7 +49,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 0, - Valaddress: i.VALADDRESS_0, + Valaddress: i.VALADDRESS_0_A, }) }) @@ -76,7 +76,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeTrue()) @@ -122,7 +122,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_1, PoolId: 0, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, Amount: 100 * i.KYVE, }) @@ -144,7 +144,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(BeZero()) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_0_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeTrue()) @@ -221,7 +221,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ Creator: i.STAKER_0, PoolId: 1, - Valaddress: i.VALADDRESS_1, + Valaddress: i.VALADDRESS_1_A, }) s.PerformValidityChecks() @@ -242,7 +242,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { Expect(valaccount.Staker).To(Equal(i.STAKER_0)) Expect(valaccount.PoolId).To(Equal(uint64(1))) - Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_1)) + Expect(valaccount.Valaddress).To(Equal(i.VALADDRESS_1_A)) Expect(valaccount.Points).To(BeZero()) Expect(valaccount.IsLeaving).To(BeTrue())