Skip to content

Commit

Permalink
Make app runnable without creating default home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-dydx committed Feb 9, 2024
1 parent 6249e97 commit d6b28ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 12 additions & 2 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ const (
// TODO(DEC-1097): improve `cmd/` by adding tests, custom app configs, custom init cmd, and etc.
func NewRootCmd(
option *RootCmdOption,
homeDir string,
) *cobra.Command {
return NewRootCmdWithInterceptors(
option,
homeDir,
tempDir(),
func(serverCtxPtr *server.Context) {

},
Expand Down Expand Up @@ -165,6 +164,7 @@ func NewRootCmdWithInterceptors(
if err != nil {
panic(err)
}
initClientCtx.HomeDir = ""
if err := autoCliOpts(tempApp, initClientCtx).EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down Expand Up @@ -424,3 +424,13 @@ func appExport(

return dydxApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
}

var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = dydxapp.DefaultNodeHome
}
defer os.RemoveAll(dir)

return dir
}
2 changes: 1 addition & 1 deletion protocol/cmd/dydxprotocold/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
config.SetupConfig()

option := cmd.GetOptionWithCustomStartCmd()
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)
rootCmd := cmd.NewRootCmd(option)

cmd.AddTendermintSubcommands(rootCmd)
cmd.AddInitCmdPostRunE(rootCmd)
Expand Down
3 changes: 1 addition & 2 deletions protocol/testing/containertest/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containertest
import (
"context"
"fmt"
"github.com/dydxprotocol/v4-chain/protocol/app"
"time"

comethttp "github.com/cometbft/cometbft/rpc/client/http"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (n *Node) getContextForBroadcastTx(signer string) (*client.Context, *pflag.
WithViper(cmd.EnvPrefix)

option := cmd.GetOptionWithCustomStartCmd()
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)
rootCmd := cmd.NewRootCmd(option)
flags.AddTxFlagsToCmd(rootCmd)
flags := rootCmd.Flags()

Expand Down

0 comments on commit d6b28ea

Please sign in to comment.