-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upgrade/cosmos46' of https://github.com/terra-money/core …
…into upgrade/cosmos46
- Loading branch information
Showing
6 changed files
with
170 additions
and
10 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
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,114 @@ | ||
package app_test | ||
|
||
import ( | ||
"github.com/tendermint/tendermint/libs/log" | ||
dbm "github.com/tendermint/tm-db" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/terra-money/core/v2/app" | ||
"github.com/terra-money/core/v2/app/wasmconfig" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
) | ||
|
||
func init() { | ||
simapp.GetSimulatorFlags() | ||
} | ||
|
||
type SimApp interface { | ||
app.TerraApp | ||
GetBaseApp() *baseapp.BaseApp | ||
AppCodec() codec.Codec | ||
SimulationManager() *module.SimulationManager | ||
ModuleAccountAddrs() map[string]bool | ||
Name() string | ||
LegacyAmino() *codec.LegacyAmino | ||
BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock | ||
EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock | ||
InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain | ||
} | ||
|
||
// BenchmarkSimulation run the chain simulation | ||
// Running using starport command: | ||
// `starport chain simulate -v --numBlocks 200 --blockSize 50` | ||
// Running as go benchmark test: | ||
// `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true` | ||
func BenchmarkSimulation(b *testing.B) { | ||
simapp.FlagEnabledValue = true | ||
simapp.FlagCommitValue = true | ||
|
||
config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation") | ||
require.NoError(b, err, "simulation setup failed") | ||
|
||
b.Cleanup(func() { | ||
db.Close() | ||
err = os.RemoveAll(dir) | ||
require.NoError(b, err) | ||
}) | ||
|
||
encoding := app.MakeEncodingConfig() | ||
|
||
simApp := app.NewTerraApp( | ||
logger, | ||
db, | ||
nil, | ||
true, | ||
map[int64]bool{}, | ||
app.DefaultNodeHome, | ||
0, | ||
encoding, | ||
simapp.EmptyAppOptions{}, | ||
wasmconfig.DefaultConfig(), | ||
) | ||
|
||
// Run randomized simulations | ||
_, simParams, simErr := simulation.SimulateFromSeed( | ||
b, | ||
os.Stdout, | ||
simApp.BaseApp, | ||
simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()), | ||
simulationtypes.RandomAccounts, | ||
simapp.SimulationOperations(simApp, simApp.AppCodec(), config), | ||
simApp.ModuleAccountAddrs(), | ||
config, | ||
simApp.AppCodec(), | ||
) | ||
|
||
// export state and simParams before the simulation error is checked | ||
err = simapp.CheckExportSimulation(simApp, config, simParams) | ||
require.NoError(b, err) | ||
require.NoError(b, simErr) | ||
|
||
if config.Commit { | ||
simapp.PrintStats(db) | ||
} | ||
} | ||
|
||
func TestSimulationManager(t *testing.T) { | ||
db := dbm.NewMemDB() | ||
encoding := app.MakeEncodingConfig() | ||
|
||
simApp := app.NewTerraApp( | ||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)), | ||
db, | ||
nil, | ||
true, | ||
map[int64]bool{}, | ||
app.DefaultNodeHome, | ||
0, | ||
encoding, | ||
simapp.EmptyAppOptions{}, | ||
wasmconfig.DefaultConfig(), | ||
) | ||
sm := simApp.SimulationManager() | ||
require.NotNil(t, sm) | ||
} |
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