Skip to content

Commit

Permalink
fix(services): prevent app name with number (ignite#4249)
Browse files Browse the repository at this point in the history
* fix(services): prevent app name with number

* changelog

* updates

---------

Co-authored-by: Danilo Pantani <[email protected]>
  • Loading branch information
julienrbrt and Pantani authored Jul 15, 2024
1 parent 82a3a75 commit de8fc6d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- [#4194](https://github.com/ignite/cli/pull/4194) Bump client/v2 to `v2.0.0-beta.2`
- [#4189](https://github.com/ignite/cli/pull/4189) Deprecate `ignite node` for `ignite connect` app
- [#4210](https://github.com/ignite/cli/pull/4210) Improve default home wiring
- [#4249](https://github.com/ignite/cli/pull/4249) Prevent creating a chain with number in the name
- [#4253](https://github.com/ignite/cli/pull/4253) Bump cosmos-sdk to `v0.50.8`

### Fixes
Expand Down
8 changes: 8 additions & 0 deletions ignite/services/scaffolder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/ignite/cli/v29/ignite/pkg/cosmosgen"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/templates/app"
Expand All @@ -28,6 +29,13 @@ func Init(
return "", "", err
}

// Check if the module name is valid (no numbers)
for _, r := range pathInfo.Package {
if r >= '0' && r <= '9' {
return "", "", errors.Errorf("invalid app name %s: cannot contain numbers", pathInfo.Package)
}
}

// Create a new folder named as the blockchain when a custom path is not specified
var appFolder string
if root == "" {
Expand Down
18 changes: 18 additions & 0 deletions integration/app/cmd_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package app_test

import (
"bytes"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -52,6 +53,23 @@ func TestGenerateAnAppWithName(t *testing.T) {
app.EnsureSteady()
}

// TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name.
func TestGenerateAnAppWithInvalidName(t *testing.T) {
buf := new(bytes.Buffer)

env := envtest.New(t)
env.Must(env.Exec("should prevent creating an app with an invalid name",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "s", "chain", "blog2"),
step.Stdout(buf),
step.Stderr(buf),
)),
envtest.ExecShouldError(),
))

require.Contains(t, buf.String(), "Invalid app name blog2: cannot contain numbers")
}

func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
var (
env = envtest.New(t)
Expand Down
8 changes: 4 additions & 4 deletions integration/chain/cmd_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestServeWithCustomHome(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgblog2")
app = env.Scaffold("github.com/test/sgbloga")
servers = app.RandomizeServerPorts()
)

Expand All @@ -36,7 +36,7 @@ func TestServeWithCustomHome(t *testing.T) {
func TestServeWithConfigHome(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgblog3")
app = env.Scaffold("github.com/test/sgblogb")
servers = app.RandomizeServerPorts()
)

Expand All @@ -58,7 +58,7 @@ func TestServeWithCustomConfigFile(t *testing.T) {

var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgblog4")
app = env.Scaffold("github.com/test/sgblogc")
)
// Move config
newConfig := "new_config.yml"
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestServeWithCustomConfigFile(t *testing.T) {
func TestServeWithName(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("sgblog5")
app = env.Scaffold("sgblogd")
servers = app.RandomizeServerPorts()
)

Expand Down
2 changes: 1 addition & 1 deletion integration/ibc/cmd_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestCreateModuleWithIBC(t *testing.T) {
func TestCreateIBCPacket(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/blogibc2")
app = env.Scaffold("github.com/test/blogibcb")
)

env.Must(env.Exec("create an IBC module",
Expand Down

0 comments on commit de8fc6d

Please sign in to comment.