Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jan 8, 2025
1 parent 48b6069 commit 28caf29
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/v2/appmanager/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ func (a appManager[T]) DeliverSims(
}

if latestVersion+1 != block.Height {
return nil, nil, fmt.Errorf("invalid DeliverBlock height wanted %d, got %d", latestVersion+1, block.Height)
return nil, nil, fmt.Errorf("invalid DeliverSims height wanted %d, got %d", latestVersion+1, block.Height)
}

blockResponse, newState, err := a.stf.DeliverSims(ctx, block, currentState, simsBuilder)
if err != nil {
return nil, nil, fmt.Errorf("block delivery failed: %w", err)
return nil, nil, fmt.Errorf("sims delivery failed: %w", err)
}

return blockResponse, newState, nil
Expand Down
21 changes: 18 additions & 3 deletions simapp/v2/sim_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,32 @@ func SetupTestInstance[T Tx, V SimulationApp[T]](t *testing.T, factory AppFactor
}

// RunWithSeeds runs a series of subtests using the default set of random seeds for deterministic simulation testing.
func RunWithSeeds[T Tx](t *testing.T, seeds []int64) {
func RunWithSeeds[T Tx](
t *testing.T,
seeds []int64,
postRunActions ...func(t testing.TB, app TestInstance[T], accs []simtypes.Account),
) {
t.Helper()
cfg := cli.NewConfigFromFlags()
cfg.ChainID = SimAppChainID
for i := range seeds {
seed := seeds[i]
t.Run(fmt.Sprintf("seed: %d", seed), func(t *testing.T) {
t.Parallel()
RunWithSeed(t, NewSimApp[T], AppConfig(), cfg, seed)
RunWithSeed(t, NewSimApp[T], AppConfig(), cfg, seed, postRunActions...)
})
}
}

// RunWithSeed initializes and executes a simulation run with the given seed, generating blocks and transactions.
func RunWithSeed[T Tx, V SimulationApp[T]](t *testing.T, appFactory AppFactory[T, V], appConfig depinject.Config, tCfg simtypes.Config, seed int64) {
func RunWithSeed[T Tx, V SimulationApp[T]](
t *testing.T,
appFactory AppFactory[T, V],
appConfig depinject.Config,
tCfg simtypes.Config,
seed int64,
postRunActions ...func(t testing.TB, app TestInstance[T], accs []simtypes.Account),
) {
t.Helper()
r := rand.New(rand.NewSource(seed))
testInstance := SetupTestInstance[T, V](t, appFactory, appConfig)
Expand Down Expand Up @@ -209,6 +220,10 @@ func RunWithSeed[T Tx, V SimulationApp[T]](t *testing.T, appFactory AppFactory[T
testInstance.StakingKeeper,
)
require.NoError(t, testInstance.App.Close(), "closing app")

for _, step := range postRunActions {
step(t, testInstance, accounts)
}
}

// prepareInitialGenesisState initializes the genesis state for simulation by generating accounts, app state, chain ID, and timestamp.
Expand Down

0 comments on commit 28caf29

Please sign in to comment.