forked from crescent-network/crescent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_common.go
34 lines (26 loc) 路 1.03 KB
/
test_common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package keeper // noalias
import (
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/jesse-pinkman-cre/crescent/x/liquidstaking/types"
)
// RandomValidator returns a random validator given access to the keeper and ctx
func RandomValidator(r *rand.Rand, keeper types.StakingKeeper, ctx sdk.Context) (val stakingtypes.Validator, ok bool) {
vals := keeper.GetAllValidators(ctx)
if len(vals) == 0 {
return stakingtypes.Validator{}, false
}
i := r.Intn(len(vals))
return vals[i], true
}
// RandomActiveLiquidValidator returns a random validator given access to the keeper and ctx
func RandomActiveLiquidValidator(r *rand.Rand, ctx sdk.Context, k Keeper, sk types.StakingKeeper) (val stakingtypes.Validator, ok bool) {
avs := k.GetActiveLiquidValidators(ctx, k.GetParams(ctx).WhitelistedValsMap())
if len(avs) == 0 {
return stakingtypes.Validator{}, false
}
i := r.Intn(len(avs))
val, found := sk.GetValidator(ctx, avs[i].GetOperator())
return val, found
}