-
Notifications
You must be signed in to change notification settings - Fork 579
/
operations.go
62 lines (52 loc) · 2.1 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
54
55
56
57
58
59
60
61
62
package simulation
import (
"errors"
"time"
legacysimulationtype "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v15/simulation/simtypes"
"github.com/osmosis-labs/osmosis/v15/x/lockup/keeper"
"github.com/osmosis-labs/osmosis/v15/x/lockup/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func RandomMsgLockTokens(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*types.MsgLockTokens, error) {
sender, err := sim.RandomSimAccountWithBalance(ctx)
if err != nil {
return nil, err
}
lockCoin := sim.RandExponentialCoin(ctx, sender.Address)
duration := simtypes.RandSelect(sim, time.Minute, time.Hour, time.Hour*24)
return &types.MsgLockTokens{
Owner: sender.Address.String(),
Duration: duration,
Coins: sdk.Coins{lockCoin},
}, nil
}
func RandomMsgBeginUnlockingAll(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*types.MsgBeginUnlockingAll, error) {
sender := sim.RandomSimAccount()
return &types.MsgBeginUnlockingAll{
Owner: sender.Address.String(),
}, nil
}
func RandomMsgBeginUnlocking(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*types.MsgBeginUnlocking, error) {
sender, senderExists := sim.RandomSimAccountWithConstraint(accountHasLockConstraint(k, ctx))
if !senderExists {
return nil, errors.New("no addr has created a lock")
}
lock := randLock(k, sim, ctx, sender.Address)
return &types.MsgBeginUnlocking{
Owner: sender.Address.String(),
ID: lock.ID,
}, nil
}
var notUnlockingFilter = func(l types.PeriodLock) bool { return !l.IsUnlocking() }
func accountHasLockConstraint(k keeper.Keeper, ctx sdk.Context) simtypes.SimAccountConstraint {
return func(acc legacysimulationtype.Account) bool {
return len(osmoutils.Filter(notUnlockingFilter, k.GetAccountPeriodLocks(ctx, acc.Address))) != 0
}
}
func randLock(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context, addr sdk.AccAddress) types.PeriodLock {
locks := k.GetAccountPeriodLocks(ctx, addr)
notUnlockingLocks := osmoutils.Filter(notUnlockingFilter, locks)
return simtypes.RandSelect(sim, notUnlockingLocks...)
}