Skip to content

Commit

Permalink
chore: implemented setter method for max pool stake
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Dec 20, 2024
1 parent 7a81510 commit 08de954
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 48 deletions.
6 changes: 6 additions & 0 deletions testutil/integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ func (suite *KeeperTestSuite) GetNextUploader() (nextStaker string, nextValaddre

return
}

func (suite *KeeperTestSuite) SetMaxVotingPower(maxVotingPower string) {
params := suite.App().PoolKeeper.GetParams(suite.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr(maxVotingPower)
suite.App().PoolKeeper.SetParams(suite.Ctx(), params)
}
4 changes: 1 addition & 3 deletions x/bundles/keeper/keeper_suite_invalid_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ var _ = Describe("invalid bundles", Ordered, func() {
}
s.RunTxPoolSuccess(msg)

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

s.RunTxFundersSuccess(&funderstypes.MsgCreateFunder{
Creator: i.ALICE,
Expand Down
4 changes: 1 addition & 3 deletions x/bundles/keeper/keeper_suite_valid_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,7 @@ var _ = Describe("valid bundles", Ordered, func() {

It("Produce a valid bundle with multiple validators and foreign delegation although some voted invalid with maximum voting power", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.4")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.4")

s.CreateValidator(i.STAKER_2, "Staker-2", int64(100*i.KYVE))

Expand Down
8 changes: 2 additions & 6 deletions x/bundles/keeper/logic_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {

It("Assert pool can run while voting power of one node exceeds 40%", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.4")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.4")

msg := &pooltypes.MsgCreatePool{
Authority: gov,
Expand Down Expand Up @@ -371,9 +369,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {

It("Assert pool can run with a single staker while voting power is 100%", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

msg := &pooltypes.MsgCreatePool{
Authority: gov,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() {
PoolId: 0,
})

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.2")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.2")

// ACT
s.CommitAfterSeconds(1)
Expand Down
8 changes: 2 additions & 6 deletions x/bundles/keeper/logic_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ var _ = Describe("logic_round_robin.go", Ordered, func() {
}
s.App().PoolKeeper.SetPool(s.Ctx(), pool)

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")
})

AfterEach(func() {
Expand Down Expand Up @@ -269,9 +267,7 @@ var _ = Describe("logic_round_robin.go", Ordered, func() {

It("Frequency analysis with maximum voting power cap", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.5")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.5")

// NOTE that dummy with index 2 has more than 50% voting power, so his effective stake
// will be lower
Expand Down
24 changes: 6 additions & 18 deletions x/stakers/keeper/keeper_suite_effective_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {
}
s.RunTxPoolSuccess(msg)

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.5")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.5")
})

AfterEach(func() {
Expand Down Expand Up @@ -147,9 +145,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {

It("Test effective stake with multiple validators above the max pool voting power", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.35")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.35")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(600*i.KYVE))
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down Expand Up @@ -193,9 +189,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {

It("Test effective stake with fewer validators than required to undercut the max pool voting power", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.2")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.2")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down Expand Up @@ -315,9 +309,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {

It("Test effective stake with 0% as max pool stake", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down Expand Up @@ -357,9 +349,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {

It("Test effective stake with 100% as max pool stake", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down Expand Up @@ -467,9 +457,7 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() {

It("Test effective stake with multiple validators above the max pool voting power due to stake fractions", func() {
// ARRANGE
params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("0.35")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("0.35")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down
4 changes: 1 addition & 3 deletions x/stakers/keeper/msg_server_join_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {
}
s.RunTxPoolSuccess(msg)

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))

Expand Down
4 changes: 1 addition & 3 deletions x/stakers/keeper/msg_server_leave_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() {
// create staker
s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

// join pool
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down
4 changes: 1 addition & 3 deletions x/stakers/keeper/msg_server_update_stake_fraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ var _ = Describe("msg_server_update_stake_fraction.go", Ordered, func() {
}
s.RunTxPoolSuccess(msg)

params := s.App().PoolKeeper.GetParams(s.Ctx())
params.MaxVotingPowerPerPool = math.LegacyMustNewDecFromStr("1")
s.App().PoolKeeper.SetParams(s.Ctx(), params)
s.SetMaxVotingPower("1")

s.CreateValidator(i.STAKER_0, "Staker-0", int64(100*i.KYVE))

Expand Down

0 comments on commit 08de954

Please sign in to comment.