Skip to content

Commit

Permalink
fix test app import export
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Dec 17, 2024
1 parent bfc3cb6 commit 75c028d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 53 deletions.
33 changes: 0 additions & 33 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
//func (app *RegenApp) ExportAppStateAndValidators(
// forZeroHeight bool,
// jailAllowedAddrs []string,
// modulesToExport []string,
//) (servertypes.ExportedApp, error) {
// // as if they could withdraw from the start of the next block
// ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
//
// // We export at last height + 1, because that's the height at which
// // Tendermint will start InitChain.
// height := app.LastBlockHeight() + 1
// if forZeroHeight {
// height = 0
// app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
// }
//
// genState := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
// appState, err := json.MarshalIndent(genState, "", " ")
// if err != nil {
// return servertypes.ExportedApp{}, err
// }
//
// validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
// return servertypes.ExportedApp{
// AppState: appState,
// Validators: validators,
// Height: height,
// ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
// }, err
//}

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *RegenApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) {
Expand Down
57 changes: 37 additions & 20 deletions app/simulation/app_determinism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ package simulation
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/server"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/ibc-go/v7/testing/simapp"
"math/rand"
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
Expand All @@ -19,9 +24,11 @@ import (
regen "github.com/regen-network/regen-ledger/v5/app"
)

func TestAppDeterminism(t *testing.T) {
// 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 app-determinism simulation")
t.Skip("skipping application simulation")
}

config := simcli.NewConfigFromFlags()
Expand All @@ -32,11 +39,23 @@ func TestAppDeterminism(t *testing.T) {
config.ChainID = SimAppChainID

numSeeds := 3
numTimesToRunPerSeed := 3
numTimesToRunPerSeed := 5

// 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
}

appHashList := make([]json.RawMessage, numTimesToRunPerSeed)
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

for i := 0; i < numSeeds; i++ {
config.Seed = rand.Int63()
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
Expand All @@ -47,25 +66,24 @@ func TestAppDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()

app := regen.NewRegenApp(
logger,
db,
nil,
true,
simcli.FlagPeriodValue,
simtestutil.EmptyAppOptions{},
interBlockCacheOpt(),
baseapp.SetChainID(SimAppChainID),
)
require.Equal(t, regen.AppName, app.Name())
app := regen.NewRegenApp(logger, db, nil, true, simcli.FlagPeriodValue, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

fmt.Printf(
"running app-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)
_, _, err := simulateFromSeed(t, app, config)

_, _, 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),
simapp.BlockedAddresses(),
config,
app.AppCodec(),
)
require.NoError(t, err)

if config.Commit {
Expand All @@ -78,8 +96,7 @@ func TestAppDeterminism(t *testing.T) {
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,
"non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)
}
}
Expand Down

0 comments on commit 75c028d

Please sign in to comment.