-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.go
53 lines (45 loc) · 1.81 KB
/
operations.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package simulation
import (
"fmt"
"math/rand"
sdk "github.com/blockgenx/blockgen-sdk/types"
"github.com/blockgenx/blockgen-sdk/types/simulation"
"github.com/blockgenx/blockgen-sdk/x/params/types/proposal"
)
func min(a int, b int) int {
if a <= b {
return a
}
return b
}
// SimulateParamChangeProposalContent returns random parameter change content.
// It will generate a ParameterChangeProposal object with anywhere between 1 and
// the total amount of defined parameters changes, all of which have random valid values.
func SimulateParamChangeProposalContent(paramChangePool []simulation.ParamChange) simulation.ContentSimulatorFn {
numProposals := 0
// Bound the maximum number of simultaneous parameter changes
maxSimultaneousParamChanges := min(len(paramChangePool), 1000)
if maxSimultaneousParamChanges == 0 {
panic("param changes array is empty")
}
return func(r *rand.Rand, _ sdk.Context, _ []simulation.Account) simulation.Content {
numChanges := simulation.RandIntBetween(r, 1, maxSimultaneousParamChanges)
paramChanges := make([]proposal.ParamChange, numChanges)
// perm here takes at most len(paramChangePool) calls to random
paramChoices := r.Perm(len(paramChangePool))
for i := 0; i < numChanges; i++ {
spc := paramChangePool[paramChoices[i]]
// add a new distinct parameter to the set of changes
paramChanges[i] = proposal.NewParamChange(spc.Subspace(), spc.Key(), spc.SimValue()(r))
}
title := fmt.Sprintf("title from SimulateParamChangeProposalContent-%d", numProposals)
desc := fmt.Sprintf("desc from SimulateParamChangeProposalContent-%d. Random short desc: %s",
numProposals, simulation.RandStringOfLength(r, 20))
numProposals++
return proposal.NewParameterChangeProposal(
title, // title
desc, // description
paramChanges, // set of changes
)
}
}