github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/simulation/genesis.go (about)

     1  package simulation
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"math/rand"
     7  
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
     9  	clientsims "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/simulation"
    10  	clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types"
    11  	connectionsims "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/simulation"
    12  	connectiontypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/types"
    13  	channelsims "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/simulation"
    14  	channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types"
    15  	host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host"
    16  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/types"
    17  )
    18  
    19  // DONTCOVER
    20  
    21  // Simulation parameter constants
    22  const (
    23  	clientGenesis     = "client_genesis"
    24  	connectionGenesis = "connection_genesis"
    25  	channelGenesis    = "channel_genesis"
    26  )
    27  
    28  // RandomizedGenState generates a random GenesisState for evidence
    29  func RandomizedGenState(simState *module.SimulationState) {
    30  	var (
    31  		clientGenesisState     clienttypes.GenesisState
    32  		connectionGenesisState connectiontypes.GenesisState
    33  		channelGenesisState    channeltypes.GenesisState
    34  	)
    35  
    36  	simState.AppParams.GetOrGenerate(
    37  		simState.Cdc, clientGenesis, &clientGenesisState, simState.Rand,
    38  		func(r *rand.Rand) { clientGenesisState = clientsims.GenClientGenesis(r, simState.Accounts) },
    39  	)
    40  
    41  	simState.AppParams.GetOrGenerate(
    42  		simState.Cdc, connectionGenesis, &connectionGenesisState, simState.Rand,
    43  		func(r *rand.Rand) { connectionGenesisState = connectionsims.GenConnectionGenesis(r, simState.Accounts) },
    44  	)
    45  
    46  	simState.AppParams.GetOrGenerate(
    47  		simState.Cdc, channelGenesis, &channelGenesisState, simState.Rand,
    48  		func(r *rand.Rand) { channelGenesisState = channelsims.GenChannelGenesis(r, simState.Accounts) },
    49  	)
    50  
    51  	ibcGenesis := types.GenesisState{
    52  		ClientGenesis:     clientGenesisState,
    53  		ConnectionGenesis: connectionGenesisState,
    54  		ChannelGenesis:    channelGenesisState,
    55  	}
    56  
    57  	bz, err := json.MarshalIndent(&ibcGenesis, "", " ")
    58  	if err != nil {
    59  		panic(err)
    60  	}
    61  	fmt.Printf("Selected randomly generated %s parameters:\n%s\n", host.ModuleName, bz)
    62  	simState.GenState[host.ModuleName] = simState.Cdc.MustMarshalJSON(&ibcGenesis)
    63  }