MCPcopy Create free account
hub / github.com/akash-network/node / SetupWithConfiguration

Function SetupWithConfiguration

testutil/sims/app_helpers.go:138–206  ·  view source on GitHub ↗

SetupWithConfiguration initializes a new runtime.App. A Nop logger is set in runtime.App. appConfig defines the application configuration (f.e. app_config.go). extraOutputs defines the extra outputs to be assigned by the dependency injector (depinject).

(appConfig depinject.Config, startupConfig StartupConfig, extraOutputs ...any)

Source from the content-addressed store, hash-verified

136// appConfig defines the application configuration (f.e. app_config.go).
137// extraOutputs defines the extra outputs to be assigned by the dependency injector (depinject).
138func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupConfig, extraOutputs ...any) (*runtime.App, error) {
139 // create the app with depinject
140 var (
141 app *runtime.App
142 appBuilder *runtime.AppBuilder
143 codec codec.Codec
144 )
145
146 if err := depinject.Inject(appConfig, append(extraOutputs, &appBuilder, &codec)...); err != nil {
147 return nil, fmt.Errorf("failed to inject dependencies: %w", err)
148 }
149
150 if startupConfig.BaseAppOption != nil {
151 app = appBuilder.Build(startupConfig.DB, nil, startupConfig.BaseAppOption)
152 } else {
153 app = appBuilder.Build(startupConfig.DB, nil)
154 }
155 if err := app.Load(true); err != nil {
156 return nil, fmt.Errorf("failed to load app: %w", err)
157 }
158
159 // create validator set
160 valSet, err := startupConfig.ValidatorSet()
161 if err != nil {
162 return nil, fmt.Errorf("failed to create validator set")
163 }
164
165 balances := make([]banktypes.Balance, 0, len(startupConfig.GenesisAccounts))
166 genAccounts := make([]authtypes.GenesisAccount, 0, len(startupConfig.GenesisAccounts))
167
168 for _, ga := range startupConfig.GenesisAccounts {
169 genAccounts = append(genAccounts, ga.GenesisAccount)
170 balances = append(balances, banktypes.Balance{Address: ga.GenesisAccount.GetAddress().String(), Coins: ga.Coins})
171 }
172
173 genesisState, err := GenesisStateWithValSet(codec, app.DefaultGenesis(), valSet, genAccounts, balances...)
174 if err != nil {
175 return nil, fmt.Errorf("failed to create genesis state: %w", err)
176 }
177
178 // init chain must be called to stop deliverState from being nil
179 stateBytes, err := cmtjson.MarshalIndent(genesisState, "", " ")
180 if err != nil {
181 return nil, fmt.Errorf("failed to marshal default genesis state: %w", err)
182 }
183
184 // init chain will set the validator set and initialize the genesis accounts
185 _, err = app.InitChain(&abci.RequestInitChain{
186 Validators: []abci.ValidatorUpdate{},
187 ConsensusParams: DefaultConsensusParams,
188 AppStateBytes: stateBytes,
189 })
190 if err != nil {
191 return nil, fmt.Errorf("failed to init chain: %w", err)
192 }
193
194 // commit genesis changes
195 if !startupConfig.AtGenesis {

Callers 2

SetupFunction · 0.85
SetupAtGenesisFunction · 0.85

Calls 5

InitChainMethod · 0.80
FinalizeBlockMethod · 0.80
GenesisStateWithValSetFunction · 0.70
StringMethod · 0.45
DefaultGenesisMethod · 0.45

Tested by

no test coverage detected