Skip to content

Commit

Permalink
feat: add --mock flag to init (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 10, 2024
1 parent 61b445b commit 0fccdb3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
47 changes: 38 additions & 9 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"strings"
"time"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/archives"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/dependencies"
"github.com/dymensionxyz/roller/utils/rollapp"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
Expand All @@ -33,6 +34,8 @@ func Cmd() *cobra.Command {
pterm.Error.Println("failed to add flags")
return
}
isMockFlagSet := cmd.Flags().Changed("mock")
shouldUseMockBackend, _ := cmd.Flags().GetBool("mock")

var raID string
if len(args) != 0 {
Expand All @@ -43,13 +46,11 @@ func Cmd() *cobra.Command {
).Show()
}

envs := []string{"mock", "playground"}
env, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Show()
hd := consts.Hubs[env]
if env == "mock" {
var hd consts.HubData
var env string

if shouldUseMockBackend {
env := "mock"
err := runInit(cmd, env, raID)
if err != nil {
fmt.Println("failed to run init: ", err)
Expand All @@ -58,6 +59,23 @@ func Cmd() *cobra.Command {
return
}

if !isMockFlagSet && !shouldUseMockBackend {
envs := []string{"mock", "playground"}
env, _ = pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Show()
hd = consts.Hubs[env]
if env == "mock" {
err := runInit(cmd, env, raID)
if err != nil {
fmt.Println("failed to run init: ", err)
return
}
return
}
}

// ex binaries install
dymdBinaryOptions := dependencies.Dependency{
Name: "dymension",
Expand Down Expand Up @@ -153,6 +171,9 @@ func Cmd() *cobra.Command {
)
},
}

cmd.Flags().Bool("mock", false, "initialize the rollapp with mock backend")

return cmd
}

Expand All @@ -164,6 +185,14 @@ func installBinaries(bech32 string) error {
return errors.New(errMsg)
}

defer func() {
dir, err := os.UserHomeDir()
if err != nil {
return
}
_ = os.Chdir(dir)
}()

buildableDeps := map[string]dependencies.Dependency{
"rollapp": {
Repository: "https://github.com/dymensionxyz/rollapp-evm.git",
Expand Down
29 changes: 6 additions & 23 deletions cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package setup

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -83,30 +82,14 @@ func Cmd() *cobra.Command {
)
errorhandling.PrettifyErrorIfExists(err)

seq := sequencer.GetInstance(*rollappConfig)
startRollappCmd := seq.GetStartCmd()

LogPath = filepath.Join(
rollappConfig.Home,
consts.ConfigDirName.Rollapp,
"rollapputils.log",
)
RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp)

if rollappConfig.HubData.ID == "mock" {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go bash.RunCmdAsync(
ctx, startRollappCmd, func() {
printOutput(*rollappConfig, startRollappCmd)
err := createPidFile(RollappDirPath, startRollappCmd)
if err != nil {
pterm.Warning.Println("failed to create pid file")
}
}, parseError,
utils.WithLogging(utils.GetSequencerLogPath(*rollappConfig)),
pterm.Error.Println("setup is not required for mock backend")
pterm.Info.Printf(
"run %s instead to run the rollapp\n",
pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()).
Sprintf("roller rollapp start"),
)
select {}
return
}

getRaCmd := rollapp.GetRollappCmd(rollerData.RollappID, rollerData.HubData)
Expand Down
4 changes: 1 addition & 3 deletions cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Consider using 'services' if you want to run a 'systemd' service instead.
// TODO: this is an ugly workaround to start a light client for those
// who run a rollapp locally on their non-linux boxes ( why would you )
// refactor and remove repetition with da-light-client start command
if runtime.GOOS != "linux" {
if runtime.GOOS != "linux" && rollappConfig.HubData.ID != consts.MockHubID {
damanager := datalayer.NewDAManager(rollappConfig.DA.Backend, rollappConfig.Home)
startDALCCmd := damanager.GetStartDACmd()
if startDALCCmd == nil {
Expand All @@ -91,15 +91,13 @@ Consider using 'services' if you want to run a 'systemd' service instead.
}

DaLcEndpoint = damanager.GetLightNodeEndpoint()
DaLogPath = utils.GetDALogFilePath(rollappConfig.Home)

defer cancel()
go bash.RunCmdAsync(
ctx,
startDALCCmd,
printDaOutput,
parseError,
utils.WithLogging(DaLogPath),
)
}

Expand Down
2 changes: 1 addition & 1 deletion data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (c *Celestia) GetSequencerDAConfig(nt string) string {
}

return fmt.Sprintf(
`{"base_url": "%s", "timeout": 60000000000, "gas_prices":1.0, "gas_adjustment": 1.3, "namespace_id":"%s","auth_token":"%s","backoff":{"initial_delay":6000000000,"max_delay":6000000000,"growth_factor":2},"retry_attempts":4,"retry_delay":3000000000}`,
`{"base_url": "%s", "timeout": 60000000000, "gas_prices":0.02, "gas_adjustment": 1.3, "namespace_id":"%s","auth_token":"%s","backoff":{"initial_delay":6000000000,"max_delay":6000000000,"growth_factor":2},"retry_attempts":4,"retry_delay":3000000000}`,
lcEndpoint,
c.NamespaceID,
authToken,
Expand Down

0 comments on commit 0fccdb3

Please sign in to comment.