Skip to content

Commit

Permalink
fix(services): prevent app name with number (backport #4249) (#4256)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mergify[bot] and julienrbrt committed Jul 15, 2024
1 parent c1ae9c2 commit 9698827
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## [`v28.5.0`](https://github.com/ignite/cli/releases/tag/v28.5.0)

### Features

- [#4183](https://github.com/ignite/cli/pull/4183) Set `chain-id` in the client.toml
Expand All @@ -27,6 +29,7 @@
If you are uprading manually, check out the recommended changes in `root.go` from the above PR.
- [#4210](https://github.com/ignite/cli/pull/4210) Improve default home wiring
- [#4077](https://github.com/ignite/cli/pull/4077) Merge the swagger files manually instead use nodetime `swagger-combine`
- [#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 @@ -10,6 +10,7 @@ import (

"github.com/ignite/cli/v28/ignite/pkg/cache"
"github.com/ignite/cli/v28/ignite/pkg/cosmosgen"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/pkg/gomodulepath"
"github.com/ignite/cli/v28/ignite/pkg/placeholder"
"github.com/ignite/cli/v28/ignite/pkg/xgit"
Expand All @@ -33,6 +34,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 @@ -46,7 +46,7 @@ func TestServeWithWasm(t *testing.T) {
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 @@ -66,7 +66,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 @@ -88,7 +88,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 @@ -116,7 +116,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 @@ -189,7 +189,7 @@ func TestCreateIBCOracle(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 9698827

Please sign in to comment.