diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml deleted file mode 100644 index 4e994e8..0000000 --- a/.github/workflows/sims.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: Sims -# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short) -# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed -on: - pull_request: - push: - branches: - - main - -concurrency: - group: ci-${{ github.ref }}-sims - cancel-in-progress: true - -jobs: - build: - permissions: - contents: read # for actions/checkout to fetch code - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip-sims')" - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - run: make -C simapp build - - name: Install runsim - run: go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - - uses: actions/cache@v3 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - - test-sim-nondeterminism: - runs-on: ubuntu-latest - needs: [build] - timeout-minutes: 60 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - uses: actions/cache@v3 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - - name: test-sim-import-export - run: | - make test-sim-nondeterminism - - test-sim-import-export: - runs-on: ubuntu-latest - needs: [build] - timeout-minutes: 60 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - uses: actions/cache@v3 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - - name: test-sim-import-export - run: | - make test-sim-import-export - - test-sim-after-import: - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - uses: actions/cache@v3 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - - name: test-sim-after-import - run: | - make test-sim-after-import - - test-sim-multi-seed-short: - runs-on: ubuntu-latest - needs: [build] - timeout-minutes: 60 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - uses: actions/cache@v3 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - - name: test-sim-multi-seed-short - run: | - make test-sim-multi-seed-short - - sims-notify-success: - needs: - [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - runs-on: ubuntu-latest - if: ${{ success() }} - steps: - - name: Check out repository - uses: actions/checkout@v3 - - name: Get previous workflow status - uses: ./.github/actions/last-workflow-status - id: last_status - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Notify Slack on success - if: ${{ steps.last_status.outputs.last_status == 'failure' }} - uses: rtCamp/action-slack-notify@v2.2.0 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: sdk-sims - SLACK_USERNAME: Sim Tests - SLACK_ICON_EMOJI: ":white_check_mark:" - SLACK_COLOR: good - SLACK_MESSAGE: Sims are passing - SLACK_FOOTER: "" - - sims-notify-failure: - permissions: - contents: none - needs: - [test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export] - runs-on: ubuntu-latest - if: ${{ failure() }} - steps: - - name: Notify Slack on failure - uses: rtCamp/action-slack-notify@v2.2.0 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: sdk-sims - SLACK_USERNAME: Sim Tests - SLACK_ICON_EMOJI: ":skull:" - SLACK_COLOR: danger - SLACK_MESSAGE: Sims are failing - SLACK_FOOTER: "" \ No newline at end of file diff --git a/simapp/app/sim_bench_test.go b/simapp/app/sim_bench_test.go deleted file mode 100644 index 7e89fce..0000000 --- a/simapp/app/sim_bench_test.go +++ /dev/null @@ -1,164 +0,0 @@ -package app - -import ( - "fmt" - "os" - "testing" - - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - 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") -} - -// Profile with: -// /usr/local/go/bin/go test -benchmem -run=^$ cosmossdk.io/simapp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out -func BenchmarkFullAppSimulation(b *testing.B) { - b.ReportAllocs() - - config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID - - db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "goleveldb-app-sim", "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" - 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 := NewChainApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) - - // 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), - BlockedAddresses(), - 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) - } -} - -func BenchmarkInvariants(b *testing.B) { - b.ReportAllocs() - - config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID - - db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-invariant-bench", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - if err != nil { - b.Fatalf("simulation setup failed: %s", err.Error()) - } - - if skip { - b.Skip("skipping benchmark application simulation") - } - - config.AllInvariants = false - - defer func() { - require.NoError(b, db.Close()) - require.NoError(b, os.RemoveAll(dir)) - }() - - appOptions := make(simtestutil.AppOptionsMap, 0) - appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - - app := NewChainApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) - - // 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), - BlockedAddresses(), - 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) - } - - ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight() + 1}) - - // 3. Benchmark each invariant separately - // - // NOTE: We use the crisis keeper as it has all the invariants registered with - // their respective metadata which makes it useful for testing/benchmarking. - for _, cr := range app.CrisisKeeper.Routes() { - cr := cr - b.Run(fmt.Sprintf("%s/%s", cr.ModuleName, cr.Route), func(b *testing.B) { - if res, stop := cr.Invar(ctx); stop { - b.Fatalf( - "broken invariant at block %d of %d\n%s", - ctx.BlockHeight()-1, config.NumBlocks, res, - ) - } - }) - } -} diff --git a/simapp/app/sim_test.go b/simapp/app/sim_test.go deleted file mode 100644 index 960884d..0000000 --- a/simapp/app/sim_test.go +++ /dev/null @@ -1,397 +0,0 @@ -package app - -import ( - "encoding/json" - "flag" - "fmt" - "math/rand" - "os" - "runtime/debug" - "strings" - "testing" - - abci "github.com/cometbft/cometbft/abci/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - dbm "github.com/cosmos/cosmos-db" - "github.com/spf13/viper" - "github.com/stretchr/testify/require" - - "cosmossdk.io/log" - "cosmossdk.io/store" - storetypes "cosmossdk.io/store/types" - "cosmossdk.io/x/feegrant" - - "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" - authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" - "github.com/cosmos/cosmos-sdk/x/simulation" - simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// SimAppChainID hardcoded chainID for simulation -const SimAppChainID = "demo" - -var FlagEnableStreamingValue bool - -// Get flags every time the simulator is run -func init() { - simcli.GetSimulatorFlags() - flag.BoolVar(&FlagEnableStreamingValue, "EnableStreaming", false, "Enable streaming service") -} - -// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of -// an IAVLStore for faster simulation speed. -func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { - bapp.SetFauxMerkleMode() -} - -// interBlockCacheOpt returns a BaseApp option function that sets the persistent -// inter-block write-through cache. -func interBlockCacheOpt() func(*baseapp.BaseApp) { - return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) -} - -func TestFullAppSimulation(t *testing.T) { - config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID - - db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - if skip { - t.Skip("skipping application simulation") - } - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, db.Close()) - require.NoError(t, os.RemoveAll(dir)) - }() - - appOptions := make(simtestutil.AppOptionsMap, 0) - appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - - app := NewChainApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) - require.Equal(t, appName, app.Name()) - - // run randomized simulation - _, simParams, simErr := simulation.SimulateFromSeed( - t, - 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), - BlockedAddresses(), - config, - app.AppCodec(), - ) - - // export state and simParams before the simulation error is checked - err = simtestutil.CheckExportSimulation(app, config, simParams) - require.NoError(t, err) - require.NoError(t, simErr) - - if config.Commit { - simtestutil.PrintStats(db) - } -} - -func TestAppImportExport(t *testing.T) { - config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID - - db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - if skip { - t.Skip("skipping application import/export simulation") - } - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, db.Close()) - require.NoError(t, os.RemoveAll(dir)) - }() - - appOptions := make(simtestutil.AppOptionsMap, 0) - appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - - app := NewChainApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) - require.Equal(t, appName, app.Name()) - - // Run randomized simulation - _, simParams, simErr := simulation.SimulateFromSeed( - t, - 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), - BlockedAddresses(), - config, - app.AppCodec(), - ) - - // export state and simParams before the simulation error is checked - err = simtestutil.CheckExportSimulation(app, config, simParams) - require.NoError(t, err) - require.NoError(t, simErr) - - if config.Commit { - simtestutil.PrintStats(db) - } - - fmt.Printf("exporting genesis...\n") - - exported, err := app.ExportAppStateAndValidators(false, []string{}, []string{}) - require.NoError(t, err) - - fmt.Printf("importing genesis...\n") - - newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, newDB.Close()) - require.NoError(t, os.RemoveAll(newDir)) - }() - - newApp := NewChainApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) - require.Equal(t, appName, newApp.Name()) - - var genesisState GenesisState - err = json.Unmarshal(exported.AppState, &genesisState) - require.NoError(t, err) - - ctxA := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) - ctxB := newApp.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) - _, err = newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState) - - if err != nil { - if strings.Contains(err.Error(), "validator set is empty after InitGenesis") { - logger.Info("Skipping simulation as all validators have been unbonded") - logger.Info("err", err, "stacktrace", string(debug.Stack())) - return - } - } - - require.NoError(t, err) - err = newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) - require.NoError(t, err) - fmt.Printf("comparing stores...\n") - - // skip certain prefixes - skipPrefixes := map[string][][]byte{ - stakingtypes.StoreKey: { - stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, - stakingtypes.HistoricalInfoKey, stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey, - stakingtypes.UnbondingTypeKey, stakingtypes.ValidatorUpdatesKey, - }, - authzkeeper.StoreKey: {authzkeeper.GrantQueuePrefix}, - feegrant.StoreKey: {feegrant.FeeAllowanceQueueKeyPrefix}, - slashingtypes.StoreKey: {slashingtypes.ValidatorMissedBlockBitmapKeyPrefix}, - } - - storeKeys := app.GetStoreKeys() - require.NotEmpty(t, storeKeys) - - for _, appKeyA := range storeKeys { - // only compare kvstores - if _, ok := appKeyA.(*storetypes.KVStoreKey); !ok { - continue - } - - keyName := appKeyA.Name() - appKeyB := newApp.GetKey(keyName) - - storeA := ctxA.KVStore(appKeyA) - storeB := ctxB.KVStore(appKeyB) - - failedKVAs, failedKVBs := simtestutil.DiffKVStores(storeA, storeB, skipPrefixes[keyName]) - require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare %s", keyName) - - require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(keyName, app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) - } -} - -func TestAppSimulationAfterImport(t *testing.T) { - config := simcli.NewConfigFromFlags() - config.ChainID = SimAppChainID - - db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - if skip { - t.Skip("skipping application simulation after import") - } - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, db.Close()) - require.NoError(t, os.RemoveAll(dir)) - }() - - appOptions := make(simtestutil.AppOptionsMap, 0) - appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - - app := NewChainApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) - require.Equal(t, appName, app.Name()) - - // Run randomized simulation - stopEarly, simParams, simErr := simulation.SimulateFromSeed( - t, - 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), - BlockedAddresses(), - config, - app.AppCodec(), - ) - - // export state and simParams before the simulation error is checked - err = simtestutil.CheckExportSimulation(app, config, simParams) - require.NoError(t, err) - require.NoError(t, simErr) - - if config.Commit { - simtestutil.PrintStats(db) - } - - if stopEarly { - fmt.Println("can't export or import a zero-validator genesis, exiting test...") - return - } - - fmt.Printf("exporting genesis...\n") - - exported, err := app.ExportAppStateAndValidators(true, []string{}, []string{}) - require.NoError(t, err) - - fmt.Printf("importing genesis...\n") - - newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue) - require.NoError(t, err, "simulation setup failed") - - defer func() { - require.NoError(t, newDB.Close()) - require.NoError(t, os.RemoveAll(newDir)) - }() - - newApp := NewChainApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) - require.Equal(t, appName, newApp.Name()) - - newApp.InitChain(&abci.RequestInitChain{ - AppStateBytes: exported.AppState, - ChainId: SimAppChainID, - }) - - _, _, err = simulation.SimulateFromSeed( - t, - os.Stdout, - newApp.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(newApp, newApp.AppCodec(), config), - BlockedAddresses(), - config, - app.AppCodec(), - ) - require.NoError(t, err) -} - -// TODO: Make another test for the fuzzer itself, which just has noOp txs -// and doesn't depend on the application. -func TestAppStateDeterminism(t *testing.T) { - if !simcli.FlagEnabledValue { - t.Skip("skipping application simulation") - } - - config := simcli.NewConfigFromFlags() - config.InitialBlockHeight = 1 - config.ExportParamsPath = "" - config.OnOperation = false - config.AllInvariants = false - config.ChainID = SimAppChainID - - numSeeds := 3 - numTimesToRunPerSeed := 3 // This used to be set to 5, but we've temporarily reduced it to 3 for the sake of faster CI. - appHashList := make([]json.RawMessage, numTimesToRunPerSeed) - - // We will be overriding the random seed and just run a single simulation on the provided seed value - if config.Seed != simcli.DefaultSeedValue { - numSeeds = 1 - } - - appOptions := viper.New() - if FlagEnableStreamingValue { - m := make(map[string]interface{}) - m["streaming.abci.keys"] = []string{"*"} - m["streaming.abci.plugin"] = "abci_v1" - 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) - if simcli.FlagVerboseValue { - appOptions.SetDefault(flags.FlagLogLevel, "debug") - } - - for i := 0; i < numSeeds; i++ { - if config.Seed == simcli.DefaultSeedValue { - config.Seed = rand.Int63() - } - - fmt.Println("config.Seed: ", config.Seed) - - for j := 0; j < numTimesToRunPerSeed; j++ { - var logger log.Logger - if simcli.FlagVerboseValue { - logger = log.NewTestLogger(t) - } else { - logger = log.NewNopLogger() - } - - db := dbm.NewMemDB() - app := NewChainApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) - - fmt.Printf( - "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", - config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, - ) - - _, _, err := simulation.SimulateFromSeed( - t, - 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), - BlockedAddresses(), - config, - app.AppCodec(), - ) - require.NoError(t, err) - - if config.Commit { - simtestutil.PrintStats(db) - } - - appHash := app.LastCommitID().Hash - appHashList[j] = appHash - - if j != 0 { - require.Equal( - t, string(appHashList[0]), string(appHashList[j]), - "non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, - ) - } - } - } -} diff --git a/x/cada/module/module.go b/x/cada/module/module.go index 8180d24..b5b78ea 100644 --- a/x/cada/module/module.go +++ b/x/cada/module/module.go @@ -12,14 +12,12 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "github.com/vitwit/avail-da-module/x/cada/client/cli" "github.com/vitwit/avail-da-module/x/cada/keeper" - simulation "github.com/vitwit/avail-da-module/x/cada/simulation" types "github.com/vitwit/avail-da-module/x/cada/types" ) @@ -173,18 +171,18 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - simulation.RandomizedGenState(simState) -} - -// RegisterStoreDecoder registers a decoder for distribution module's types -func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) { -} - -// WeightedOperations returns the all the accounts module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, simState.TxConfig, - am.authkeeper, am.bankkeeper, *am.keeper, - ) -} +// func (AppModule) GenerateGenesisState(simState *module.SimulationState) { +// simulation.RandomizedGenState(simState) +// } + +// // RegisterStoreDecoder registers a decoder for distribution module's types +// func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) { +// } + +// // WeightedOperations returns the all the accounts module operations with their respective weights. +// func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { +// return simulation.WeightedOperations( +// simState.AppParams, simState.Cdc, simState.TxConfig, +// am.authkeeper, am.bankkeeper, *am.keeper, +// ) +// } diff --git a/x/cada/simulation/genesis.go b/x/cada/simulation/genesis.go deleted file mode 100644 index 5f32926..0000000 --- a/x/cada/simulation/genesis.go +++ /dev/null @@ -1,16 +0,0 @@ -package simulation - -import ( - "github.com/cosmos/cosmos-sdk/types/module" - types "github.com/vitwit/avail-da-module/x/cada/types" -) - -// RandomizedGenState creates a randomized GenesisState for testing. -func RandomizedGenState(simState *module.SimulationState) { - // Since your GenesisState is empty, there's not much to randomize. - // We'll just set the GenesisState to its empty struct. - genesis := types.GenesisState{} - - // Here we use simState to set the default genesis - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&genesis) -} diff --git a/x/cada/simulation/oprations.go b/x/cada/simulation/oprations.go deleted file mode 100644 index 025e9e1..0000000 --- a/x/cada/simulation/oprations.go +++ /dev/null @@ -1,96 +0,0 @@ -package simulation - -import ( - "math/rand" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/vitwit/avail-da-module/x/cada/keeper" - availtypes "github.com/vitwit/avail-da-module/x/cada/types" -) - -const ( - OpWeightMsgUpdateBlobStatusRequest = "op_weight_msg_update_blob_status" - - DefaultWeightMsgUpdateStatusRequest = 100 -) - -func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, txConfig client.TxConfig, - ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, k keeper.Keeper, -) simulation.WeightedOperations { - var weightMsgUpdateBlobStatusRequest int - appParams.GetOrGenerate(OpWeightMsgUpdateBlobStatusRequest, &weightMsgUpdateBlobStatusRequest, nil, func(_ *rand.Rand) { - weightMsgUpdateBlobStatusRequest = DefaultWeightMsgUpdateStatusRequest - }) - - return simulation.WeightedOperations{ - simulation.NewWeightedOperation( - weightMsgUpdateBlobStatusRequest, - SimulateUpdateBlobStatus(txConfig, cdc, ak, bk, k), - ), - } -} - -func SimulateUpdateBlobStatus(txConfig client.TxConfig, _ codec.JSONCodec, ak authkeeper.AccountKeeper, - bk bankkeeper.Keeper, _ keeper.Keeper, -) simtypes.Operation { - return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, - ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simaAccount, _ := simtypes.RandomAcc(r, accs) - - // Ensure the account has a valid public key - account := ak.GetAccount(ctx, simaAccount.Address) - if account == nil || account.GetPubKey() == nil { - return simtypes.NoOpMsg(availtypes.ModuleName, availtypes.TypeMsgUpdateBlobStatus, "account has no pubkey"), nil, nil - } - - fromBlock := r.Uint64()%100 + 1 - toBlock := fromBlock + r.Uint64()%10 - - isSuccess := r.Intn(2) == 1 - - availHeight := r.Uint64()%100 + 1 - - blockRange := availtypes.Range{ - From: fromBlock, - To: toBlock, - } - - // Fetch spendable coins to simulate transaction fees (even if just dummy fees) - spendable := bk.SpendableCoins(ctx, simaAccount.Address) - if spendable.Empty() { - return simtypes.NoOpMsg(availtypes.ModuleName, availtypes.TypeMsgUpdateBlobStatus, "account has no spendable coins"), nil, nil - } - - // Ensure TxGen is properly initialized - if txConfig == nil { - return simtypes.NoOpMsg(availtypes.ModuleName, availtypes.TypeMsgUpdateBlobStatus, "TxGen is nil"), nil, nil - } - - msg := availtypes.NewMsgUpdateBlobStatus(simaAccount.Address.String(), blockRange, availHeight, isSuccess) - - txCtx := simulation.OperationInput{ - R: r, - App: app, - TxGen: txConfig, - Msg: msg, - Context: ctx, - SimAccount: simaAccount, - ModuleName: availtypes.ModuleName, - CoinsSpentInMsg: spendable, - } - - // Generate and deliver the transaction - return simulation.GenAndDeliverTxWithRandFees(txCtx) - - //return simtypes.NewOperationMsg(msg, true, ""), nil, nil - } -}