Skip to content

Commit

Permalink
swap condition for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 2, 2024
1 parent 976d140 commit c852325
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions x/auth/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit c852325

Please sign in to comment.