From 672c30472fa59e34f31fd7ace2424e393b2bfaf3 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 28 Nov 2023 10:47:08 -0500 Subject: [PATCH] fix: build and integration (#33) * refactor * clean * rename * clean * fix * fix --- Makefile | 20 +-- go.mod | 12 +- go.sum | 16 +- tests/{simapp => app}/ante.go | 2 +- tests/{simapp => app}/app.go | 150 ++++++++---------- tests/{simapp => app}/config.go | 35 +--- tests/{simapp => app}/export.go | 6 +- .../testappd => app/feemarketd/cmd}/root.go | 32 ++-- tests/{simapp => app}/feemarketd/main.go | 6 +- tests/{simapp => app}/params/encoding.go | 0 tests/integration/integration_test.go | 13 +- tests/integration/setup.go | 21 +++ tests/integration/suite.go | 14 ++ x/feemarket/client/cli/query.go | 17 +- x/feemarket/types/state_fuzz_test.go | 3 +- 15 files changed, 178 insertions(+), 169 deletions(-) rename tests/{simapp => app}/ante.go (99%) rename tests/{simapp => app}/app.go (81%) rename tests/{simapp => app}/config.go (84%) rename tests/{simapp => app}/export.go (95%) rename tests/{simapp/feemarketd/testappd => app/feemarketd/cmd}/root.go (89%) rename tests/{simapp => app}/feemarketd/main.go (56%) rename tests/{simapp => app}/params/encoding.go (100%) diff --git a/Makefile b/Makefile index 0f2668f..3b0213f 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,8 @@ whitespace += $(whitespace) comma := , build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) -ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=testapp \ - -X github.com/cosmos/cosmos-sdk/version.AppName=testappd \ +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=feemarket \ + -X github.com/cosmos/cosmos-sdk/version.AppName=feemarketd \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ @@ -80,7 +80,7 @@ BUILD_TARGETS := build-test-app build-test-app: BUILD_ARGS=-o $(BUILD_DIR)/ $(BUILD_TARGETS): $(BUILD_DIR)/ - cd $(CURDIR)/tests/simapp && go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... + cd $(CURDIR)/tests/app && go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... $(BUILD_DIR)/: mkdir -p $(BUILD_DIR)/ @@ -90,13 +90,13 @@ $(BUILD_DIR)/: # other addresses using "genesis add-genesis-account address 10000000000000000000000000stake". # This will allow users to bootstrap their wallet with a balance. build-and-start-app: build-test-app - ./build/testappd init validator1 --chain-id chain-id-0 - ./build/testappd keys add validator1 - ./build/testappd genesis add-genesis-account validator1 10000000000000000000000000stake - ./build/testappd genesis add-genesis-account cosmos1see0htr47uapjvcvh0hu6385rp8lw3em24hysg 10000000000000000000000000stake - ./build/testappd genesis gentx validator1 1000000000stake --chain-id chain-id-0 - ./build/testappd genesis collect-gentxs - ./build/testappd start --api.enable true --api.enabled-unsafe-cors true --log_level info + ./build/feemarketd init validator1 --chain-id chain-id-0 + ./build/feemarketd keys add validator1 + ./build/feemarketd genesis add-genesis-account validator1 10000000000000000000000000stake + ./build/feemarketd genesis add-genesis-account cosmos1see0htr47uapjvcvh0hu6385rp8lw3em24hysg 10000000000000000000000000stake + ./build/feemarketd genesis gentx validator1 1000000000stake --chain-id chain-id-0 + ./build/feemarketd genesis collect-gentxs + ./build/feemarketd start --api.enable true --api.enabled-unsafe-cors true --log_level info .PHONY: build-test-app build-and-start-app diff --git a/go.mod b/go.mod index d2a35c1..6f69bdf 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,17 @@ module github.com/skip-mev/feemarket go 1.21.4 require ( - cosmossdk.io/api v0.7.2 - cosmossdk.io/core v0.11.0 + cosmossdk.io/api v0.3.1 + cosmossdk.io/core v0.5.1 cosmossdk.io/depinject v1.0.0-alpha.4 + cosmossdk.io/errors v1.0.0 cosmossdk.io/log v1.2.1 - cosmossdk.io/math v1.1.3-rc.1 + cosmossdk.io/math v1.2.0 github.com/client9/misspell v0.3.4 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 - github.com/cosmos/cosmos-proto v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.47.5 + github.com/cosmos/cosmos-proto v1.0.0-beta.2 + github.com/cosmos/cosmos-sdk v0.47.6 github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.3 github.com/golangci/golangci-lint v1.55.2 @@ -35,7 +36,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.4 // indirect cloud.google.com/go/storage v1.30.1 // indirect - cosmossdk.io/errors v1.0.0 // indirect cosmossdk.io/tools/rosetta v0.2.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/4meepo/tagalign v1.3.3 // indirect diff --git a/go.sum b/go.sum index e0c21cd..a1388f8 100644 --- a/go.sum +++ b/go.sum @@ -399,16 +399,16 @@ cloud.google.com/go/workflows v1.8.0/go.mod h1:ysGhmEajwZxGn1OhGOGKsTXc5PyxOc0vf cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT3ujaO/WwSA= cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= -cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= -cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w= +cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= +cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk= cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= -cosmossdk.io/math v1.1.3-rc.1 h1:NebCNWDqb1MJRNfvxr4YY7d8FSYgkuB3L75K6xvM+Zo= -cosmossdk.io/math v1.1.3-rc.1/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= +cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= +cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw= cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= @@ -603,10 +603,10 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= -github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.47.5 h1:n1+WjP/VM/gAEOx3TqU2/Ny734rj/MX1kpUnn7zVJP8= -github.com/cosmos/cosmos-sdk v0.47.5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8= +github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= +github.com/cosmos/cosmos-sdk v0.47.6 h1:uyo/eg9NMB66aQZIZUv/LeOPTdSnsU23wZkgFYpjikQ= +github.com/cosmos/cosmos-sdk v0.47.6/go.mod h1:xTc1chW8HyUWCfrgGbjS5jNu9RzlPVrBNfbL9RmZUio= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= diff --git a/tests/simapp/ante.go b/tests/app/ante.go similarity index 99% rename from tests/simapp/ante.go rename to tests/app/ante.go index a478fe0..b4ff0a1 100644 --- a/tests/simapp/ante.go +++ b/tests/app/ante.go @@ -1,4 +1,4 @@ -package simapp +package app import ( errorsmod "cosmossdk.io/errors" diff --git a/tests/simapp/app.go b/tests/app/app.go similarity index 81% rename from tests/simapp/app.go rename to tests/app/app.go index 6fb5f3b..2eec646 100644 --- a/tests/simapp/app.go +++ b/tests/app/app.go @@ -1,9 +1,8 @@ -//go:build !app_v1 - -package simapp +package app +//nolint:revive import ( - "encoding/json" + _ "embed" "io" "os" "path/filepath" @@ -22,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -32,8 +32,6 @@ import ( authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/x/capability" - capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" consensus "github.com/cosmos/cosmos-sdk/x/consensus" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -53,7 +51,6 @@ import ( groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper" nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" @@ -67,11 +64,17 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - "github.com/skip-mev/feemarket/x/feemarket" + feemarketmodule "github.com/skip-mev/feemarket/x/feemarket" feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" ) +const ( + ChainID = "chain-id-0" +) + var ( + BondDenom = sdk.DefaultBondDenom + // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -82,7 +85,6 @@ var ( auth.AppModuleBasic{}, genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), bank.AppModuleBasic{}, - capability.AppModuleBasic{}, staking.AppModuleBasic{}, mint.AppModuleBasic{}, distr.AppModuleBasic{}, @@ -104,20 +106,19 @@ var ( vesting.AppModuleBasic{}, nftmodule.AppModuleBasic{}, consensus.AppModuleBasic{}, - feemarket.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + feemarketmodule.AppModuleBasic{}, ) ) var ( - _ runtime.AppI = (*SimApp)(nil) - _ servertypes.Application = (*SimApp)(nil) + _ runtime.AppI = (*TestApp)(nil) + _ servertypes.Application = (*TestApp)(nil) ) -// SimApp extends an ABCI application, but with most of its parameters exported. -// They are exported for convenience in creating helper functions, as object -// capabilities aren't needed for testing. -type SimApp struct { +type TestApp struct { *runtime.App + legacyAmino *codec.LegacyAmino appCodec codec.Codec txConfig client.TxConfig @@ -126,7 +127,6 @@ type SimApp struct { // keepers AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper @@ -137,15 +137,10 @@ type SimApp struct { ParamsKeeper paramskeeper.Keeper AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper GroupKeeper groupkeeper.Keeper - NFTKeeper nftkeeper.Keeper ConsensusParamsKeeper consensuskeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper FeeMarketKeeper feemarketkeeper.Keeper - - // simulation manager - sm *module.SimulationManager - ModuleManager *module.Manager } func init() { @@ -154,20 +149,19 @@ func init() { panic(err) } - DefaultNodeHome = filepath.Join(userHomeDir, ".simapp") + DefaultNodeHome = filepath.Join(userHomeDir, ".feemarket") } -// NewSimApp returns a reference to an initialized SimApp. -func NewSimApp( +func New( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), -) *SimApp { +) *TestApp { var ( - app = &SimApp{} + app = &TestApp{} appBuilder *runtime.AppBuilder // merge the AppConfig and other configuration in one config @@ -211,7 +205,6 @@ func NewSimApp( &app.interfaceRegistry, &app.AccountKeeper, &app.BankKeeper, - &app.CapabilityKeeper, &app.StakingKeeper, &app.SlashingKeeper, &app.MintKeeper, @@ -224,7 +217,6 @@ func NewSimApp( &app.EvidenceKeeper, &app.FeeGrantKeeper, &app.GroupKeeper, - &app.NFTKeeper, &app.ConsensusParamsKeeper, &app.FeeMarketKeeper, ); err != nil { @@ -259,10 +251,8 @@ func NewSimApp( app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) - // ---------------------------------------------------------------------------- // - // ------------------------- Begin Custom Code -------------------------------- // - // ---------------------------------------------------------------------------- // - + // Create a global ante handler that will be called on each transaction when + // proposals are being built and verified. handlerOptions := ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, @@ -270,27 +260,27 @@ func NewSimApp( SigGasConsumer: ante.DefaultSigVerificationGasConsumer, SignModeHandler: app.txConfig.SignModeHandler(), } - options := HandlerOptions{ - BaseOptions: handlerOptions, - } - anteHandler, err := NewAnteHandler(options) + + anteHandler, err := ante.NewAnteHandler(handlerOptions) if err != nil { panic(err) } + app.App.SetAnteHandler(anteHandler) + // ---------------------------------------------------------------------------- // + // ------------------------- End Custom Code ---------------------------------- // + // ---------------------------------------------------------------------------- // + /**** Module Options ****/ app.ModuleManager.RegisterInvariants(app.CrisisKeeper) - // create the simulation manager and define the order of the modules for deterministic simulations - // - // NOTE: this is not required apps that don't use the simulator for fuzz testing - // transactions - overrideModules := map[string]module.AppModuleSimulation{} - app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. + // app.RegisterUpgradeHandlers() - app.sm.RegisterStoreDecoders() + // add test gRPC service for testing gRPC queries in isolation + // testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) // A custom InitChainer can be set if extra pre-init-genesis logic is required. // By default, when using app wiring enabled module, this is not required. @@ -310,19 +300,21 @@ func NewSimApp( return app } -// Name returns the name of the App -func (app *SimApp) Name() string { return app.BaseApp.Name() } - -// LoadHeight loads a particular height -func (app *SimApp) LoadHeight(height int64) error { - return app.LoadVersion(height) +// ChainID gets chainID from private fields of BaseApp +// Should be removed once SDK 0.50.x will be adopted +func (app *TestApp) ChainID() string { + field := reflect.ValueOf(app.BaseApp).Elem().FieldByName("chainID") + return field.String() } +// Name returns the name of the App +func (app *TestApp) Name() string { return app.BaseApp.Name() } + // LegacyAmino returns SimApp's amino codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *SimApp) LegacyAmino() *codec.LegacyAmino { +func (app *TestApp) LegacyAmino() *codec.LegacyAmino { return app.legacyAmino } @@ -330,60 +322,48 @@ func (app *SimApp) LegacyAmino() *codec.LegacyAmino { // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *SimApp) AppCodec() codec.Codec { +func (app *TestApp) AppCodec() codec.Codec { return app.appCodec } +// InterfaceRegistry returns SimApp's InterfaceRegistry +func (app *TestApp) InterfaceRegistry() codectypes.InterfaceRegistry { + return app.interfaceRegistry +} + // TxConfig returns SimApp's TxConfig -func (app *SimApp) TxConfig() client.TxConfig { +func (app *TestApp) TxConfig() client.TxConfig { return app.txConfig } -// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. -func (app *SimApp) DefaultGenesis() map[string]json.RawMessage { - return ModuleBasics.DefaultGenesis(app.appCodec) +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *TestApp) GetKey(storeKey string) *storetypes.KVStoreKey { + sk := app.UnsafeFindStoreKey(storeKey) + kvStoreKey, ok := sk.(*storetypes.KVStoreKey) + if !ok { + return nil + } + return kvStoreKey } // GetSubspace returns a param subspace for a given module name. // // NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace { +func (app *TestApp) GetSubspace(moduleName string) paramstypes.Subspace { subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) return subspace } // SimulationManager implements the SimulationApp interface -func (app *SimApp) SimulationManager() *module.SimulationManager { - return app.sm -} - -// ChainID gets chainID from private fields of BaseApp -// Should be removed once SDK 0.50.x will be adopted -func (app *SimApp) ChainID() string { - field := reflect.ValueOf(app.BaseApp).Elem().FieldByName("chainID") - return field.String() -} - -// InterfaceRegistry returns SimApp's InterfaceRegistry -func (app *SimApp) InterfaceRegistry() codectypes.InterfaceRegistry { - return app.interfaceRegistry -} - -// GetKey returns the KVStoreKey for the provided store key. -// -// NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { - sk := app.UnsafeFindStoreKey(storeKey) - kvStoreKey, ok := sk.(*storetypes.KVStoreKey) - if !ok { - return nil - } - return kvStoreKey +func (app *TestApp) SimulationManager() *module.SimulationManager { + return nil } // RegisterAPIRoutes registers all application module routes with the provided // API server. -func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { +func (app *TestApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) // register swagger API in app.go so that other applications can override easily if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { diff --git a/tests/simapp/config.go b/tests/app/config.go similarity index 84% rename from tests/simapp/config.go rename to tests/app/config.go index 341789e..53b6375 100644 --- a/tests/simapp/config.go +++ b/tests/app/config.go @@ -1,4 +1,4 @@ -package simapp +package app import ( "time" @@ -44,23 +44,6 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "google.golang.org/protobuf/types/known/durationpb" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/genutil" - _ "github.com/cosmos/cosmos-sdk/x/gov" - _ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects - - _ "github.com/skip-mev/feemarket/x/feemarket" // import for side-effects - feemarketmodulev1 "github.com/skip-mev/feemarket/api/feemarket/feemarket/module/v1" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) @@ -85,11 +68,11 @@ var ( moduleAccPerms = []*authmodulev1.ModuleAccountPermission{ {Account: authtypes.FeeCollectorName}, {Account: distrtypes.ModuleName}, - {Account: feemarkettypes.ModuleName}, {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, {Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}}, + {Account: feemarkettypes.ModuleName, Permissions: []string{}}, } // blocked account addresses @@ -109,7 +92,7 @@ var ( { Name: "runtime", Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "SimApp", + AppName: "TestApp", // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. @@ -133,8 +116,8 @@ var ( group.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, + feemarkettypes.ModuleName, consensustypes.ModuleName, - feemarkettypes.ModuleName, // TODO is this the right order? }, EndBlockers: []string{ crisistypes.ModuleName, @@ -155,7 +138,7 @@ var ( consensustypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - feemarkettypes.ModuleName, // TODO is this the right order? + feemarkettypes.ModuleName, }, OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ { @@ -176,7 +159,7 @@ var ( Config: appconfig.WrapAny(&authmodulev1.Module{ Bech32Prefix: "cosmos", ModuleAccountPermissions: moduleAccPerms, - // By default, modules authority is the governance module. This is configurable with the following: + // By default modules authority is the governance module. This is configurable with the following: // Authority: "group", // A custom module authority can be set using a module name // Authority: "cosmos1cwwv22j5ca08ggdv9c2uky355k908694z577tv", // or a specific address }), @@ -255,10 +238,8 @@ var ( Config: appconfig.WrapAny(&consensusmodulev1.Module{}), }, { - Name: feemarkettypes.ModuleName, - Config: appconfig.WrapAny(&feemarketmodulev1.Module{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - }), + Name: feemarkettypes.ModuleName, + Config: appconfig.WrapAny(&feemarketmodulev1.Module{}), }, }, }) diff --git a/tests/simapp/export.go b/tests/app/export.go similarity index 95% rename from tests/simapp/export.go rename to tests/app/export.go index 6dff0d6..7cb309f 100644 --- a/tests/simapp/export.go +++ b/tests/app/export.go @@ -1,4 +1,4 @@ -package simapp +package app import ( "encoding/json" @@ -16,7 +16,7 @@ import ( // ExportAppStateAndValidators exports the state of the application for a genesis // file. -func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) { +func (app *TestApp) 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()}) @@ -47,7 +47,7 @@ func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAd // NOTE zero height genesis is a temporary feature which will be deprecated // // in favour of export at a block height -func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { +func (app *TestApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false // check if there is a allowed address list diff --git a/tests/simapp/feemarketd/testappd/root.go b/tests/app/feemarketd/cmd/root.go similarity index 89% rename from tests/simapp/feemarketd/testappd/root.go rename to tests/app/feemarketd/cmd/root.go index 28649eb..2b836f8 100644 --- a/tests/simapp/feemarketd/testappd/root.go +++ b/tests/app/feemarketd/cmd/root.go @@ -1,4 +1,4 @@ -package testappd +package cmd import ( "errors" @@ -27,13 +27,13 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/skip-mev/feemarket/tests/simapp" - "github.com/skip-mev/feemarket/tests/simapp/params" + "github.com/skip-mev/feemarket/tests/app" + "github.com/skip-mev/feemarket/tests/app/params" ) func NewRootCmd() *cobra.Command { // we "pre"-instantiate the application for getting the injected/configured encoding configuration - simApp := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) + simApp := app.New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome)) encodingConfig := params.EncodingConfig{ InterfaceRegistry: simApp.InterfaceRegistry(), Codec: simApp.AppCodec(), @@ -48,11 +48,11 @@ func NewRootCmd() *cobra.Command { WithLegacyAmino(encodingConfig.Amino). WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). - WithHomeDir(simapp.DefaultNodeHome). + WithHomeDir(app.DefaultNodeHome). WithViper("") rootCmd := &cobra.Command{ - Use: "testappd", + Use: "cmd", Short: "Skip FeeMarket simulation application", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { // set the default command outputs @@ -159,13 +159,13 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { cfg.Seal() rootCmd.AddCommand( - genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome), + genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), debug.Cmd(), config.Cmd(), pruning.PruningCmd(newApp), ) - server.AddCommands(rootCmd, simapp.DefaultNodeHome, newApp, appExport, addModuleInitFlags) + server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, appExport, addModuleInitFlags) // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( @@ -173,7 +173,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { genesisCommand(encodingConfig), queryCommand(), txCommand(), - keys.Commands(simapp.DefaultNodeHome), + keys.Commands(app.DefaultNodeHome), ) } @@ -182,7 +182,7 @@ func addModuleInitFlags(startCmd *cobra.Command) { } func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { - cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, simapp.ModuleBasics, simapp.DefaultNodeHome) + cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, app.ModuleBasics, app.DefaultNodeHome) for _, subCmd := range cmds { cmd.AddCommand(subCmd) @@ -209,7 +209,7 @@ func queryCommand() *cobra.Command { authcmd.QueryTxCmd(), ) - simapp.ModuleBasics.AddQueryCommands(cmd) + app.ModuleBasics.AddQueryCommands(cmd) return cmd } @@ -235,7 +235,7 @@ func txCommand() *cobra.Command { authcmd.GetAuxToFeeCommand(), ) - simapp.ModuleBasics.AddTxCommands(cmd) + app.ModuleBasics.AddTxCommands(cmd) return cmd } @@ -248,7 +248,7 @@ func newApp( ) servertypes.Application { baseAppOpts := server.DefaultBaseappOptions(appOpts) - return simapp.NewSimApp( + return app.New( logger, db, traceStore, @@ -268,7 +268,7 @@ func appExport( appOpts servertypes.AppOptions, modulesToExport []string, ) (servertypes.ExportedApp, error) { - var testApp *simapp.SimApp + var testApp *app.TestApp // this check is necessary as we use the flag in x/upgrade. // we can exit more gracefully by checking the flag here. @@ -287,13 +287,13 @@ func appExport( appOpts = viperAppOpts if height != -1 { - testApp = simapp.NewSimApp(logger, db, traceStore, false, appOpts) + testApp = app.New(logger, db, traceStore, false, appOpts) if err := testApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - testApp = simapp.NewSimApp(logger, db, traceStore, true, appOpts) + testApp = app.New(logger, db, traceStore, true, appOpts) } return testApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/tests/simapp/feemarketd/main.go b/tests/app/feemarketd/main.go similarity index 56% rename from tests/simapp/feemarketd/main.go rename to tests/app/feemarketd/main.go index 8036ee7..74748bc 100644 --- a/tests/simapp/feemarketd/main.go +++ b/tests/app/feemarketd/main.go @@ -6,13 +6,13 @@ import ( "cosmossdk.io/log" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/skip-mev/feemarket/tests/simapp" - cmd "github.com/skip-mev/feemarket/tests/simapp/feemarketd/testappd" + "github.com/skip-mev/feemarket/tests/app" + cmd "github.com/skip-mev/feemarket/tests/app/feemarketd/cmd" ) func main() { rootCmd := cmd.NewRootCmd() - if err := svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome); err != nil { + if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil { log.NewLogger(rootCmd.OutOrStderr()).Error("failure when running app", "err", err) os.Exit(1) } diff --git a/tests/simapp/params/encoding.go b/tests/app/params/encoding.go similarity index 100% rename from tests/simapp/params/encoding.go rename to tests/app/params/encoding.go diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 5b98ea7..71e5624 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/strangelove-ventures/interchaintest/v7" + interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -30,7 +30,12 @@ var ( noHostMount = false gasAdjustment = 2.0 - genesisKV []cosmos.GenesisKV + genesisKV = []cosmos.GenesisKV{ + { + Key: "app_state.feemarket.params", + Value: feemarkettypes.DefaultParams(), + }, + } consensusParams = ictestutil.Toml{ "timeout_commit": "3500ms", @@ -53,11 +58,11 @@ var ( Name: "feemarket", Denom: denom, ChainID: "chain-id-0", - Bin: "testappd", + Bin: "feemarketd", Bech32Prefix: "cosmos", CoinType: "118", GasAdjustment: gasAdjustment, - GasPrices: fmt.Sprintf("0%s", denom), + GasPrices: fmt.Sprintf("20%s", denom), TrustingPeriod: "48h", NoHostMount: noHostMount, ModifyGenesis: cosmos.ModifyGenesis(genesisKV), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index ae37422..a92d193 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -34,6 +34,8 @@ import ( "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + "github.com/skip-mev/feemarket/x/feemarket/types" ) type KeyringOverride struct { @@ -232,6 +234,25 @@ func (s *TestSuite) BroadcastTxsWithCallback( return rawTxs } +func (s *TestSuite) QueryParams() types.Params { + // cast chain to cosmos-chain + cosmosChain, ok := s.chain.(*cosmos.CosmosChain) + s.Require().True(ok) + // get nodes + nodes := cosmosChain.Nodes() + s.Require().True(len(nodes) > 0) + + // make params query to first node + resp, _, err := nodes[0].ExecQuery(context.Background(), "feemarket", "params") + s.Require().NoError(err) + + // unmarshal params + var params types.Params + err = s.cdc.UnmarshalJSON(resp, ¶ms) + s.Require().NoError(err) + return params +} + // QueryValidators queries for all the network's validators func (s *TestSuite) QueryValidators(chain *cosmos.CosmosChain) []sdk.ValAddress { s.T().Helper() diff --git a/tests/integration/suite.go b/tests/integration/suite.go index c2ab65c..ce0276e 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -3,6 +3,8 @@ package integration import ( "context" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,6 +37,8 @@ type TestSuite struct { // broadcaster is the RPC interface to the ITS network bc *cosmos.Broadcaster + + cdc codec.Codec } func NewIntegrationTestSuiteFromSpec(spec *interchaintest.ChainSpec) *TestSuite { @@ -79,6 +83,8 @@ func (s *TestSuite) SetupSuite() { // create the broadcaster s.T().Log("creating broadcaster") s.setupBroadcaster() + + s.cdc = s.chain.Config().EncodingConfig.Codec } func (s *TestSuite) TearDownSuite() { @@ -93,3 +99,11 @@ func (s *TestSuite) SetupSubTest() { s.Require().NoError(err) s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1) } + +func (s *TestSuite) TestQueryParams() { + // query params + params := s.QueryParams() + + // expect validate to pass + require.NoError(s.T(), params.ValidateBasic(), params) +} diff --git a/x/feemarket/client/cli/query.go b/x/feemarket/client/cli/query.go index e1fded7..d36139b 100644 --- a/x/feemarket/client/cli/query.go +++ b/x/feemarket/client/cli/query.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" "github.com/skip-mev/feemarket/x/feemarket/types" @@ -13,9 +14,11 @@ import ( func GetQueryCmd() *cobra.Command { // create base command cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - RunE: client.ValidateCmd, + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, } // add sub-commands @@ -28,7 +31,7 @@ func GetQueryCmd() *cobra.Command { // GetParamsCmd returns the cli-command that queries the current feemarket parameters. func GetParamsCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "params", Short: "Query for the current feemarket parameters", Args: cobra.NoArgs, @@ -44,7 +47,11 @@ func GetParamsCmd() *cobra.Command { return err } - return clientCtx.PrintProto(resp) + return clientCtx.PrintProto(&resp.Params) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/feemarket/types/state_fuzz_test.go b/x/feemarket/types/state_fuzz_test.go index 661eaca..66c6a2f 100644 --- a/x/feemarket/types/state_fuzz_test.go +++ b/x/feemarket/types/state_fuzz_test.go @@ -4,8 +4,9 @@ import ( "testing" "cosmossdk.io/math" - "github.com/skip-mev/feemarket/x/feemarket/types" "github.com/stretchr/testify/require" + + "github.com/skip-mev/feemarket/x/feemarket/types" ) func FuzzDefaultFeeMarket(f *testing.F) {