Skip to content

Commit

Permalink
fix: tests in x/stakers
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Oct 3, 2023
1 parent 5961096 commit cd57ba5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 75 deletions.
21 changes: 10 additions & 11 deletions x/stakers/keeper/exported_functions_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
pooltypes "github.com/KYVENetwork/chain/x/pool/types"
"strconv"

kyveApp "github.com/KYVENetwork/chain/app"
Expand All @@ -14,8 +15,7 @@ import (
delegationTypes "github.com/KYVENetwork/chain/x/delegation/types"
// Gov
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
// Pool
poolTypes "github.com/KYVENetwork/chain/x/pool/types"

// Stakers
stakersTypes "github.com/KYVENetwork/chain/x/stakers/types"
)
Expand Down Expand Up @@ -56,15 +56,14 @@ var _ = Describe("Protocol Governance Voting", Ordered, func() {
_ = s.RunTxSuccess(createTx)

// Create and join a pool.
s.App().PoolKeeper.AppendPool(s.Ctx(), poolTypes.Pool{
Name: "Cosmos Hub",
Protocol: &poolTypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &poolTypes.UpgradePlan{},
})
gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String()
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

joinTx := &stakersTypes.MsgJoinPool{
Creator: i.ALICE,
Expand Down
87 changes: 41 additions & 46 deletions x/stakers/keeper/msg_server_join_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {
initialBalanceStaker1 := uint64(0)
initialBalanceValaddress1 := uint64(0)

gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String()

BeforeEach(func() {
// init new clean chain
s = i.NewCleanChain()

// create pool
s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "PoolTest",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

// create staker
s.RunTxStakersSuccess(&stakerstypes.MsgCreateStaker{
Expand Down Expand Up @@ -174,16 +174,17 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {

It("Join disabled pool", func() {
// ARRANGE
s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "DisabledPool",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
Disabled: true,
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 1)
pool.Disabled = true
s.App().PoolKeeper.SetPool(s.Ctx(), pool)

// ACT
_, err := s.RunTx(&stakerstypes.MsgJoinPool{
Expand Down Expand Up @@ -392,15 +393,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {
Amount: 100 * i.KYVE,
})

s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "Test Pool2",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

// ACT
s.RunTxStakersError(&stakerstypes.MsgJoinPool{
Expand All @@ -417,15 +416,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {

It("Try to join pool with a valaddress that is already used by another staker", func() {
// ARRANGE
s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "Test Pool2",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

s.RunTxStakersSuccess(&stakerstypes.MsgCreateStaker{
Creator: i.STAKER_1,
Expand Down Expand Up @@ -488,15 +485,13 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() {
Amount: 100 * i.KYVE,
})

s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "Test Pool2",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

// ACT
s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Expand Down
33 changes: 15 additions & 18 deletions x/stakers/keeper/msg_server_leave_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ TEST CASES - msg_server_leave_pool.go

var _ = Describe("msg_server_leave_pool.go", Ordered, func() {
s := i.NewCleanChain()
gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String()

BeforeEach(func() {
// init new clean chain
s = i.NewCleanChain()

// create pool
s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "PoolTest",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

// create staker
s.RunTxStakersSuccess(&stakerstypes.MsgCreateStaker{
Expand Down Expand Up @@ -208,15 +207,13 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() {

It("Leave one of multiple pools a staker has previously joined", func() {
// ARRANGE
s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{
Name: "PoolTest",
Protocol: &pooltypes.Protocol{
Version: "0.0.0",
Binaries: "{}",
LastUpgrade: uint64(s.Ctx().BlockTime().Unix()),
},
UpgradePlan: &pooltypes.UpgradePlan{},
})
msg := &pooltypes.MsgCreatePool{
Authority: gov,
UploadInterval: 60,
MaxBundleSize: 100,
Binaries: "{}",
}
s.RunTxPoolSuccess(msg)

s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{
Creator: i.STAKER_0,
Expand Down

0 comments on commit cd57ba5

Please sign in to comment.