Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(simulation): re-enable simulation tests #1735

Merged
merged 14 commits into from
Dec 28, 2023
Merged
47 changes: 0 additions & 47 deletions .github/workflows/sims.yml

This file was deleted.

63 changes: 63 additions & 0 deletions .github/workflows/simulation-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Simulation tests

on:
push:
branches:
# every push to default branch
- main
schedule:
# once per day
- cron: "0 0 * * *"
pull_request:
branches:
# every pull request to default branch
- main

jobs:
test-sim-nondeterminism:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
- name: TestAppStateDeterminism
run: |
make test-sim-nondeterminism

test-sim-default-genesis-fast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
- name: TestFullAppSimulation
run: |
make test-sim-default-genesis-fast

test-sim-import-export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
- name: TestAppImportExport
run: |
make test-sim-import-export

test-sim-after-import:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
- name: TestAppSimulationAfterImport
run: |
make test-sim-after-import
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1686](https://github.com/NibiruChain/nibiru/pull/1686) - test(perp): add more tests for perp module msg server for DnR
* [#1683](https://github.com/NibiruChain/nibiru/pull/1683) - feat(perp): Add `StartDnREpoch` to `AfterEpochEnd` hook
* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant.
* [#1680](https://github.com/NibiruChain/nibiru/pull/1680) - feat(perp): MsgShiftPegMultiplier, MsgShiftSwapInvariant.
* [#1677](https://github.com/NibiruChain/nibiru/pull/1677) - fix(perp): make Gen_market set initial perp versions
* [#1669](https://github.com/NibiruChain/nibiru/pull/1669) - feat(perp): add query to get collateral metadata
* [#1663](https://github.com/NibiruChain/nibiru/pull/1663) - feat(perp): Add volume based rebates
Expand All @@ -75,25 +74,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - feat(inflation): add events for inflation distribution
* [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - fix(sudo): Make blank sudoers root invalid at genesis time.
* [#1710](https://github.com/NibiruChain/nibiru/pull/1710) - refactor(perp): Clean and organize module errors for x/perp
* [#1714](https://github.com/NibiruChain/nibiru/pull/1714) - ci(localnet.sh): Fix script, simplify, and test in CI.
* [#1714](https://github.com/NibiruChain/nibiru/pull/1714) - ci(localnet.sh): Fix script, simplify, and test in CI.
* [#1719](https://github.com/NibiruChain/nibiru/pull/1719) - refactor(test): add is not mandatory interface to action
* [#1723](https://github.com/NibiruChain/nibiru/pull/1723) - ci(e2e-wasm.yml): rm unused workflow
* [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs
* [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests

### Dependencies
k-yang marked this conversation as resolved.
Show resolved Hide resolved
- Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720))
- Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724))
- Bump `github.com/holiman/uint256` from 1.2.3 to 1.2.4 ([#1730](https://github.com/NibiruChain/nibiru/pull/1730))
- Bump `github.com/dvsekhvalnov/jose2go` from 1.5.0 to 1.6.0 ([#1733](https://github.com/NibiruChain/nibiru/pull/1733))

* Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720))
* Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724))
* Bump `github.com/holiman/uint256` from 1.2.3 to 1.2.4 ([#1730](https://github.com/NibiruChain/nibiru/pull/1730))
* Bump `github.com/dvsekhvalnov/jose2go` from 1.5.0 to 1.6.0 ([#1733](https://github.com/NibiruChain/nibiru/pull/1733))
* Bump `github.com/spf13/cast` from 1.5.1 to 1.6.0 ([#1689](https://github.com/NibiruChain/nibiru/pull/1689))
* Bump `cosmossdk.io/math` from 1.1.2 to 1.2.0 ([#1676](https://github.com/NibiruChain/nibiru/pull/1676))
* Bump `github.com/grpc-ecosystem/grpc-gateway/v2` from 2.18.0 to 2.18.1 ([#1675](https://github.com/NibiruChain/nibiru/pull/1675))
* Bump `actions/setup-go` from 4 to 5 ([#1696](https://github.com/NibiruChain/nibiru/pull/1696))
* Bump `golang` from 1.19 to 1.21 ([#1698](https://github.com/NibiruChain/nibiru/pull/1698))
* [#1678](https://github.com/NibiruChain/nibiru/pull/1678) - chore(deps): collections to v0.4.0 for math.Int value encoder


## [v1.1.0] - 2023-11-20

* [[Release Link](https://github.com/NibiruChain/nibiru/releases/tag/v1.1.0)]
Expand Down
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type NibiruApp struct {
AppKeepers // embed all module keepers

// the module manager
mm *module.Manager
ModuleManager *module.Manager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have some benefit of adding it public?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required for TestAppImportExport.


// simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -179,7 +179,7 @@ func NewNibiruApp(
// add test gRPC service for testing gRPC queries in isolation
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})

app.InitSimulationManager(app.appCodec)
app.initSimulationManager(app.appCodec)

// initialize stores
app.MountKVStores(keys)
Expand Down Expand Up @@ -251,12 +251,12 @@ func (app *NibiruApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *NibiruApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
return app.ModuleManager.BeginBlock(ctx, req)
}

// EndBlocker application updates every end block
func (app *NibiruApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
return app.ModuleManager.EndBlock(ctx, req)
}

// InitChainer application update at chain initialization
Expand All @@ -265,8 +265,8 @@ func (app *NibiruApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) ab
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
app.upgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
}

// LoadHeight loads a particular height
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (app *NibiruApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down
49 changes: 14 additions & 35 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,23 @@ func (app *NibiruApp) initModuleManager(
encodingConfig EncodingConfig,
skipGenesisInvariants bool,
) {
app.mm = module.NewManager(
app.ModuleManager = module.NewManager(
app.initAppModules(encodingConfig, skipGenesisInvariants)...,
)

orderedModules := orderedModuleNames()
app.mm.SetOrderBeginBlockers(orderedModules...)
app.mm.SetOrderEndBlockers(orderedModules...)
app.mm.SetOrderInitGenesis(orderedModules...)
app.mm.SetOrderExportGenesis(orderedModules...)
app.ModuleManager.SetOrderBeginBlockers(orderedModules...)
app.ModuleManager.SetOrderEndBlockers(orderedModules...)
app.ModuleManager.SetOrderInitGenesis(orderedModules...)
app.ModuleManager.SetOrderExportGenesis(orderedModules...)

// Uncomment if you want to set a custom migration order here.
// app.mm.SetOrderMigrations(custom order)

app.mm.RegisterInvariants(&app.crisisKeeper)
app.ModuleManager.RegisterInvariants(&app.crisisKeeper)
app.configurator = module.NewConfigurator(
app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)
app.ModuleManager.RegisterServices(app.configurator)

// see https://github.com/cosmos/cosmos-sdk/blob/666c345ad23ddda9523cc5cd1b71187d91c26f34/simapp/upgrades.go#L35-L57
for _, subspace := range app.paramsKeeper.GetSubspaces() {
Expand Down Expand Up @@ -847,34 +847,13 @@ func initParamsKeeper(
return paramsKeeper
}

// TODO: Simulation manager
func (app *NibiruApp) InitSimulationManager(
func (app *NibiruApp) initSimulationManager(
appCodec codec.Codec,
) {
// // create the simulation manager and define the order of the modules for deterministic simulations
// //
// // NOTE: this is not required apps that don't use the simulator for fuzz testing
// // transactions
// epochsModule := epochs.NewAppModule(appCodec, app.EpochsKeeper)
// app.sm = module.NewSimulationManager(
// auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
// bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
// feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
// gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
// staking.NewAppModule(appCodec, app.stakingKeeper, app.AccountKeeper, app.BankKeeper),
// distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper),
// slashing.NewAppModule(appCodec, app.slashingKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper),
// params.NewAppModule(app.paramsKeeper),
// authzmodule.NewAppModule(appCodec, app.authzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// // native x/
// epochsModule,
// // ibc
// capability.NewAppModule(appCodec, *app.capabilityKeeper),
// evidence.NewAppModule(app.evidenceKeeper),
// ibc.NewAppModule(app.ibcKeeper),
// ibctransfer.NewAppModule(app.transferKeeper),
// ibcfee.NewAppModule(app.ibcFeeKeeper),
// )
//
// app.sm.RegisterStoreDecoders()
overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
}
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)

app.sm.RegisterStoreDecoders()
}
2 changes: 1 addition & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (app *NibiruApp) setupUpgrades() {

func (app *NibiruApp) setUpgradeHandlers() {
for _, u := range Upgrades {
app.upgradeKeeper.SetUpgradeHandler(u.UpgradeName, u.CreateUpgradeHandler(app.mm, app.configurator))
app.upgradeKeeper.SetUpgradeHandler(u.UpgradeName, u.CreateUpgradeHandler(app.ModuleManager, app.configurator))
}
}

Expand Down
72 changes: 40 additions & 32 deletions contrib/make/simulation.mk
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
BINDIR = $(GOPATH)/bin
RUNSIM = $(BINDIR)/runsim
SIMAPP = ./simapp

.PHONY: runsim
runsim: $(RUNSIM)
$(RUNSIM):
@echo "Installing runsim..."
@(cd /tmp && go install github.com/cosmos/tools/cmd/[email protected])

.PHONY: test-sim-nondeterminism
test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h
@go test -mod=readonly -v $(SIMAPP) \
-run TestAppStateDeterminism \
-Enabled=true \
-Params=params.json \
-NumBlocks=100 \
-BlockSize=200 \
-Commit=true \
-Period=0 \
-Verbose=true

.PHONY: test-sim-default-genesis-fast
test-sim-default-genesis-fast:
@echo "Running default genesis simulation..."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v

.PHONY: test-sim-custom-genesis-multi-seed
test-sim-custom-genesis-multi-seed: runsim
@echo "Running multi-seed custom genesis simulation..."
@$(RUNSIM) -SimAppPkg=$(SIMAPP) -ExitOnFail 400 5 TestFullAppSimulation

.PHONY: test-sim-multi-seed-long
test-sim-multi-seed-long: runsim
@echo "Running long multi-seed application simulation. This may take awhile!"
@$(RUNSIM) -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation
@go test -mod=readonly -v $(SIMAPP) \
-run TestFullAppSimulation \
-Params=params.json \
-Enabled=true \
-NumBlocks=100 \
-BlockSize=200 \
-Commit=true \
-Seed=99 \
-Period=0

.PHONY: test-sim-multi-seed-short
test-sim-multi-seed-short: runsim
@echo "Running short multi-seed application simulation. This may take awhile!"
@$(RUNSIM) -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation
.PHONY: test-sim-import-export
test-sim-import-export:
@echo "Running application import/export simulation. This may take several minutes..."
@go test -mod=readonly -v $(SIMAPP) \
-run TestAppImportExport \
-Params=params.json \
-Enabled=true \
-NumBlocks=100 \
-Commit=true \
-Seed=99 \
-Period=5

.PHONY: test-sim-benchmark-invariants
test-sim-benchmark-invariants:
@echo "Running simulation invariant benchmarks..."
@go test -mod=readonly $(SIMAPP) -benchmem -bench=BenchmarkInvariants -run=^$ \
-Enabled=true -NumBlocks=1000 -BlockSize=200 \
-Period=1 -Commit=true -Seed=57 -v -timeout 24h
.PHONY: test-sim-after-import
test-sim-after-import:
@echo "Running application simulation-after-import. This may take several minutes..."
@go test -mod=readonly -v $(SIMAPP) \
-run TestAppSimulationAfterImport \
-Params=params.json \
-Enabled=true \
-NumBlocks=50 \
-Commit=true \
-Seed=99 \
-Period=5
Loading
Loading