-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from 0xPolygon/raneet10/pos-1950
Initialise app simulation tests
- Loading branch information
Showing
4 changed files
with
498 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package app | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
flag "github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" | ||
) | ||
|
||
var FlagEnableBenchStreamingValue bool | ||
|
||
// Get flags every time the simulator is run | ||
func init() { | ||
flag.BoolVar(&FlagEnableBenchStreamingValue, "EnableStreaming", false, "Enable streaming service") | ||
} | ||
|
||
// TODO HV2: test this once https://github.com/0xPolygon/cosmos-sdk/pull/3 is merged | ||
// see https://github.com/0xPolygon/heimdall-v2/pull/10#discussion_r1482779246 | ||
|
||
// Profile with: | ||
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/0xPolygon/heimdall-v2/app -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out | ||
func BenchmarkFullAppSimulation(b *testing.B) { | ||
b.ReportAllocs() | ||
|
||
config := simcli.NewConfigFromFlags() | ||
config.ChainID = HeimdallAppChainID | ||
|
||
db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "goleveldb-app-heimdall", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) | ||
if err != nil { | ||
b.Fatalf("simulation setup failed: %s", err.Error()) | ||
} | ||
|
||
if skip { | ||
b.Skip("skipping benchmark application simulation") | ||
} | ||
|
||
defer func() { | ||
require.NoError(b, db.Close()) | ||
require.NoError(b, os.RemoveAll(dir)) | ||
}() | ||
|
||
appOptions := viper.New() | ||
if FlagEnableStreamingValue { | ||
m := make(map[string]interface{}) | ||
m["streaming.abci.keys"] = []string{"*"} | ||
m["streaming.abci.plugin"] = "abci_v1" //nolint:goconst | ||
m["streaming.abci.stop-node-on-err"] = true | ||
for key, value := range m { | ||
appOptions.SetDefault(key, value) | ||
} | ||
} | ||
appOptions.SetDefault(flags.FlagHome, DefaultNodeHome) | ||
appOptions.SetDefault(server.FlagInvCheckPeriod, simcli.FlagPeriodValue) | ||
|
||
app := NewHeimdallApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(HeimdallAppChainID)) | ||
|
||
// run randomized simulation | ||
|
||
_, simParams, simErr := simulation.SimulateFromSeed( | ||
b, | ||
os.Stdout, | ||
app.BaseApp, | ||
simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()), | ||
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 | ||
simtestutil.SimulationOperations(app, app.AppCodec(), config), | ||
app.BlockedModuleAccountAddrs(app.ModuleAccountAddrs()), | ||
config, | ||
app.AppCodec(), | ||
) | ||
|
||
// export state and simParams before the simulation error is checked | ||
if err = simtestutil.CheckExportSimulation(app, config, simParams); err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
if simErr != nil { | ||
b.Fatal(simErr) | ||
} | ||
|
||
if config.Commit { | ||
simtestutil.PrintStats(db) | ||
} | ||
} |
Oops, something went wrong.