Skip to content

Commit

Permalink
fix: sim tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Jul 12, 2024
1 parent b430fe1 commit 3fa43eb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ cover.out
coverage.txt
coverage.xml
testreport.xml
.testchains
.testchains
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ test-sim-nondeterminism:
go test ./app $(BUILD_FLAGS) -mod=readonly -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=$(FUZZ_NUM_BLOCKS) -BlockSize=$(FUZZ_BLOCK_SIZE) -Commit=true -Period=0 -v \
-NumSeeds=$(FUZZ_NUM_SEEDS) -NumTimesToRunPerSeed=$(FUZZ_NUM_RUNS_PER_SEED) -timeout 24h
@rm -rf ./app/github.com

test-sim-import-export:
go install github.com/cosmos/tools/cmd/runsim@latest
@echo "Running application import/export simulation. This may take several minutes..."
runsim -Jobs=4 -SimAppPkg=./app -ExitOnFail 10 5 TestAppImportExport
@rm -rf ./.testchains

test-unit-cosmos:
./scripts/test/run-test-unit-cosmos.sh >&2
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func New(
invCheckPeriod,
appOpts,
appparams.Bech32PrefixAccAddr,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
)

// TODO: decide if we want textual sign mode (https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/UPGRADING.md#textual-sign-mode)
Expand Down
19 changes: 12 additions & 7 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
Expand Down Expand Up @@ -159,6 +160,8 @@ func (appKeepers *AppKeepers) NewAppKeepers(
invCheckPeriod uint,
appOpts servertypes.AppOptions,
bech32Prefix string,
msgServiceRouter *baseapp.MsgServiceRouter,
grpcQueryRouter *baseapp.GRPCQueryRouter,
) {
// Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey
appKeepers.GenerateKeys()
Expand Down Expand Up @@ -359,7 +362,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICAControllerKeeper,
bApp.MsgServiceRouter(),
msgServiceRouter,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.ICAControllerKeeper = &icaControllerKeeper
Expand All @@ -373,10 +376,12 @@ func (appKeepers *AppKeepers) NewAppKeepers(
appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.ScopedICAHostKeeper,
bApp.MsgServiceRouter(),
msgServiceRouter,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.ICAHostKeeper = &icaHostKeeper
// TODO: use this with ibc-go v8.3.0 https://github.com/cosmos/ibc-go/issues/6415
// appKeepers.ICAHostKeeper.WithQueryRouter(grpcQueryRouter)

appKeepers.IcaModule = ica.NewAppModule(appKeepers.ICAControllerKeeper, appKeepers.ICAHostKeeper)

Expand Down Expand Up @@ -439,8 +444,8 @@ func (appKeepers *AppKeepers) NewAppKeepers(
appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedWasmKeeper,
appKeepers.TransferKeeper,
bApp.MsgServiceRouter(),
bApp.GRPCQueryRouter(),
msgServiceRouter,
grpcQueryRouter,
wasmDir,
wasmConfig,
supportedFeatures,
Expand All @@ -455,9 +460,9 @@ func (appKeepers *AppKeepers) NewAppKeepers(
govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). //nolint:staticcheck
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(*appKeepers.ParamsKeeper))
// TODO: test these proposals and remove these legacy handler
// AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). //nolint:staticcheck
// AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)).
// AddRoute(ibcexported.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)) //nolint:staticcheck

Expand All @@ -472,7 +477,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.DistrKeeper,
bApp.MsgServiceRouter(),
msgServiceRouter,
govConfig,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand Down Expand Up @@ -523,7 +528,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(
authzKeepper := authzkeeper.NewKeeper(
runtime.NewKVStoreService(appKeepers.keys[authzkeeper.StoreKey]),
appCodec,
bApp.MsgServiceRouter(),
msgServiceRouter,
appKeepers.AccountKeeper,
)
appKeepers.AuthzKeeper = &authzKeepper
Expand Down
1 change: 1 addition & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func appModules(
app.AppKeepers.InterchainTxsModule,
app.AppKeepers.FeeRefunderModule,
app.AppKeepers.ContractManagerModule,
consensus.NewAppModule(appCodec, *app.AppKeepers.ConsensusParamsKeeper),
}
}

Expand Down
47 changes: 32 additions & 15 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"go/build"
"math/rand"
"os"
"path"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"testing"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
tmrand "github.com/cometbft/cometbft/libs/rand"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"

Expand Down Expand Up @@ -108,20 +111,21 @@ func TestAppStateDeterminism(t *testing.T) {
t.Skip("skipping application simulation")
}

config := simcli.NewConfigFromFlags()
config.InitialBlockHeight = 1
config.ExportParamsPath = ""
config.OnOperation = false
config.AllInvariants = false
config.ChainID = SimAppChainID
appParamsConfigurationSim(t, &config)

appHashList := make([]json.RawMessage, NumTimesToRunPerSeed)

for i := 0; i < NumSeeds; i++ {
config := simcli.NewConfigFromFlags()
config.InitialBlockHeight = 1
config.ExportParamsPath = ""
config.OnOperation = false
config.AllInvariants = false

config.Seed = rand.Int63()

for j := 0; j < NumTimesToRunPerSeed; j++ {
config.ChainID = SimAppChainID + tmrand.NewRand().Str(6)
appParamsConfigurationSim(t, &config)

var logger log.Logger
if simcli.FlagVerboseValue {
logger = log.NewTestLogger(t)
Expand All @@ -137,12 +141,12 @@ func TestAppStateDeterminism(t *testing.T) {
nil,
true,
map[int64]bool{},
DefaultNodeHome,
testHomeDir(config.ChainID),
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
baseapp.SetChainID(config.ChainID),
baseapp.SetMinGasPrices("0unls"),
)

Expand Down Expand Up @@ -184,7 +188,7 @@ func TestAppStateDeterminism(t *testing.T) {
func TestAppImportExport(t *testing.T) {
sdk.DefaultBondDenom = params.DefaultBondDenom
config := simcli.NewConfigFromFlags()
config.ChainID = SimAppChainID
config.ChainID = SimAppChainID + tmrand.NewRand().Str(6)
appParamsConfigurationSim(t, &config)

db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
Expand All @@ -205,12 +209,12 @@ func TestAppImportExport(t *testing.T) {
nil,
true,
map[int64]bool{},
dir,
testHomeDir(config.ChainID),
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
baseapp.SetChainID(config.ChainID),
)
require.Equal(t, Name, nolusApp.Name())

Expand Down Expand Up @@ -250,18 +254,20 @@ func TestAppImportExport(t *testing.T) {
newDB.Close()
require.NoError(t, os.RemoveAll(newDir))
}()

config.ChainID = SimAppChainID + tmrand.NewRand().Str(6)
newNolusApp := New(
log.NewNopLogger(),
newDB,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
testHomeDir(config.ChainID),
simcli.FlagPeriodValue,
encConfig,
simtestutil.EmptyAppOptions{},
fauxMerkleModeOpt,
baseapp.SetChainID(SimAppChainID),
baseapp.SetChainID(config.ChainID),
)
require.Equal(t, Name, newNolusApp.Name())

Expand Down Expand Up @@ -358,3 +364,14 @@ func GetSimulationLog(storeName string, sdr simtypes.StoreDecoderRegistry, kvAs,
func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
bapp.SetFauxMerkleMode()
}

func RootDir() string {
_, b, _, _ := runtime.Caller(0) //nolint:dogsled
d := path.Join(path.Dir(b), "..")
return d
}

func testHomeDir(chainID string) string {
projectRoot := RootDir()
return path.Join(projectRoot, ".testchains", chainID)
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 // indirect
github.com/cosmos/admin-module => github.com/neutron-org/admin-module v1.0.2-0.20240402143659-7dcb4a8c2056

// TODO remove after neutron/x/transfer is updated so sims can pass without this replace
github.com/cosmos/ibc-go/v8 => /home/denislavivanov/go/github/ibc-go

// TODO adds --validate flag with default value 'true' on gov submit-proposal so we can validate the proposal on submission rather than directly on execution
// github.com/cosmos/cosmos-sdk => github.com/nolus-protocol/cosmos-sdk v0.47.6-nolus

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.1 h1:BHn
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.1/go.mod h1:82hPO/tRawbuFad2gPwChvpZ0JEIoNi91LwVneAYCeM=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ=
github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/interchain-security/v5 v5.0.0-rc0 h1:Sh5CDqLDS32q2WsO9k5j3NyBzmW+mm66c+kgRniCthA=
Expand Down

0 comments on commit 3fa43eb

Please sign in to comment.