-
Notifications
You must be signed in to change notification settings - Fork 6
/
withdraw_all_available.go
40 lines (37 loc) · 1.64 KB
/
withdraw_all_available.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
package simulation
import (
"github.com/chain4energy/c4e-chain/testutil/simulation"
"github.com/chain4energy/c4e-chain/testutil/utils"
"github.com/chain4energy/c4e-chain/x/cfevesting/keeper"
"github.com/chain4energy/c4e-chain/x/cfevesting/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"math/rand"
)
func SimulateWithdrawAllAvailable(
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) {
allVestingAccounts := k.GetAllAccountVestingPools(ctx)
if len(allVestingAccounts) == 0 {
return simtypes.NewOperationMsg(&types.MsgWithdrawAllAvailable{}, false, "", nil), nil, nil
}
randInt := utils.RandInt64(r, len(allVestingAccounts))
accAddress := allVestingAccounts[randInt].Owner
sdkAccAddress := sdk.MustAccAddressFromBech32(accAddress)
simAccount, _ := simtypes.FindAccount(accs, sdkAccAddress)
msgWithdrawAllAvailable := &types.MsgWithdrawAllAvailable{
Owner: accAddress,
}
if err := simulation.SendMessageWithRandomFees(ctx, r, ak.(authkeeper.AccountKeeper), bk.(bankkeeper.Keeper), app, simAccount, msgWithdrawAllAvailable, chainID); err != nil {
return simtypes.NewOperationMsg(msgWithdrawAllAvailable, false, "", nil), nil, nil
}
return simtypes.NewOperationMsg(msgWithdrawAllAvailable, true, "", nil), nil, nil
}
}