Skip to content

Commit

Permalink
Merge branch 'main' into marko/consensus_spinout
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Apr 25, 2024
2 parents 392c9ed + c6890b3 commit bc69c61
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.5.0
- uses: amannn/action-semantic-pull-request@v5.5.2
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
143 changes: 54 additions & 89 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package simapp
import (
"encoding/json"
"flag"
"fmt"
"math/rand"
"os"
"runtime/debug"
Expand All @@ -14,6 +13,7 @@ import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
Expand Down Expand Up @@ -58,30 +58,7 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) {
}

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 := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}
require.Equal(t, "SimApp", app.Name())

config, db, _, app := setupSimulationApp(t, "skipping application simulation")
// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
t,
Expand All @@ -97,7 +74,7 @@ func TestFullAppSimulation(t *testing.T) {
)

// export state and simParams before the simulation error is checked
err = simtestutil.CheckExportSimulation(app, config, simParams)
err := simtestutil.CheckExportSimulation(app, config, simParams)
require.NoError(t, err)
require.NoError(t, simErr)

Expand All @@ -107,29 +84,7 @@ func TestFullAppSimulation(t *testing.T) {
}

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 := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}
require.Equal(t, "SimApp", app.Name())
config, db, appOptions, app := setupSimulationApp(t, "skipping application import/export simulation")

// Run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand All @@ -146,20 +101,20 @@ func TestAppImportExport(t *testing.T) {
)

// export state and simParams before the simulation error is checked
err = simtestutil.CheckExportSimulation(app, config, simParams)
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")
t.Log("exporting genesis...\n")

exported, err := app.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err)

fmt.Printf("importing genesis...\n")
t.Log("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")
Expand All @@ -169,6 +124,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

appOptions[flags.FlagHome] = newDir // ensure a unique folder for the new app
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "SimApp", newApp.Name())

Expand All @@ -181,17 +137,17 @@ func TestAppImportExport(t *testing.T) {
_, err = newApp.ModuleManager.InitGenesis(ctxB, 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()))
t.Log("Skipping simulation as all validators have been unbonded")
t.Logf("err: %s stacktrace: %s\n", err, string(debug.Stack()))
return
}
}

require.NoError(t, err)
err = newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
require.NoError(t, err)
fmt.Printf("comparing stores...\n")

t.Log("comparing stores...")
// skip certain prefixes
skipPrefixes := map[string][][]byte{
stakingtypes.StoreKey: {
Expand Down Expand Up @@ -222,36 +178,18 @@ func TestAppImportExport(t *testing.T) {
failedKVAs, failedKVBs := simtestutil.DiffKVStores(storeA, storeB, skipPrefixes[keyName])
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare %s, key stores %s and %s", keyName, appKeyA, appKeyB)

fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), appKeyA, appKeyB)

require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(keyName, app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs))
t.Logf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), appKeyA, appKeyB)
if !assert.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(keyName, app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) {
for _, v := range failedKVAs {
t.Logf("store missmatch: %q\n", v)
}
t.FailNow()
}
}
}

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 := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}
require.Equal(t, "SimApp", app.Name())
config, db, appOptions, app := setupSimulationApp(t, "skipping application simulation after import")

// Run randomized simulation
stopEarly, simParams, simErr := simulation.SimulateFromSeed(
Expand All @@ -266,27 +204,27 @@ func TestAppSimulationAfterImport(t *testing.T) {
app.AppCodec(),
codectestutil.CodecOptions{}.GetAddressCodec(),
)
require.NoError(t, simErr)

// export state and simParams before the simulation error is checked
err = simtestutil.CheckExportSimulation(app, config, simParams)
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...")
t.Log("can't export or import a zero-validator genesis, exiting test...")
return
}

fmt.Printf("exporting genesis...\n")
t.Logf("exporting genesis...\n")

exported, err := app.ExportAppStateAndValidators(true, []string{}, []string{})
require.NoError(t, err)

fmt.Printf("importing genesis...\n")
t.Logf("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")
Expand Down Expand Up @@ -322,6 +260,33 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, err)
}

func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *SimApp) {
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(msg)
}
require.NoError(t, err, "simulation setup failed")

t.Cleanup(func() {
require.NoError(t, db.Close())
require.NoError(t, os.RemoveAll(dir))
})

appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = dir // ensure a unique folder
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}
require.Equal(t, "SimApp", app.Name())
return config, db, appOptions, app
}

// 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) {
Expand Down Expand Up @@ -355,7 +320,6 @@ func TestAppStateDeterminism(t *testing.T) {
appOptions.SetDefault(key, value)
}
}
appOptions.SetDefault(flags.FlagHome, DefaultNodeHome)
appOptions.SetDefault(server.FlagInvCheckPeriod, simcli.FlagPeriodValue)
if simcli.FlagVerboseValue {
appOptions.SetDefault(flags.FlagLogLevel, "debug")
Expand All @@ -366,7 +330,7 @@ func TestAppStateDeterminism(t *testing.T) {
config.Seed = rand.Int63()
}

fmt.Println("config.Seed: ", config.Seed)
t.Log("config.Seed: ", config.Seed)

for j := 0; j < numTimesToRunPerSeed; j++ {
var logger log.Logger
Expand All @@ -376,13 +340,14 @@ func TestAppStateDeterminism(t *testing.T) {
logger = log.NewNopLogger()
}

appOptions.SetDefault(flags.FlagHome, t.TempDir())
db := dbm.NewMemDB()
app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

fmt.Printf(
t.Logf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)
Expand Down
2 changes: 1 addition & 1 deletion store/storage/rocksdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDatabase_ReverseIterator(t *testing.T) {
// seek past domain, which should make the iterator invalid and produce an error
require.False(t, iter.Valid())

// reverse iterator with with a start and end domain
// reverse iterator with a start and end domain
iter2, err := db.ReverseIterator(storeKey1, 1, []byte("key010"), []byte("key019"))
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion store/storage/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDatabase_ReverseIterator(t *testing.T) {
// seek past domain, which should make the iterator invalid and produce an error
require.False(t, iter.Valid())

// reverse iterator with with a start and end domain
// reverse iterator with a start and end domain
iter2, err := db.ReverseIterator(storeKey1, 1, []byte("key010"), []byte("key019"))
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion store/storage/storage_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (s *StorageTestSuite) TestDatabase_Iterator() {
s.Require().False(itr.Valid())
}

// iterator with with a start and end domain over multiple versions
// iterator with a start and end domain over multiple versions
for v := uint64(1); v < 5; v++ {
itr2, err := db.Iterator(storeKey1Bytes, v, []byte("key010"), []byte("key019"))
s.Require().NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions testutil/sims/tx_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
panic(err)
}
sigs[i].Data.(*signing.SingleSignatureData).Signature = sig
err = tx.SetSignatures(sigs...)
if err != nil {
panic(err)
}
}
err = tx.SetSignatures(sigs...)
if err != nil {
panic(err)
}

return tx.GetTx(), nil
Expand Down
10 changes: 5 additions & 5 deletions tools/hubl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
cosmossdk.io/core v0.11.0
cosmossdk.io/errors v1.0.1
github.com/cockroachdb/errors v1.11.1
github.com/cosmos/cosmos-sdk v0.50.6-0.20240403102038-f63e5fdf7c96
github.com/cosmos/cosmos-sdk v0.50.6
github.com/manifoldco/promptui v0.9.0
github.com/pelletier/go-toml/v2 v2.2.1
github.com/spf13/cobra v1.8.0
Expand All @@ -33,7 +33,7 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
Expand All @@ -47,7 +47,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.12 // indirect
github.com/cosmos/iavl v1.1.1 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
Expand Down Expand Up @@ -114,7 +114,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
Expand All @@ -139,7 +139,7 @@ require (
go.etcd.io/bbolt v1.3.8 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down

0 comments on commit bc69c61

Please sign in to comment.