From dcbddd9f04b3086c0ad07ee65de16e7adedc7da4 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Dec 2019 14:59:48 +0000 Subject: [PATCH] Merge PR #221: Hide unnecessarily exported function to better coverage report --- app/sim_test.go | 21 ++++++++++++++++----- app/utils.go | 12 ------------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/sim_test.go b/app/sim_test.go index 282549ca..5a7d8def 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -78,7 +78,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { // export state and params before the simulation error is checked if config.ExportStatePath != "" { - if err := ExportStateToJSON(app, config.ExportStatePath); err != nil { + if err := exportStateToJSON(app, config.ExportStatePath); err != nil { fmt.Println(err) b.Fail() } @@ -140,7 +140,7 @@ func TestFullAppSimulation(t *testing.T) { // export state and params before the simulation error is checked if config.ExportStatePath != "" { - err := ExportStateToJSON(app, config.ExportStatePath) + err := exportStateToJSON(app, config.ExportStatePath) require.NoError(t, err) } @@ -197,7 +197,7 @@ func TestAppImportExport(t *testing.T) { // export state and simParams before the simulation error is checked if config.ExportStatePath != "" { - err := ExportStateToJSON(app, config.ExportStatePath) + err := exportStateToJSON(app, config.ExportStatePath) require.NoError(t, err) } @@ -319,7 +319,7 @@ func TestAppSimulationAfterImport(t *testing.T) { // export state and params before the simulation error is checked if config.ExportStatePath != "" { - err := ExportStateToJSON(app, config.ExportStatePath) + err := exportStateToJSON(app, config.ExportStatePath) require.NoError(t, err) } @@ -463,7 +463,7 @@ func BenchmarkInvariants(b *testing.B) { // export state and params before the simulation error is checked if config.ExportStatePath != "" { - if err := ExportStateToJSON(app, config.ExportStatePath); err != nil { + if err := exportStateToJSON(app, config.ExportStatePath); err != nil { fmt.Println(err) b.Fail() } @@ -497,3 +497,14 @@ func BenchmarkInvariants(b *testing.B) { }) } } + +// auxiliary function to export the app state to JSON +func exportStateToJSON(app *GaiaApp, path string) error { + fmt.Println("exporting app state...") + appState, _, err := app.ExportAppStateAndValidators(false, nil) + if err != nil { + return err + } + + return ioutil.WriteFile(path, []byte(appState), 0644) +} diff --git a/app/utils.go b/app/utils.go index f960b2d0..f749b528 100644 --- a/app/utils.go +++ b/app/utils.go @@ -1,7 +1,6 @@ package app import ( - "fmt" "io/ioutil" "github.com/cosmos/cosmos-sdk/codec" @@ -30,14 +29,3 @@ func SimulationOperations(app *GaiaApp, cdc *codec.Codec, config simulation.Conf simState.Contents = app.sm.GetProposalContents(simState) return app.sm.WeightedOperations(simState) } - -// ExportStateToJSON util function to export the app state to JSON -func ExportStateToJSON(app *GaiaApp, path string) error { - fmt.Println("exporting app state...") - appState, _, err := app.ExportAppStateAndValidators(false, nil) - if err != nil { - return err - } - - return ioutil.WriteFile(path, []byte(appState), 0644) -}