-
Notifications
You must be signed in to change notification settings - Fork 109
/
rand.go
32 lines (25 loc) · 1.03 KB
/
rand.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
package testutils
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/axelarnetwork/axelar-core/testutils/rand"
"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/snapshot/exported"
"github.com/axelarnetwork/utils/slices"
)
// Snapshot returns random snapshot based on the given parameters
func Snapshot(participantCount uint64, threshold utils.Threshold) exported.Snapshot {
participantsWeight := sdk.ZeroUint()
participants := slices.Expand(func(int) exported.Participant {
weight := sdk.NewUint(uint64(rand.I64Between(1, 100)))
participantsWeight = participantsWeight.Add(weight)
return exported.NewParticipant(rand.ValAddr(), weight)
},
int(participantCount),
)
bondedWeight := sdk.NewUint(uint64(rand.I64Between(
participantsWeight.BigInt().Int64(),
participantsWeight.MulUint64(uint64(threshold.Denominator)).QuoUint64(uint64(threshold.Numerator)).BigInt().Int64()+1),
))
return exported.NewSnapshot(time.Now(), rand.I64Between(1, 1000), participants, bondedWeight)
}