(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestAppImportExport(t *testing.T) { |
| 150 | config, encodingConfig, db, appOpts, logger, appA := setupSimulationApp(t, "skipping application import/export simulation") |
| 151 | |
| 152 | // Run randomized simulation |
| 153 | _, simParams, simErr := simulateFromSeedFunc(t, appA, config) |
| 154 | require.Equal(t, akash.AppName, appA.Name()) |
| 155 | |
| 156 | // export state and simParams before the simulation error is checked |
| 157 | err := simtestutil.CheckExportSimulation(appA, config, simParams) |
| 158 | require.NoError(t, err) |
| 159 | require.NoError(t, simErr) |
| 160 | |
| 161 | if config.Commit { |
| 162 | sim.PrintStats(db) |
| 163 | } |
| 164 | |
| 165 | t.Log("exporting genesis...\n") |
| 166 | exported, err := appA.ExportAppStateAndValidators(false, []string{}, []string{}) |
| 167 | require.NoError(t, err) |
| 168 | |
| 169 | t.Log("importing genesis...\n") |
| 170 | |
| 171 | newDB, newDir, _, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", sim.FlagVerboseValue, sim.FlagEnabledValue) |
| 172 | require.NoError(t, err, "simulation setup failed") |
| 173 | if skip { |
| 174 | t.Skip("skipping application import/export simulation") |
| 175 | } |
| 176 | |
| 177 | defer func() { |
| 178 | require.NoError(t, newDB.Close()) |
| 179 | require.NoError(t, os.RemoveAll(newDir)) |
| 180 | }() |
| 181 | |
| 182 | appOpts[cflags.FlagHome] = t.TempDir() // ensure a unique folder for the new app |
| 183 | appB := akash.NewApp(logger, newDB, nil, true, sim.FlagPeriodValue, map[int64]bool{}, encodingConfig, appOpts, fauxMerkleModeOpt, baseapp.SetChainID(AppChainID)) |
| 184 | require.Equal(t, akash.AppName, appB.Name()) |
| 185 | |
| 186 | ctxA := appA.NewContextLegacy(true, cmtproto.Header{Height: appA.LastBlockHeight()}) |
| 187 | ctxB := appB.NewContextLegacy(true, cmtproto.Header{Height: appA.LastBlockHeight()}) |
| 188 | |
| 189 | initReq := &abci.RequestInitChain{ |
| 190 | AppStateBytes: exported.AppState, |
| 191 | } |
| 192 | |
| 193 | _, err = appB.InitChainer(ctxB, initReq) |
| 194 | if err != nil { |
| 195 | if strings.Contains(err.Error(), "validator set is empty after InitGenesis") { |
| 196 | t.Log("Skipping simulation as all validators have been unbonded") |
| 197 | t.Logf("err: %s stacktrace: %s\n", err, string(debug.Stack())) |
| 198 | return |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | require.NoError(t, err) |
| 203 | err = appB.StoreConsensusParams(ctxB, exported.ConsensusParams) |
| 204 | require.NoError(t, err) |
| 205 | |
| 206 | t.Log("comparing stores...") |
nothing calls this directly
no test coverage detected