Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/docs/postcss-8.4.31
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Oct 13, 2023
2 parents 6136a9b + 3c9f058 commit 1098033
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/md-link-checker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .gitpod/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ignite chain serve

## Install Ignite CLI locally

```
```sh
curl https://get.ignite.com/cli | bash
```

Expand Down
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@

### 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
- [#3653](https://github.com/ignite/cli/pull/3653) Add "app" extension to plugin binaries
- [#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

Expand Down Expand Up @@ -618,7 +620,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
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/account_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 1 addition & 3 deletions ignite/cmd/account_delete.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ignitecmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cosmosaccount"
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion ignite/cmd/account_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions ignite/cmd/account_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ignitecmd

import (
"errors"
"fmt"
"os"

"github.com/cosmos/go-bip39"
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions ignite/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook)
if err != nil {
err := p.Interface.ExecuteHookCleanUp(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
Expand All @@ -229,7 +229,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook)
defer func() {
err := p.Interface.ExecuteHookCleanUp(execHook)
if err != nil {
fmt.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err)
cmd.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err)
}
}()

Expand Down Expand Up @@ -391,7 +391,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
Expand All @@ -401,7 +401,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
}
}
Expand Down
10 changes: 10 additions & 0 deletions ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"regexp"
"strings"

"github.com/spf13/cobra"

Expand All @@ -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 <module-name>Keeper.
var moduleNameKeeperAlias = map[string]string{
"auth": "account",
}

const (
flagDep = "dep"
flagIBC = "ibc"
Expand Down Expand Up @@ -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))
}

Expand Down
4 changes: 1 addition & 3 deletions ignite/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ignitecmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/version"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ignite/config/chain/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ignite/config/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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)
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
90 changes: 73 additions & 17 deletions ignite/pkg/availableport/availableport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
78 changes: 78 additions & 0 deletions ignite/pkg/availableport/availableport_test.go
Original file line number Diff line number Diff line change
@@ -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{}{}
}
})
}
}
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosfaucet/openapi/openapi.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading

0 comments on commit 1098033

Please sign in to comment.