From c07d5194747909defbdab1e2c98ea48a7d858e6b Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 3 Oct 2024 12:32:28 +0530 Subject: [PATCH] add todos for BasicManager --- app/encoding.go | 1 + app/modules.go | 16 +++++++++------- sims.mk | 27 ++++++++++++++++----------- tests/simulation/sim/sim_config.go | 15 +++++++++++---- tests/simulation/sim_test.go | 4 ++++ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/app/encoding.go b/app/encoding.go index 755b4ccbae..44748dacee 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -14,6 +14,7 @@ import ( evmenc "github.com/zeta-chain/ethermint/encoding" ethermint "github.com/zeta-chain/ethermint/types" evmtypes "github.com/zeta-chain/ethermint/x/evm/types" + authoritytypes "github.com/zeta-chain/node/x/authority/types" crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" emissionstypes "github.com/zeta-chain/node/x/emissions/types" diff --git a/app/modules.go b/app/modules.go index b041cc0d1a..038b3766aa 100644 --- a/app/modules.go +++ b/app/modules.go @@ -38,6 +38,7 @@ import ( evmtypes "github.com/zeta-chain/ethermint/x/evm/types" "github.com/zeta-chain/ethermint/x/feemarket" feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types" + authoritymodule "github.com/zeta-chain/node/x/authority" authoritytypes "github.com/zeta-chain/node/x/authority/types" crosschainmodule "github.com/zeta-chain/node/x/crosschain" @@ -126,6 +127,7 @@ func InitGenesisModuleList() []string { } } +// simulationModules returns a list of modules to include in the simulation func simulationModules( app *App, appCodec codec.Codec, @@ -139,13 +141,13 @@ func simulationModules( app.GetSubspace(authtypes.ModuleName), ), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), - gov.NewAppModule( - appCodec, - &app.GovKeeper, - app.AccountKeeper, - app.BankKeeper, - app.GetSubspace(govtypes.ModuleName), - ), + //gov.NewAppModule( + // appCodec, + // &app.GovKeeper, + // app.AccountKeeper, + // app.BankKeeper, + // app.GetSubspace(govtypes.ModuleName), + //), staking.NewAppModule( appCodec, app.StakingKeeper, diff --git a/sims.mk b/sims.mk index db4b4d7a5c..ea81e40807 100644 --- a/sims.mk +++ b/sims.mk @@ -10,27 +10,32 @@ SIMAPP = ./tests/simulation # Run sim is a cosmos tool which helps us to run multiple simulations in parallel. runsim: $(BINDIR)/runsim $(BINDIR)/runsim: - @echo "Installing runsim..." - @(cd /tmp && go install github.com/cosmos/tools/cmd/runsim@v1.0.0) + @echo 'Installing runsim...' + @TEMP_DIR=$$(mktemp -d) && \ + cd $$TEMP_DIR && \ + go install github.com/cosmos/tools/cmd/runsim@v1.0.0 && \ + rm -rf $$TEMP_DIR || (echo 'Failed to install runsim' && exit 1) + @echo 'runsim installed successfully' -test-sim-nondeterminism: - @echo "Running non-determinism test..." - @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ - -NumBlocks=10 -BlockSize=20 -Commit=true -Period=0 -v -timeout 24h +define run-sim-test + @echo "Running $(1)..." + @go test -mod=readonly $(SIMAPP) -run $(2) -Enabled=true \ + -NumBlocks=$(3) -BlockSize=$(4) -Commit=true -Period=0 -v -timeout $(5) +endef +test-sim-nondeterminism: + $(call run-sim-test,"non-determinism test",TestAppStateDeterminism,100,200,2h) test-sim-fullappsimulation: - @echo "Running TestFullAppSimulation." - @go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Enabled=true \ - -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h + $(call run-sim-test,"TestFullAppSimulation",TestFullAppSimulation,100,200,2h) test-sim-multi-seed-long: runsim - @echo "Running long multi-seed application simulation. This may take awhile!" + @echo "Running long multi-seed application simulation." @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation test-sim-multi-seed-short: runsim - @echo "Running short multi-seed application simulation. This may take awhile!" + @echo "Running short multi-seed application simulation." @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation diff --git a/tests/simulation/sim/sim_config.go b/tests/simulation/sim/sim_config.go index 915a77dd40..c306f47f54 100644 --- a/tests/simulation/sim/sim_config.go +++ b/tests/simulation/sim/sim_config.go @@ -6,6 +6,13 @@ import ( "github.com/cosmos/cosmos-sdk/types/simulation" ) +const ( + defaultSeed = 42 + defaultNumBlocks = 500 + defaultInitialHeight = 1 + defaultBlockSize = 200 +) + // List of available flags for the simulator var ( FlagGenesisFileValue string @@ -68,10 +75,10 @@ func GetSimulatorFlags() { "", "custom file path to save the exported simulation statistics JSON", ) - flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed") - flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation") - flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height") - flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block") + flag.Int64Var(&FlagSeedValue, "Seed", defaultSeed, "simulation random seed") + flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", defaultInitialHeight, "initial block to start the simulation") + flag.IntVar(&FlagNumBlocksValue, "NumBlocks", defaultNumBlocks, "number of new blocks to simulate from the initial block height") + flag.IntVar(&FlagBlockSizeValue, "BlockSize", defaultBlockSize, "operations per block") flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output") flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit") flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation") diff --git a/tests/simulation/sim_test.go b/tests/simulation/sim_test.go index 7d3d8305da..3b313338f4 100644 --- a/tests/simulation/sim_test.go +++ b/tests/simulation/sim_test.go @@ -128,6 +128,10 @@ func TestAppStateDeterminism(t *testing.T) { appHash := simApp.LastCommitID().Hash appHashList[j] = appHash + // Clean up resources + require.NoError(t, db.Close()) + require.NoError(t, os.RemoveAll(dir)) + if j != 0 { require.Equal( t,