From c852325bcf72ff3b08bb2b8c0dea8da35184b138 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 2 Dec 2024 19:43:09 +0100 Subject: [PATCH] swap condition for readability --- x/auth/simulation/genesis.go | 65 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 21afeb637dac..0e9f7e93eb4a 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -26,38 +26,41 @@ func RandomGenesisAccounts(simState *module.SimulationState) types.GenesisAccoun for i, acc := range simState.Accounts { bacc := types.NewBaseAccountWithAddress(acc.Address) - if _, ok := simState.GenState["vesting"]; ok { // check if vesting module is enabled - // Only consider making a vesting account once the initial bonded validator - // set is exhausted due to needing to track DelegatedVesting. - if !(int64(i) > simState.NumBonded && simState.Rand.Intn(100) < 50) { - genesisAccs[i] = bacc - continue - } - - initialVesting := sdk.NewCoins(sdk.NewInt64Coin(simState.BondDenom, simState.Rand.Int63n(simState.InitialStake.Int64()))) - var endTime int64 - - startTime := simState.GenTimestamp.Unix() - - // Allow for some vesting accounts to vest very quickly while others very slowly. - if simState.Rand.Intn(100) < 50 { - endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*24*30)))) - } else { - endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*12)))) - } - - bva, err := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime) - if err != nil { - panic(err) - } - - if simState.Rand.Intn(100) < 50 { - genesisAccs[i] = vestingtypes.NewContinuousVestingAccountRaw(bva, startTime) - } else { - genesisAccs[i] = vestingtypes.NewDelayedVestingAccountRaw(bva) - } - } else { + // check if vesting module is enabled + // if not, just use base account + if _, ok := simState.GenState["vesting"]; !ok { + genesisAccs[i] = bacc + continue + } + + // Only consider making a vesting account once the initial bonded validator + // set is exhausted due to needing to track DelegatedVesting. + if !(int64(i) > simState.NumBonded && simState.Rand.Intn(100) < 50) { genesisAccs[i] = bacc + continue + } + + initialVesting := sdk.NewCoins(sdk.NewInt64Coin(simState.BondDenom, simState.Rand.Int63n(simState.InitialStake.Int64()))) + var endTime int64 + + startTime := simState.GenTimestamp.Unix() + + // Allow for some vesting accounts to vest very quickly while others very slowly. + if simState.Rand.Intn(100) < 50 { + endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*24*30)))) + } else { + endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*12)))) + } + + bva, err := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime) + if err != nil { + panic(err) + } + + if simState.Rand.Intn(100) < 50 { + genesisAccs[i] = vestingtypes.NewContinuousVestingAccountRaw(bva, startTime) + } else { + genesisAccs[i] = vestingtypes.NewDelayedVestingAccountRaw(bva) } }