Skip to content

Commit 9698827

Browse files
fix(services): prevent app name with number (backport #4249) (#4256)
* fix(services): prevent app name with number (#4249) * fix(services): prevent app name with number * changelog * updates --------- Co-authored-by: Danilo Pantani <danpantani@gmail.com> (cherry picked from commit de8fc6d) # Conflicts: # ignite/services/scaffolder/init.go * fix conflict * prepare tag --------- Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent c1ae9c2 commit 9698827

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
## [`v28.5.0`](https://github.com/ignite/cli/releases/tag/v28.5.0)
6+
57
### Features
68

79
- [#4183](https://github.com/ignite/cli/pull/4183) Set `chain-id` in the client.toml
@@ -27,6 +29,7 @@
2729
If you are uprading manually, check out the recommended changes in `root.go` from the above PR.
2830
- [#4210](https://github.com/ignite/cli/pull/4210) Improve default home wiring
2931
- [#4077](https://github.com/ignite/cli/pull/4077) Merge the swagger files manually instead use nodetime `swagger-combine`
32+
- [#4249](https://github.com/ignite/cli/pull/4249) Prevent creating a chain with number in the name
3033
- [#4253](https://github.com/ignite/cli/pull/4253) Bump cosmos-sdk to `v0.50.8`
3134

3235
### Fixes

ignite/services/scaffolder/init.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/ignite/cli/v28/ignite/pkg/cache"
1212
"github.com/ignite/cli/v28/ignite/pkg/cosmosgen"
13+
"github.com/ignite/cli/v28/ignite/pkg/errors"
1314
"github.com/ignite/cli/v28/ignite/pkg/gomodulepath"
1415
"github.com/ignite/cli/v28/ignite/pkg/placeholder"
1516
"github.com/ignite/cli/v28/ignite/pkg/xgit"
@@ -33,6 +34,13 @@ func Init(
3334
return "", err
3435
}
3536

37+
// Check if the module name is valid (no numbers)
38+
for _, r := range pathInfo.Package {
39+
if r >= '0' && r <= '9' {
40+
return "", errors.Errorf("invalid app name %s: cannot contain numbers", pathInfo.Package)
41+
}
42+
}
43+
3644
// Create a new folder named as the blockchain when a custom path is not specified
3745
var appFolder string
3846
if root == "" {

integration/app/cmd_app_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package app_test
44

55
import (
6+
"bytes"
67
"os"
78
"path/filepath"
89
"testing"
@@ -52,6 +53,23 @@ func TestGenerateAnAppWithName(t *testing.T) {
5253
app.EnsureSteady()
5354
}
5455

56+
// TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name.
57+
func TestGenerateAnAppWithInvalidName(t *testing.T) {
58+
buf := new(bytes.Buffer)
59+
60+
env := envtest.New(t)
61+
env.Must(env.Exec("should prevent creating an app with an invalid name",
62+
step.NewSteps(step.New(
63+
step.Exec(envtest.IgniteApp, "s", "chain", "blog2"),
64+
step.Stdout(buf),
65+
step.Stderr(buf),
66+
)),
67+
envtest.ExecShouldError(),
68+
))
69+
70+
require.Contains(t, buf.String(), "Invalid app name blog2: cannot contain numbers")
71+
}
72+
5573
func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
5674
var (
5775
env = envtest.New(t)

integration/chain/cmd_serve_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestServeWithWasm(t *testing.T) {
4646
func TestServeWithCustomHome(t *testing.T) {
4747
var (
4848
env = envtest.New(t)
49-
app = env.Scaffold("github.com/test/sgblog2")
49+
app = env.Scaffold("github.com/test/sgbloga")
5050
servers = app.RandomizeServerPorts()
5151
)
5252

@@ -66,7 +66,7 @@ func TestServeWithCustomHome(t *testing.T) {
6666
func TestServeWithConfigHome(t *testing.T) {
6767
var (
6868
env = envtest.New(t)
69-
app = env.Scaffold("github.com/test/sgblog3")
69+
app = env.Scaffold("github.com/test/sgblogb")
7070
servers = app.RandomizeServerPorts()
7171
)
7272

@@ -88,7 +88,7 @@ func TestServeWithCustomConfigFile(t *testing.T) {
8888

8989
var (
9090
env = envtest.New(t)
91-
app = env.Scaffold("github.com/test/sgblog4")
91+
app = env.Scaffold("github.com/test/sgblogc")
9292
)
9393
// Move config
9494
newConfig := "new_config.yml"
@@ -116,7 +116,7 @@ func TestServeWithCustomConfigFile(t *testing.T) {
116116
func TestServeWithName(t *testing.T) {
117117
var (
118118
env = envtest.New(t)
119-
app = env.Scaffold("sgblog5")
119+
app = env.Scaffold("sgblogd")
120120
servers = app.RandomizeServerPorts()
121121
)
122122

integration/ibc/cmd_ibc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func TestCreateIBCOracle(t *testing.T) {
189189
func TestCreateIBCPacket(t *testing.T) {
190190
var (
191191
env = envtest.New(t)
192-
app = env.Scaffold("github.com/test/blogibc2")
192+
app = env.Scaffold("github.com/test/blogibcb")
193193
)
194194

195195
env.Must(env.Exec("create an IBC module",

0 commit comments

Comments
 (0)