Skip to content

Commit

Permalink
fix: Generate formatted rollapp id for local rollapps (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Sep 12, 2023
1 parent 999d641 commit b9fabcd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
19 changes: 11 additions & 8 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func addFlags(cmd *cobra.Command) error {
return nil
}

func GetInitConfig(initCmd *cobra.Command, args []string) (config.RollappConfig, error) {
func GetInitConfig(initCmd *cobra.Command, args []string) (*config.RollappConfig, error) {
cfg := config.RollappConfig{
RollerVersion: version.TrimVersionStr(version.BuildVersion),
}
Expand All @@ -49,15 +49,15 @@ func GetInitConfig(initCmd *cobra.Command, args []string) (config.RollappConfig,
interactive, _ := initCmd.Flags().GetBool(FlagNames.Interactive)
if interactive {
if err := RunInteractiveMode(&cfg); err != nil {
return cfg, err
return nil, err
}
return formatBaseCfg(cfg, initCmd), nil
return formatBaseCfg(cfg, initCmd)
}

rollappId := args[0]
denom := args[1]
if !isLowercaseAlphabetical(rollappId) {
return cfg, fmt.Errorf("invalid rollapp id %s. %s", rollappId, validRollappIDMsg)
return nil, fmt.Errorf("invalid rollapp id %s. %s", rollappId, validRollappIDMsg)
}
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
tokenSupply := initCmd.Flag(FlagNames.TokenSupply).Value.String()
Expand All @@ -67,22 +67,25 @@ func GetInitConfig(initCmd *cobra.Command, args []string) (config.RollappConfig,
cfg.TokenSupply = tokenSupply
cfg.DA = config.DAType(strings.ToLower(initCmd.Flag(FlagNames.DAType).Value.String()))
cfg.VMType = config.VMType(initCmd.Flag(FlagNames.VMType).Value.String())
return formatBaseCfg(cfg, initCmd), nil
return formatBaseCfg(cfg, initCmd)
}

func formatBaseCfg(cfg config.RollappConfig, initCmd *cobra.Command) config.RollappConfig {
func formatBaseCfg(cfg config.RollappConfig, initCmd *cobra.Command) (*config.RollappConfig, error) {
setDecimals(initCmd, &cfg)
formattedRollappId, err := generateRollappId(cfg)
if err != nil {
return cfg
return nil, err
}
cfg.RollappID = formattedRollappId
return cfg
return &cfg, nil
}

func generateRollappId(rlpCfg config.RollappConfig) (string, error) {
for {
RandEthId := generateRandEthId()
if rlpCfg.HubData.ID == LocalHubID {
return fmt.Sprintf("%s_%s-1", rlpCfg.RollappID, RandEthId), nil
}
isUnique, err := isEthIdentifierUnique(RandEthId, rlpCfg)
if err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func runInit(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
initConfig, err := GetInitConfig(cmd, args)
initConfigPtr, err := GetInitConfig(cmd, args)
if err != nil {
return err
}
initConfig := *initConfigPtr
outputHandler := NewOutputHandler(noOutput)
defer outputHandler.StopSpinner()
utils.RunOnInterrupt(outputHandler.StopSpinner)
Expand Down
2 changes: 1 addition & 1 deletion test/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInitCmd(t *testing.T) {
assert.NoError(initCmd.Execute())
initConfig, err := initconfig.GetInitConfig(initCmd, []string{rollappID, denom})
assert.NoError(err)
assert.NoError(testutils.VerifyRollerConfig(initConfig))
assert.NoError(testutils.VerifyRollerConfig(*initConfig))
assert.NoError(os.Remove(filepath.Join(tempDir, config.RollerConfigFileName)))
assert.NoError(testutils.VerifyRollappKeys(tempDir))
assert.NoError(testutils.VerifyRelayerKeys(tempDir, rollappID, initConfig.HubData.ID))
Expand Down

0 comments on commit b9fabcd

Please sign in to comment.