Skip to content

Commit

Permalink
test: Add fuzzer test with no-op transactions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
VolodymyrBg authored Jan 26, 2025
1 parent accd997 commit 511eaf7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}

0 comments on commit 511eaf7

Please sign in to comment.