From 511eaf7366cbfc52fc73c461123c19c238ba7076 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Sun, 26 Jan 2025 12:55:59 +0200 Subject: [PATCH] test: Add fuzzer test with no-op transactions This commit adds a new test that validates the transaction fuzzer's behavior using no-operation transactions. The test ensures that the fuzzer can: - Process transactions independently of application logic - Complete a simulation successfully - Maintain expected block height The test is designed to be fast and focused, running for only 10 blocks with minimal setup. This helps validate the fuzzer's core functionality without being affected by application-specific behavior. Resolves TODO in app/sim_test.go --- app/sim_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/app/sim_test.go b/app/sim_test.go index 839f144d6b..5733401a49 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" + sdk "github.com/cosmos/cosmos-sdk/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simulation2 "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -148,3 +149,71 @@ func TestAppStateDeterminism(t *testing.T) { } } } + +// TestFuzzerWithNoOpTxs tests the transaction fuzzer with no-operation transactions +// to verify the fuzzer's behavior independently of the application logic. +func TestFuzzerWithNoOpTxs(t *testing.T) { + if !sim.FlagEnabledValue { + t.Skip("skipping fuzzer simulation") + } + + config := sim.NewConfigFromFlags() + config.InitialBlockHeight = 1 + config.ExportParamsPath = "" + config.OnOperation = false + config.AllInvariants = false + config.ChainID = AppChainID + config.NumBlocks = 10 // Keep test short but meaningful + + // Create a minimal application setup + logger := log.NewNopLogger() + db := dbm.NewMemDB() + dir, err := os.MkdirTemp("", "gaia-fuzzer-test") + require.NoError(t, err) + defer os.RemoveAll(dir) + + appOptions := make(simtestutil.AppOptionsMap, 0) + appOptions[flags.FlagHome] = dir + appOptions[server.FlagInvCheckPeriod] = sim.FlagPeriodValue + + app := gaia.NewGaiaApp( + logger, + db, + nil, + true, + map[int64]bool{}, + dir, + appOptions, + emptyWasmOption, + interBlockCacheOpt(), + baseapp.SetChainID(AppChainID), + ) + + // Create simulation manager with only no-op operations + operations := []simulation2.WeightedOperation{ + { + Weight: 100, + Op: simulation2.Operation(func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, + accs []simulation2.Account, chainID string) (simulation2.OperationMsg, []simulation2.FutureOperation, error) { + return simulation2.NewOperationMsg(&sdk.Msg{}, true, "", nil), nil, nil + }), + }, + } + + // Run simulation + _, _, err = simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.ModuleBasics.DefaultGenesis(app.AppCodec())), + simulation2.RandomAccounts, + operations, + app.BlockedModuleAccountAddrs(app.ModuleAccountAddrs()), + config, + app.AppCodec(), + ) + require.NoError(t, err) + + // Verify that simulation completed successfully + require.Equal(t, uint64(config.NumBlocks), app.LastBlockHeight()) +}