-
Notifications
You must be signed in to change notification settings - Fork 324
/
create_rollapp.go
92 lines (83 loc) · 3.16 KB
/
create_rollapp.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package simulation
import (
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
sharedtypes "github.com/dymensionxyz/dymension/shared/types"
"github.com/dymensionxyz/dymension/simulation"
simulationtypes "github.com/dymensionxyz/dymension/simulation/types"
"github.com/dymensionxyz/dymension/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/x/rollapp/types"
)
func SimulateMsgCreateRollapp(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
// choose creator and rollappId
simAccount, rollappNumId := simtypes.RandomAcc(r, accs)
rollappId := "rollapp" + fmt.Sprint(rollappNumId)
// check if we already created it
bAlreadyExists := false
for _, item := range simulation.GlobalRollappList {
if item.RollappId == rollappId {
bAlreadyExists = true
}
}
permissionedAddresses := []string{}
bPermissioned := r.Int()%2 == 0
bFailDuplicateSequencer := false
if bPermissioned {
for i := 0; i < r.Intn(len(accs)); i++ {
seqAccount, _ := simtypes.RandomAcc(r, accs)
for _, item := range permissionedAddresses {
if item == seqAccount.Address.String() {
bFailDuplicateSequencer = true
}
}
permissionedAddresses = append(permissionedAddresses, seqAccount.Address.String())
}
}
// calculate maxSequencers and whether or not to fail the transaction
bFailMaxSequencers := r.Int()%2 == 0
maxSequencers := uint64(r.Intn(100)) + 1
if bFailMaxSequencers {
maxSequencers = 0
}
// calculate maxWithholdingBlocks and whether or not to fail the transaction
bFailMaxWithholdingBlocks := r.Int()%2 == 0
maxWithholdingBlocks := uint64(r.Intn(len(accs))) + 1
if bFailMaxWithholdingBlocks {
maxWithholdingBlocks = 0
}
msg := &types.MsgCreateRollapp{
Creator: simAccount.Address.String(),
RollappId: rollappId,
CodeStamp: "",
GenesisPath: "",
MaxWithholdingBlocks: maxWithholdingBlocks,
MaxSequencers: maxSequencers,
PermissionedAddresses: sharedtypes.Sequencers{
Addresses: permissionedAddresses,
},
}
// fmt.Printf("SimulateMsgCreateRollapp: RollappId(%s) bFailMaxSequencers(%t) bFailMaxWithholdingBlocks(%t) bFailDuplicateSequencer(%t)\n",
// msg.RollappId, bFailMaxSequencers, bFailMaxWithholdingBlocks, bFailDuplicateSequencer)
bExpectedError := bFailMaxSequencers || bFailMaxWithholdingBlocks || bFailDuplicateSequencer || bAlreadyExists
if !bExpectedError {
simulation.GlobalRollappList = append(simulation.GlobalRollappList, simulationtypes.SimRollapp{
RollappId: rollappId,
MaxSequencers: maxSequencers,
PermissionedAddresses: permissionedAddresses,
Sequencers: []int{},
LastHeight: 0,
LastCreationHeight: 0,
})
}
return simulation.GenAndDeliverMsgWithRandFees(msg, msg.Type(), types.ModuleName, r, app, &ctx, &simAccount, bk, ak, nil, bExpectedError)
}
}