(cdc codec.Codec)
| 34 | } |
| 35 | |
| 36 | func GenesisStateWithValSet(cdc codec.Codec) GenesisState { |
| 37 | privVal := mock.NewPV() |
| 38 | pubKey, _ := privVal.GetPubKey() |
| 39 | validator := tmtypes.NewValidator(pubKey, 1) |
| 40 | valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) |
| 41 | |
| 42 | // generate a genesis account |
| 43 | senderPrivKey := secp256k1.GenPrivKey() |
| 44 | senderPrivKey.PubKey().Address() |
| 45 | acc := authtypes.NewBaseAccountWithAddress(senderPrivKey.PubKey().Address().Bytes()) |
| 46 | |
| 47 | var balances []banktypes.Balance |
| 48 | initValPowers := make([]abci.ValidatorUpdate, 0, len(valSet.Validators)) |
| 49 | |
| 50 | genesisState := NewDefaultGenesisState(cdc) |
| 51 | genAccs := []authtypes.GenesisAccount{acc} |
| 52 | authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) |
| 53 | genesisState[authtypes.ModuleName] = cdc.MustMarshalJSON(authGenesis) |
| 54 | |
| 55 | validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) |
| 56 | delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) |
| 57 | |
| 58 | bondAmt := sdk.DefaultPowerReduction |
| 59 | |
| 60 | for _, val := range valSet.Validators { |
| 61 | pk, _ := cryptocodec.FromCmtPubKeyInterface(val.PubKey) |
| 62 | pkAny, _ := codectypes.NewAnyWithValue(pk) |
| 63 | validator := stakingtypes.Validator{ |
| 64 | OperatorAddress: sdk.ValAddress(val.Address).String(), |
| 65 | ConsensusPubkey: pkAny, |
| 66 | Jailed: false, |
| 67 | Status: stakingtypes.Bonded, |
| 68 | Tokens: bondAmt, |
| 69 | DelegatorShares: sdkmath.LegacyOneDec(), |
| 70 | Description: stakingtypes.Description{}, |
| 71 | UnbondingHeight: int64(0), |
| 72 | UnbondingTime: time.Unix(0, 0).UTC(), |
| 73 | Commission: stakingtypes.NewCommission(sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()), |
| 74 | MinSelfDelegation: sdkmath.ZeroInt(), |
| 75 | } |
| 76 | validators = append(validators, validator) |
| 77 | delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String(), sdkmath.LegacyOneDec())) |
| 78 | |
| 79 | // add initial validator powers so consumer InitGenesis runs correctly |
| 80 | pub, _ := val.ToProto() |
| 81 | initValPowers = append(initValPowers, abci.ValidatorUpdate{ |
| 82 | Power: val.VotingPower, |
| 83 | PubKey: pub.PubKey, |
| 84 | }) |
| 85 | } |
| 86 | // set validators and delegations |
| 87 | stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) |
| 88 | genesisState[stakingtypes.ModuleName] = cdc.MustMarshalJSON(stakingGenesis) |
| 89 | |
| 90 | totalSupply := sdk.NewCoins() |
| 91 | for _, b := range balances { |
| 92 | // add genesis acc tokens to total supply |
| 93 | totalSupply = totalSupply.Add(b.Coins...) |
nothing calls this directly
no test coverage detected