Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLOB-930, CORE-29] Extend the e2e test framework to start the cosmos app using cmd. #703

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions protocol/app/ante/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package ante_test
import (
"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/dydxprotocol/v4-chain/protocol/cmd/dydxprotocold/cmd"
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
assets "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
"reflect"
Expand Down Expand Up @@ -180,12 +178,7 @@ func TestSubmitTxnWithGas(t *testing.T) {
},
}

tApp := testapp.NewTestAppBuilder(t).
WithAppOptions(
map[string]interface{}{},
baseapp.SetMinGasPrices(cmd.MinGasPrice),
).
Build()
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()

msgSendCheckTx := testapp.MustMakeCheckTxWithPrivKeySupplier(
Expand Down
5 changes: 3 additions & 2 deletions protocol/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ func TestAppIsFullyInitialized(t *testing.T) {
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
dydxApp := testapp.DefaultTestApp(tc.customFlags)
uninitializedFields := getUninitializedStructFields(reflect.ValueOf(*dydxApp))
tApp := testapp.NewTestAppBuilder(t).WithAppOptions(tc.customFlags).Build()
tApp.InitChain()
uninitializedFields := getUninitializedStructFields(reflect.ValueOf(*tApp.App))

// Note that the PriceFeedClient is currently hard coded as disabled in GetDefaultTestAppOptions.
// Normally it would be only disabled for non-validating full nodes or for nodes where the
Expand Down
17 changes: 10 additions & 7 deletions protocol/app/prepare/full_node_prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ import (
// TestFullNodePrepareProposalHandler test that the full-node PrepareProposal handler always returns
// an empty result.
func TestFullNodePrepareProposalHandler(t *testing.T) {
t.Cleanup(gometrics.Shutdown)

conf := gometrics.DefaultConfig("service")
sink := gometrics.NewInmemSink(time.Hour, time.Hour)
_, err := gometrics.NewGlobal(conf, sink)
require.NoError(t, err)

logger, logBuffer := testlog.TestLogger()
appOpts := map[string]interface{}{
flags.NonValidatingFullNodeFlag: true,
testlog.LoggerInstanceForTest: logger,
}
tApp := testApp.NewTestAppBuilder(t).WithAppOptions(appOpts).Build()
tApp.InitChain()

// Set up metrics after test app initialization to override the telemetry that it sets up.
// TODO(CLOB-930): Expose test app telemetry directly instead of requiring tests to do this setup and clean-up
// themselves.
t.Cleanup(gometrics.Shutdown)
conf := gometrics.DefaultConfig("service")
sink := gometrics.NewInmemSink(time.Hour, time.Hour)
_, err := gometrics.NewGlobal(conf, sink)
require.NoError(t, err)

found := false
tApp.AdvanceToBlock(2, testApp.AdvanceToBlockOptions{
Expand Down
4 changes: 2 additions & 2 deletions protocol/cmd/dydxprotocold/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type DydxAppConfig struct {

// initAppConfig helps to override default appConfig template and configs.
// return "", nil if no custom configuration is required for the application.
func initAppConfig() (string, interface{}) {
func initAppConfig() (string, *DydxAppConfig) {
// Optionally allow the chain developer to overwrite the SDK's default
// server config.
srvCfg := serverconfig.DefaultConfig()
Expand Down Expand Up @@ -68,7 +68,7 @@ func initAppConfig() (string, interface{}) {

appTemplate := serverconfig.DefaultConfigTemplate

return appTemplate, appConfig
return appTemplate, &appConfig
}

// initTendermintConfig helps to override default Tendermint Config values.
Expand Down
43 changes: 37 additions & 6 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,29 @@ const (

// TODO(DEC-1097): improve `cmd/` by adding tests, custom app configs, custom init cmd, and etc.
// NewRootCmd creates a new root command for `dydxprotocold`. It is called once in the main function.
func NewRootCmd(option *RootCmdOption) *cobra.Command {
func NewRootCmd(
option *RootCmdOption,
) *cobra.Command {
return NewRootCmdWithInterceptors(
option,
func(serverCtxPtr *server.Context) {

},
func(s string, appConfig *DydxAppConfig) (string, *DydxAppConfig) {
return s, appConfig
},
func(app *dydxapp.App) *dydxapp.App {
return app
},
)
}

func NewRootCmdWithInterceptors(
option *RootCmdOption,
serverCtxInterceptor func(serverCtxPtr *server.Context),
appConfigInterceptor func(string, *DydxAppConfig) (string, *DydxAppConfig),
appInterceptor func(app *dydxapp.App) *dydxapp.App,
) *cobra.Command {
encodingConfig := dydxapp.GetEncodingConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand Down Expand Up @@ -85,7 +107,7 @@ func NewRootCmd(option *RootCmdOption) *cobra.Command {
return err
}

customAppTemplate, customAppConfig := initAppConfig()
customAppTemplate, customAppConfig := appConfigInterceptor(initAppConfig())
customTMConfig := initTendermintConfig()

if err := server.InterceptConfigsPreRunHandler(
Expand All @@ -97,18 +119,25 @@ func NewRootCmd(option *RootCmdOption) *cobra.Command {
return err
}

serverCtxInterceptor(server.GetServerContextFromCmd(cmd))

return nil
},
SilenceUsage: true,
}

initRootCmd(rootCmd, option, encodingConfig)
initRootCmd(rootCmd, option, encodingConfig, appInterceptor)

return rootCmd
}

// initRootCmd initializes the app's root command with useful commands.
func initRootCmd(rootCmd *cobra.Command, option *RootCmdOption, encodingConfig dydxapp.EncodingConfig) {
func initRootCmd(
rootCmd *cobra.Command,
option *RootCmdOption,
encodingConfig dydxapp.EncodingConfig,
appInterceptor func(app *dydxapp.App) *dydxapp.App,
) {
gentxModule := basic_manager.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
rootCmd.AddCommand(
genutilcli.InitCmd(basic_manager.ModuleBasics, dydxapp.DefaultNodeHome),
Expand All @@ -131,7 +160,9 @@ func initRootCmd(rootCmd *cobra.Command, option *RootCmdOption, encodingConfig d
server.AddCommands(
rootCmd,
dydxapp.DefaultNodeHome,
a.newApp,
func(logger log.Logger, db dbm.DB, writer io.Writer, options servertypes.AppOptions) servertypes.Application {
return appInterceptor(a.newApp(logger, db, writer, options))
},
a.appExport,
func(cmd *cobra.Command) {
addModuleInitFlags(cmd)
Expand Down Expand Up @@ -222,7 +253,7 @@ func (a appCreator) newApp(
db dbm.DB,
traceStore io.Writer,
appOpts servertypes.AppOptions,
) servertypes.Application {
) *dydxapp.App {
var cache sdk.MultiStorePersistentCache

if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
Expand Down
2 changes: 1 addition & 1 deletion protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ replace (
// Use dYdX fork of CometBFT
github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.37.3-0.20230908230338-65f7a2f25c18
// Use dYdX fork of Cosmos SDK
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231011192538-b95c66dedbd5
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231025201005-bef8a051e94f
// Cosmos SDK 0.47.x upgrade guide (https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#replaces) mentions
// that there are stability issues. See https://github.com/cosmos/cosmos-sdk/issues/14949 and
// https://github.com/ethereum/go-ethereum/pull/25413 for further context.
Expand Down
4 changes: 2 additions & 2 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dydxprotocol/cometbft v0.37.3-0.20230908230338-65f7a2f25c18 h1:1RIco92QcPS24BeNCNWJC4zXza4GEHHuoviWIQEQ/NI=
github.com/dydxprotocol/cometbft v0.37.3-0.20230908230338-65f7a2f25c18/go.mod h1:cpghf0+1GJpJvrqpTHE6UyTcD05m/xllo0xpufL3PgA=
github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231011192538-b95c66dedbd5 h1:9lSntpmEJcEhc3al6YmRh51ZHINjqJmzL5it9tMK5+0=
github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231011192538-b95c66dedbd5/go.mod h1:iaAXVu5Jcd//vREctLTuxLqj5ScUP4psgqW7M6XsaQ8=
github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231025201005-bef8a051e94f h1:q1WhMJ0EjcF2Tj7MBPd+nacxmj3juiRwz11MZ+m6WAE=
github.com/dydxprotocol/cosmos-sdk v0.47.5-0.20231025201005-bef8a051e94f/go.mod h1:iaAXVu5Jcd//vREctLTuxLqj5ScUP4psgqW7M6XsaQ8=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-resiliency v1.3.0 h1:RRL0nge+cWGlxXbUzJ7yMcq6w2XBEr19dCN6HECGaT0=
github.com/eapache/go-resiliency v1.3.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
Expand Down
Loading
Loading