diff --git a/.github/workflows/md-link-checker-config.json b/.github/workflows/md-link-checker-config.json index 8c15416958..fa7f2bde39 100644 --- a/.github/workflows/md-link-checker-config.json +++ b/.github/workflows/md-link-checker-config.json @@ -10,7 +10,7 @@ "pattern": "^https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax" }, { - "pattern": "^https://docs.starport.network" + "pattern": "^https://docs.ignite.com/" }, { "pattern": "^http://localhost" diff --git a/.gitpod/readme.md b/.gitpod/readme.md index 6894ce078e..f8c77c0198 100644 --- a/.gitpod/readme.md +++ b/.gitpod/readme.md @@ -38,7 +38,7 @@ ignite chain serve ## Install Ignite CLI locally -``` +```sh curl https://get.ignite.com/cli | bash ``` diff --git a/changelog.md b/changelog.md index 83997294ac..92ef0c5186 100644 --- a/changelog.md +++ b/changelog.md @@ -17,8 +17,9 @@ ### Changes -- [#3581](https://github.com/ignite/cli/pull/3581) Bump cometbft and cometbft-db in the template +- [#3621](https://github.com/ignite/cli/pull/3621) Change `pkg/availableport` to allow custom parameters in `Find` function and handle duplicated ports - [#3559](https://github.com/ignite/cli/pull/3559) Bump network plugin version to `v0.1.1` +- [#3581](https://github.com/ignite/cli/pull/3581) Bump cometbft and cometbft-db in the template - [#3522](https://github.com/ignite/cli/pull/3522) Remove indentation from `chain serve` output - [#3601](https://github.com/ignite/cli/pull/3601) Update ts-relayer version to `0.10.0` - [#3658](https://github.com/ignite/cli/pull/3658) Rename Marshaler to Codec in EncodingConfig @@ -26,6 +27,7 @@ - [#3656](https://github.com/ignite/cli/pull/3656) Disable Go toolchain download - [#3662](https://github.com/ignite/cli/pull/3662) Refactor CLI "plugin" command to "app" - [#3669](https://github.com/ignite/cli/pull/3669) Rename `plugins` config file to `igniteapps` +- [#3683](https://github.com/ignite/cli/pull/3683) Resolve `--dep auth` as `--dep account` in `scaffold module` ### Fixes @@ -624,7 +626,7 @@ Our new name is **Ignite CLI**! automatically take care of building proto files without a need of script in the app's source code. - Integrated third-party proto-files used by Cosmos SDK modules into Ignite CLI - Added ability to customize binary name with `build.binary` in `config.yml` -- Added ability to change path to home directory with ` .home` in `config.yml` +- Added ability to change path to home directory with `.home` in `config.yml` - Added ability to add accounts by `address` with in `config.yml` - Added faucet functionality available on port 4500 and configurable with `faucet` in `config.yml` - Added `starport faucet [address] [coins]` command diff --git a/go.mod b/go.mod index 650ab1ffe8..0ef30d6ce3 100644 --- a/go.mod +++ b/go.mod @@ -63,8 +63,8 @@ require ( golang.org/x/exp v0.0.0-20230519143937-03e91628a987 golang.org/x/mod v0.12.0 golang.org/x/sync v0.2.0 - golang.org/x/term v0.8.0 - golang.org/x/text v0.9.0 + golang.org/x/term v0.13.0 + golang.org/x/text v0.13.0 golang.org/x/tools v0.9.1 golang.org/x/vuln v0.1.0 google.golang.org/grpc v1.55.0 @@ -402,10 +402,10 @@ require ( go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.23.0 // indirect golang.org/x/arch v0.1.0 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 8ec7b06929..7f248794e6 100644 --- a/go.sum +++ b/go.sum @@ -1419,8 +1419,8 @@ golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1522,8 +1522,8 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1647,8 +1647,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1659,8 +1659,8 @@ golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1672,8 +1672,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/ignite/cmd/account_create.go b/ignite/cmd/account_create.go index e0febdc74b..adcedeef1b 100644 --- a/ignite/cmd/account_create.go +++ b/ignite/cmd/account_create.go @@ -35,6 +35,6 @@ func accountCreateHandler(cmd *cobra.Command, args []string) error { return fmt.Errorf("unable to create account: %w", err) } - fmt.Printf("Account %q created, keep your mnemonic in a secret place:\n\n%s\n", name, mnemonic) + cmd.Printf("Account %q created, keep your mnemonic in a secret place:\n\n%s\n", name, mnemonic) return nil } diff --git a/ignite/cmd/account_delete.go b/ignite/cmd/account_delete.go index f999f86955..bc07004fbe 100644 --- a/ignite/cmd/account_delete.go +++ b/ignite/cmd/account_delete.go @@ -1,8 +1,6 @@ package ignitecmd import ( - "fmt" - "github.com/spf13/cobra" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -34,6 +32,6 @@ func accountDeleteHandler(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("Account %s deleted.\n", name) + cmd.Printf("Account %s deleted.\n", name) return nil } diff --git a/ignite/cmd/account_export.go b/ignite/cmd/account_export.go index 3436bc13c9..8a36b8f479 100644 --- a/ignite/cmd/account_export.go +++ b/ignite/cmd/account_export.go @@ -64,6 +64,6 @@ func accountExportHandler(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("Account %q exported to file: %s\n", name, path) + cmd.Printf("Account %q exported to file: %s\n", name, path) return nil } diff --git a/ignite/cmd/account_import.go b/ignite/cmd/account_import.go index 762bf8b46c..dd77f212b6 100644 --- a/ignite/cmd/account_import.go +++ b/ignite/cmd/account_import.go @@ -2,7 +2,6 @@ package ignitecmd import ( "errors" - "fmt" "os" "github.com/cosmos/go-bip39" @@ -71,6 +70,6 @@ func accountImportHandler(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("Account %q imported.\n", name) + cmd.Printf("Account %q imported.\n", name) return nil } diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 28c3586d90..121c98229f 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -223,7 +223,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook *plugin.Hook) ctx := cmd.Context() err := p.Interface.ExecuteHookCleanUp(ctx, newExecutedHook(hook, cmd, args)) if err != nil { - fmt.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) + cmd.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) } } return err @@ -241,7 +241,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook *plugin.Hook) defer func() { err := p.Interface.ExecuteHookCleanUp(ctx, execHook) if err != nil { - fmt.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) + cmd.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) } }() @@ -404,7 +404,7 @@ If no path is specified all declared apps are updated.`, if err != nil { return err } - fmt.Printf("All apps updated.\n") + cmd.Println("All apps updated.") return nil } // find the plugin to update @@ -414,7 +414,7 @@ If no path is specified all declared apps are updated.`, if err != nil { return err } - fmt.Printf("App %q updated.\n", p.Path) + cmd.Printf("App %q updated.\n", p.Path) return nil } } diff --git a/ignite/cmd/scaffold_module.go b/ignite/cmd/scaffold_module.go index 03cf5f3c65..8dc6db50ef 100644 --- a/ignite/cmd/scaffold_module.go +++ b/ignite/cmd/scaffold_module.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "regexp" + "strings" "github.com/spf13/cobra" @@ -15,6 +16,11 @@ import ( modulecreate "github.com/ignite/cli/ignite/templates/module/create" ) +// moduleNameKeeperAlias is a map of well known module names that have a different keeper name than the usual Keeper. +var moduleNameKeeperAlias = map[string]string{ + "auth": "account", +} + const ( flagDep = "dep" flagIBC = "ibc" @@ -170,6 +176,10 @@ func scaffoldModuleHandler(cmd *cobra.Command, args []string) error { return fmt.Errorf("invalid module dependency name format '%s'", name) } + if alias, ok := moduleNameKeeperAlias[strings.ToLower(name)]; ok { + name = alias + } + deps = append(deps, modulecreate.NewDependency(name)) } diff --git a/ignite/cmd/version.go b/ignite/cmd/version.go index 62e74a2238..ed65f8013f 100644 --- a/ignite/cmd/version.go +++ b/ignite/cmd/version.go @@ -1,8 +1,6 @@ package ignitecmd import ( - "fmt" - "github.com/spf13/cobra" "github.com/ignite/cli/ignite/version" @@ -14,7 +12,7 @@ func NewVersion() *cobra.Command { Use: "version", Short: "Print the current build information", Run: func(cmd *cobra.Command, _ []string) { - fmt.Println(version.Long(cmd.Context())) + cmd.Println(version.Long(cmd.Context())) }, } return c diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index b71de4e1ef..d7900c022d 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -126,7 +126,7 @@ type Faucet struct { Host string `yaml:"host,omitempty"` // Port number for faucet server to listen at. - Port int `yaml:"port,omitempty"` + Port uint `yaml:"port,omitempty"` } // Init overwrites sdk configurations with given values. diff --git a/ignite/config/chain/config.go b/ignite/config/chain/config.go index 9b52185fea..3724442cbf 100644 --- a/ignite/config/chain/config.go +++ b/ignite/config/chain/config.go @@ -74,7 +74,7 @@ func FaucetHost(cfg *Config) string { // We keep supporting Port option for backward compatibility // TODO: drop this option in the future host := cfg.Faucet.Host - if cfg.Faucet.Port != 0 { + if cfg.Faucet.Port != uint(0) { host = fmt.Sprintf(":%d", cfg.Faucet.Port) } diff --git a/ignite/internal/tools/gen-cli-docs/main.go b/ignite/internal/tools/gen-cli-docs/main.go index b07cfd4502..7370e368db 100644 --- a/ignite/internal/tools/gen-cli-docs/main.go +++ b/ignite/internal/tools/gen-cli-docs/main.go @@ -104,7 +104,7 @@ func generateCmd(cmd *cobra.Command, w io.Writer) error { } // here we change sub titles to bold styling. Otherwise, these titles will get - // printed in the right menu of docs.starport.network which is unpleasant because + // printed in the right menu of docs.ignite.com which is unpleasant because // we only want to see a list of all available commands without the extra noise. sc := bufio.NewScanner(b) for sc.Scan() { diff --git a/ignite/pkg/availableport/availableport.go b/ignite/pkg/availableport/availableport.go index b5247c6caa..77f9445d63 100644 --- a/ignite/pkg/availableport/availableport.go +++ b/ignite/pkg/availableport/availableport.go @@ -4,29 +4,85 @@ import ( "fmt" "math/rand" "net" + "time" ) +type availablePortOptions struct { + randomizer *rand.Rand + minPort uint + maxPort uint +} + +type Options func(o *availablePortOptions) + +func WithRandomizer(r *rand.Rand) Options { + return func(o *availablePortOptions) { + o.randomizer = r + } +} + +func WithMaxPort(maxPort uint) Options { + return func(o *availablePortOptions) { + o.maxPort = maxPort + } +} + +func WithMinPort(minPort uint) Options { + return func(o *availablePortOptions) { + o.minPort = minPort + } +} + // Find finds n number of unused ports. // it is not guaranteed that these ports will not be allocated to // another program in the time of calling Find(). -func Find(n int) (ports []int, err error) { - min := 44000 - max := 55000 - - for i := 0; i < n; i++ { - for { - port := rand.Intn(max-min+1) + min - - conn, err := net.Dial("tcp", fmt.Sprintf(":%d", port)) - // if there is an error, this might mean that no one is listening from this port - // which is what we need. - if err == nil { - conn.Close() - continue - } - ports = append(ports, port) - break +func Find(n uint, options ...Options) (ports []uint, err error) { + // Defining them before so we can set a value depending on the AvailablePortOptions + opts := availablePortOptions{ + minPort: 44000, + maxPort: 55000, + randomizer: rand.New(rand.NewSource(time.Now().UnixNano())), + } + + for _, apply := range options { + apply(&opts) + } + // If the number of ports required is bigger than the range, this stops it + if opts.maxPort < opts.minPort { + return nil, fmt.Errorf("invalid ports range: max < min (%d < %d)", opts.maxPort, opts.minPort) + } + + // If the number of ports required is bigger than the range, this stops it + if n > (opts.maxPort - opts.minPort) { + return nil, fmt.Errorf("invalid amount of ports requested: limit is %d", opts.maxPort-opts.minPort) + } + + // Marker to point if a port is already added in the list + registered := make(map[uint]bool) + for len(registered) < int(n) { + // Greater or equal to min and lower than max + totalPorts := opts.maxPort - opts.minPort + 1 + randomPort := opts.randomizer.Intn(int(totalPorts)) + port := uint(randomPort) + opts.minPort + + conn, err := net.Dial("tcp", fmt.Sprintf(":%d", port)) + // if there is an error, this might mean that no one is listening from this port + // which is what we need. + if err == nil { + conn.Close() + continue + } + if conn != nil { + defer conn.Close() + } + + // if the port is already registered we skip it to the next one + // otherwise it's added to the ports list and pointed in our map + if registered[port] { + continue } + ports = append(ports, port) + registered[port] = true } return ports, nil } diff --git a/ignite/pkg/availableport/availableport_test.go b/ignite/pkg/availableport/availableport_test.go new file mode 100644 index 0000000000..cd42b0b6ff --- /dev/null +++ b/ignite/pkg/availableport/availableport_test.go @@ -0,0 +1,78 @@ +package availableport_test + +import ( + "fmt" + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ignite/cli/ignite/pkg/availableport" +) + +func TestFind(t *testing.T) { + tests := []struct { + name string + n uint + options []availableport.Options + err error + }{ + { + name: "test 10 ports", + n: 10, + }, + { + name: "invalid port range", + n: 10, + options: []availableport.Options{ + availableport.WithMinPort(5), + availableport.WithMaxPort(1), + }, + err: fmt.Errorf("invalid ports range: max < min (1 < 5)"), + }, + { + name: "invalid maximum port range", + n: 10, + options: []availableport.Options{ + availableport.WithMinPort(55001), + availableport.WithMaxPort(1), + }, + err: fmt.Errorf("invalid ports range: max < min (1 < 55001)"), + }, + { + name: "only invalid maximum port range", + n: 10, + options: []availableport.Options{ + availableport.WithMaxPort(43999), + }, + err: fmt.Errorf("invalid ports range: max < min (43999 < 44000)"), + }, + { + name: "with randomizer", + n: 100, + options: []availableport.Options{ + availableport.WithRandomizer(rand.New(rand.NewSource(2023))), + availableport.WithMinPort(100), + availableport.WithMaxPort(200), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := availableport.Find(tt.n, tt.options...) + if tt.err != nil { + require.Equal(t, tt.err, err) + return + } + require.NoError(t, err) + require.Len(t, got, int(tt.n)) + + seen := make(map[uint]struct{}) + for _, val := range got { + _, ok := seen[val] + require.Falsef(t, ok, "duplicated port %d", val) + seen[val] = struct{}{} + } + }) + } +} diff --git a/ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl b/ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl index 384c2b6609..e24875af0a 100644 --- a/ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl +++ b/ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl @@ -57,5 +57,5 @@ definitions: externalDocs: - description: "Find out more about Starport" + description: "Find out more about Ignite CLI" url: "https://github.com/ignite/cli/tree/develop/docs" diff --git a/ignite/pkg/iowait/iowait.go b/ignite/pkg/iowait/iowait.go deleted file mode 100644 index 5926d41523..0000000000 --- a/ignite/pkg/iowait/iowait.go +++ /dev/null @@ -1,30 +0,0 @@ -package iowait - -import ( - "bufio" - "fmt" - "io" - "strings" -) - -// Until waits for the appearance of s in the string n times and -// then stops blocking. -func Until(r io.Reader, s string, n int) (capturedLines []string, err error) { - total := n - scanner := bufio.NewScanner(r) - for { - if n == 0 { - return capturedLines, nil - } - if !scanner.Scan() { - if n != 0 { - return capturedLines, fmt.Errorf("could not find %d out of %d", n, total) - } - return capturedLines, scanner.Err() - } - if strings.Contains(scanner.Text(), s) { - capturedLines = append(capturedLines, scanner.Text()) - n-- - } - } -} diff --git a/ignite/pkg/jsondoc/jsondoc.go b/ignite/pkg/jsondoc/jsondoc.go deleted file mode 100644 index 460c5d3e23..0000000000 --- a/ignite/pkg/jsondoc/jsondoc.go +++ /dev/null @@ -1,34 +0,0 @@ -package jsondoc - -import ( - "encoding/json" - - "github.com/goccy/go-yaml" -) - -// Doc represents a JSON encoded data. -type Doc []byte - -// ToDocs converts a list of JSON encoded data to docs. -func ToDocs(data [][]byte) []Doc { - var docs []Doc - for _, d := range data { - docs = append(docs, d) - } - return docs -} - -// MarshalYAML converts Doc to a YAML encoded data during YAML marshaling. -func (d Doc) MarshalYAML() ([]byte, error) { - var out interface{} - if err := json.Unmarshal(d, &out); err != nil { - return nil, err - } - return yaml.Marshal(out) -} - -// Pretty converts a Doc to a human-readable string. -func (d Doc) Pretty() (string, error) { - proposalyaml, err := yaml.Marshal(d) - return string(proposalyaml), err -} diff --git a/ignite/pkg/looseerrgroup/looseerrgroup.go b/ignite/pkg/looseerrgroup/looseerrgroup.go deleted file mode 100644 index 8e5302b0a4..0000000000 --- a/ignite/pkg/looseerrgroup/looseerrgroup.go +++ /dev/null @@ -1,26 +0,0 @@ -package looseerrgroup - -import ( - "context" - - "golang.org/x/sync/errgroup" -) - -// Wait waits until g.Wait() returns or ctx canceled, whichever occurs first. -// returned error is context.Canceled if ctx canceled otherwise the error returned by g.Wait(). -// -// this is useful when errgroup cannot be used with errgroup.WithContext which happens if executed -// func does not support cancellation. -func Wait(ctx context.Context, g *errgroup.Group) error { - doneC := make(chan struct{}) - - go func() { g.Wait(); close(doneC) }() - - select { - case <-ctx.Done(): - return ctx.Err() - - case <-doneC: - return g.Wait() - } -} diff --git a/ignite/pkg/tendermintlogger/logger.go b/ignite/pkg/tendermintlogger/logger.go deleted file mode 100644 index 302c0ad7f5..0000000000 --- a/ignite/pkg/tendermintlogger/logger.go +++ /dev/null @@ -1,10 +0,0 @@ -package tendermintlogger - -import tmlog "github.com/cometbft/cometbft/libs/log" - -type DiscardLogger struct{} - -func (l DiscardLogger) Debug(string, ...interface{}) {} -func (l DiscardLogger) Info(string, ...interface{}) {} -func (l DiscardLogger) Error(string, ...interface{}) {} -func (l DiscardLogger) With(...interface{}) tmlog.Logger { return l } diff --git a/ignite/pkg/tendermintlogger/logger_test.go b/ignite/pkg/tendermintlogger/logger_test.go deleted file mode 100644 index c483e93e3d..0000000000 --- a/ignite/pkg/tendermintlogger/logger_test.go +++ /dev/null @@ -1,5 +0,0 @@ -package tendermintlogger - -import tmlog "github.com/cometbft/cometbft/libs/log" - -var _ tmlog.Logger = (*DiscardLogger)(nil) diff --git a/ignite/pkg/xstrings/xstrings.go b/ignite/pkg/xstrings/xstrings.go index c8229e9735..ff038a95db 100644 --- a/ignite/pkg/xstrings/xstrings.go +++ b/ignite/pkg/xstrings/xstrings.go @@ -4,6 +4,7 @@ import ( "strings" "unicode" + "golang.org/x/exp/slices" // TODO: replace with slices.Contains when it will be available in stdlib (1.21) "golang.org/x/text/cases" "golang.org/x/text/language" ) @@ -19,7 +20,7 @@ func AllOrSomeFilter(list, filterList []string) []string { var elems []string for _, elem := range list { - if !SliceContains(filterList, elem) { + if !slices.Contains(filterList, elem) { elems = append(elems, elem) } } @@ -27,17 +28,6 @@ func AllOrSomeFilter(list, filterList []string) []string { return elems } -// SliceContains returns with true if s is a member of ss. -func SliceContains(ss []string, s string) bool { - for _, e := range ss { - if e == s { - return true - } - } - - return false -} - // List returns a slice of strings captured after the value returned by do which is // called n times. func List(n int, do func(i int) string) []string { diff --git a/integration/app.go b/integration/app.go index c9c5a0396a..54516c5d7b 100644 --- a/integration/app.go +++ b/integration/app.go @@ -218,7 +218,7 @@ func (a App) RandomizeServerPorts() Hosts { ports, err := availableport.Find(7) require.NoError(a.env.t, err) - genAddr := func(port int) string { + genAddr := func(port uint) string { return fmt.Sprintf("127.0.0.1:%d", port) } diff --git a/integration/readme.md b/integration/readme.md index 58e08914bb..1d9ef27b35 100644 --- a/integration/readme.md +++ b/integration/readme.md @@ -1,6 +1,6 @@ -# Starport Integration Tests +# Ignite CLI Integration Tests -The Starport integration tests build a new application and run all Starport commands to check the Starport code integrity. The runners and helper methods are located in this current folder. The test commands are split into folders, for better concurrency, each folder is a parallel job into the CI workflow. To create a new one, we only need to create a new folder. This will be automatically detected and added into the PR CI checks, or we can only create new tests into an existing folder or file. +The Ignite CLI integration tests build a new application and run all Ignite CLI commands to check the Ignite CLI code integrity. The runners and helper methods are located in this current folder. The test commands are split into folders, for better concurrency, each folder is a parallel job into the CI workflow. To create a new one, we only need to create a new folder. This will be automatically detected and added into the PR CI checks, or we can only create new tests into an existing folder or file. Running synchronously all integration tests can be very slow. The command below can run everything: @@ -25,7 +25,7 @@ var ( ) ``` -- Now, you can use the env to run the starport commands and check the success status: +- Now, you can use the env to run the ignite commands and check the success status: ```go env.Must(env.Exec("create a list with bool",