From f817c466ced16e7ec7f2a9c6abea669d0a71f315 Mon Sep 17 00:00:00 2001 From: Itay Levy Date: Tue, 20 Jun 2023 12:25:04 +0200 Subject: [PATCH 1/3] Added rollapp id verification on roller config init --- cmd/config/init/flags.go | 13 +++++++++++++ cmd/config/init/init.go | 2 +- .../init_with_flags/relayer/config/config.yaml | 6 +++--- .../init_with_flags/rollapp/config/client.toml | 2 +- .../init_with_flags/rollapp/config/genesis.json | 2 +- .../init_without_flags/relayer/config/config.yaml | 6 +++--- .../init_without_flags/rollapp/config/client.toml | 2 +- .../init_without_flags/rollapp/config/genesis.json | 2 +- test/config/init/init_test.go | 2 +- 9 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index ae614656..988c4ec1 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -2,6 +2,7 @@ package initconfig import ( "fmt" + "regexp" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" @@ -21,6 +22,12 @@ func addFlags(cmd *cobra.Command) { if _, ok := Hubs[hubID]; !ok { return fmt.Errorf("invalid hub ID: %s. %s", hubID, getAvailableHubsMessage()) } + rollappID := args[0] + if !validateRollAppID(rollappID) { + return fmt.Errorf("the provided RollApp ID '%s' is invalid. Please ensure it follows the format:"+ + " 'letters_numbers_numbers',"+ + " where 'letters' are lowercase English letters, and 'numbers' are 1 to 5 digit numbers", rollappID) + } return nil } } @@ -61,3 +68,9 @@ func GetInitConfig(initCmd *cobra.Command, args []string) InitConfig { func getAvailableHubsMessage() string { return fmt.Sprintf("Acceptable values are '%s', '%s' or '%s'", TestnetHubID, StagingHubID, LocalHubID) } + +func validateRollAppID(id string) bool { + pattern := `^[a-z]+_[0-9]{1,5}_[0-9]{1,5}$` + r, _ := regexp.Compile(pattern) + return r.MatchString(id) +} diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index 2dbdd2c6..47862d45 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -19,7 +19,7 @@ type InitConfig struct { func InitCmd() *cobra.Command { initCmd := &cobra.Command{ - Use: "init ", + Use: "init ", Short: "Initialize a RollApp configuration on your local machine.", Run: func(cmd *cobra.Command, args []string) { initConfig := GetInitConfig(cmd, args) diff --git a/test/config/init/goldens/init_with_flags/relayer/config/config.yaml b/test/config/init/goldens/init_with_flags/relayer/config/config.yaml index b42735ff..d5717557 100644 --- a/test/config/init/goldens/init_with_flags/relayer/config/config.yaml +++ b/test/config/init/goldens/init_with_flags/relayer/config/config.yaml @@ -19,11 +19,11 @@ chains: output-format: json sign-mode: direct client-type: 07-tendermint - mars: + mars_1_1: type: cosmos value: key: relayer-rollapp-key - chain-id: mars + chain-id: mars_1_1 rpc-addr: http://localhost:26657 account-prefix: rol keyring-backend: test @@ -37,7 +37,7 @@ chains: paths: hub-rollapp: src: - chain-id: mars + chain-id: mars_1_1 dst: chain-id: 35-C src-channel-filter: diff --git a/test/config/init/goldens/init_with_flags/rollapp/config/client.toml b/test/config/init/goldens/init_with_flags/rollapp/config/client.toml index 65b6640e..f1ac6bee 100644 --- a/test/config/init/goldens/init_with_flags/rollapp/config/client.toml +++ b/test/config/init/goldens/init_with_flags/rollapp/config/client.toml @@ -6,7 +6,7 @@ ############################################################################### # The network chain ID -chain-id = "mars" +chain-id = "mars_1_1" # The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) keyring-backend = "os" # CLI output format (text|json) diff --git a/test/config/init/goldens/init_with_flags/rollapp/config/genesis.json b/test/config/init/goldens/init_with_flags/rollapp/config/genesis.json index e5eef8bb..eb05d17a 100644 --- a/test/config/init/goldens/init_with_flags/rollapp/config/genesis.json +++ b/test/config/init/goldens/init_with_flags/rollapp/config/genesis.json @@ -1,6 +1,6 @@ { "genesis_time": "PLACEHOLDER_TIMESTAMP", - "chain_id": "mars", + "chain_id": "mars_1_1", "initial_height": "1", "consensus_params": { "block": { diff --git a/test/config/init/goldens/init_without_flags/relayer/config/config.yaml b/test/config/init/goldens/init_without_flags/relayer/config/config.yaml index b42735ff..d5717557 100644 --- a/test/config/init/goldens/init_without_flags/relayer/config/config.yaml +++ b/test/config/init/goldens/init_without_flags/relayer/config/config.yaml @@ -19,11 +19,11 @@ chains: output-format: json sign-mode: direct client-type: 07-tendermint - mars: + mars_1_1: type: cosmos value: key: relayer-rollapp-key - chain-id: mars + chain-id: mars_1_1 rpc-addr: http://localhost:26657 account-prefix: rol keyring-backend: test @@ -37,7 +37,7 @@ chains: paths: hub-rollapp: src: - chain-id: mars + chain-id: mars_1_1 dst: chain-id: 35-C src-channel-filter: diff --git a/test/config/init/goldens/init_without_flags/rollapp/config/client.toml b/test/config/init/goldens/init_without_flags/rollapp/config/client.toml index 65b6640e..f1ac6bee 100644 --- a/test/config/init/goldens/init_without_flags/rollapp/config/client.toml +++ b/test/config/init/goldens/init_without_flags/rollapp/config/client.toml @@ -6,7 +6,7 @@ ############################################################################### # The network chain ID -chain-id = "mars" +chain-id = "mars_1_1" # The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) keyring-backend = "os" # CLI output format (text|json) diff --git a/test/config/init/goldens/init_without_flags/rollapp/config/genesis.json b/test/config/init/goldens/init_without_flags/rollapp/config/genesis.json index dbbca89d..72afbd7a 100644 --- a/test/config/init/goldens/init_without_flags/rollapp/config/genesis.json +++ b/test/config/init/goldens/init_without_flags/rollapp/config/genesis.json @@ -1,6 +1,6 @@ { "genesis_time": "PLACEHOLDER_TIMESTAMP", - "chain_id": "mars", + "chain_id": "mars_1_1", "initial_height": "1", "consensus_params": { "block": { diff --git a/test/config/init/init_test.go b/test/config/init/init_test.go index 75ce9863..36e8dc62 100644 --- a/test/config/init/init_test.go +++ b/test/config/init/init_test.go @@ -45,7 +45,7 @@ func TestInitCmd(t *testing.T) { }() initCmd := initconfig.InitCmd() denom := "udym" - rollappID := "mars" + rollappID := "mars_1_1" initCmd.SetArgs(append([]string{ rollappID, denom, From a9274d17cd6e65274fbe3fdc36a5faef2dc13815 Mon Sep 17 00:00:00 2001 From: Itay Levy Date: Tue, 20 Jun 2023 15:46:34 +0200 Subject: [PATCH 2/3] Improved invalid rollapp ID error message --- cmd/config/init/flags.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index 988c4ec1..e32d9cc2 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -24,9 +24,10 @@ func addFlags(cmd *cobra.Command) { } rollappID := args[0] if !validateRollAppID(rollappID) { - return fmt.Errorf("the provided RollApp ID '%s' is invalid. Please ensure it follows the format:"+ - " 'letters_numbers_numbers',"+ - " where 'letters' are lowercase English letters, and 'numbers' are 1 to 5 digit numbers", rollappID) + return fmt.Errorf("invalid RollApp ID '%s'. A valid ID should follow the format 'rollapp-name_EIP155_version', "+ + "where 'rollapp-name' is made up of lowercase English letters, 'EIP155_version' is a 1 to 5 digit number"+ + " representing the EIP155 rollapp ID, "+ + "and 'version' is a 1 to 5 digit number representing the rollapp version. For example: 'mars_9721_1'", rollappID) } return nil } From c0609414c2ae1985c5cdfbb4fcff0e0c3eebb365 Mon Sep 17 00:00:00 2001 From: Itay Levy Date: Tue, 20 Jun 2023 15:58:00 +0200 Subject: [PATCH 3/3] Including the rollapp id message in the roller config init help section --- cmd/config/init/flags.go | 11 +++++++---- cmd/config/init/init.go | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index e32d9cc2..31d1a8ea 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -24,15 +24,18 @@ func addFlags(cmd *cobra.Command) { } rollappID := args[0] if !validateRollAppID(rollappID) { - return fmt.Errorf("invalid RollApp ID '%s'. A valid ID should follow the format 'rollapp-name_EIP155_version', "+ - "where 'rollapp-name' is made up of lowercase English letters, 'EIP155_version' is a 1 to 5 digit number"+ - " representing the EIP155 rollapp ID, "+ - "and 'version' is a 1 to 5 digit number representing the rollapp version. For example: 'mars_9721_1'", rollappID) + return fmt.Errorf("invalid RollApp ID '%s'. %s", rollappID, getValidRollappIdMessage()) } return nil } } +func getValidRollappIdMessage() string { + return "A valid RollApp ID should follow the format 'rollapp-name_EIP155_version', where 'rollapp-name' is made up of" + + " lowercase English letters, 'EIP155_version' is a 1 to 5 digit number representing the EIP155 rollapp ID, and '" + + "version' is a 1 to 5 digit number representing the version. For example: 'mars_9721_1'" +} + func getDecimals(cmd *cobra.Command) uint64 { decimals, err := cmd.Flags().GetUint64(FlagNames.Decimals) if err != nil { diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index 47862d45..d41f5aa5 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -1,6 +1,7 @@ package initconfig import ( + "fmt" "os" "github.com/dymensionxyz/roller/cmd/consts" @@ -21,6 +22,10 @@ func InitCmd() *cobra.Command { initCmd := &cobra.Command{ Use: "init ", Short: "Initialize a RollApp configuration on your local machine.", + Long: fmt.Sprintf(`Initialize a RollApp configuration on your local machine. + +%s +`, getValidRollappIdMessage()), Run: func(cmd *cobra.Command, args []string) { initConfig := GetInitConfig(cmd, args) utils.PrettifyErrorIfExists(VerifyUniqueRollappID(initConfig.RollappID, initConfig))