From d4ca56b9018fb005a00c1491e6a571594f8d1867 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:07:50 -0500 Subject: [PATCH 01/80] base --- .../chainconfig/{config/config.go => base/base.go} | 2 +- ignite/chainconfig/chainconfig.go | 5 ++--- ignite/chainconfig/chainconfig_test.go | 3 +-- ignite/chainconfig/convert.go | 4 +--- ignite/chainconfig/errors.go | 6 ++---- ignite/chainconfig/parser.go | 8 +++----- ignite/chainconfig/parser_test.go | 5 ++--- ignite/chainconfig/testdata/testdata.go | 3 +-- ignite/chainconfig/v0/config.go | 13 ++++++------- ignite/chainconfig/v0/config_convert.go | 3 +-- ignite/chainconfig/v0/config_convert_test.go | 3 +-- ignite/chainconfig/v1/config.go | 7 +++---- ignite/chainconfig/v1/config_convert.go | 4 +--- ignite/chainconfig/v1/config_test.go | 11 +++++------ ignite/services/chain/generate.go | 3 +-- integration/cosmosgen/bank_module_test.go | 3 +-- integration/cosmosgen/custom_module_test.go | 3 +-- integration/node/cmd_query_bank_test.go | 5 ++--- integration/node/cmd_tx_bank_send_test.go | 5 ++--- 19 files changed, 37 insertions(+), 59 deletions(-) rename ignite/chainconfig/{config/config.go => base/base.go} (99%) diff --git a/ignite/chainconfig/config/config.go b/ignite/chainconfig/base/base.go similarity index 99% rename from ignite/chainconfig/config/config.go rename to ignite/chainconfig/base/base.go index b5b30b5229..b950a0b10e 100644 --- a/ignite/chainconfig/config/config.go +++ b/ignite/chainconfig/base/base.go @@ -1,4 +1,4 @@ -package config +package base import ( "fmt" diff --git a/ignite/chainconfig/chainconfig.go b/ignite/chainconfig/chainconfig.go index 665ce43a75..fc99377c08 100644 --- a/ignite/chainconfig/chainconfig.go +++ b/ignite/chainconfig/chainconfig.go @@ -9,7 +9,6 @@ import ( "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/config" v0 "github.com/ignite/cli/ignite/chainconfig/v0" v1 "github.com/ignite/cli/ignite/chainconfig/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -51,10 +50,10 @@ var ( DefaultOpenAPIPath = "docs/static/openapi.yml" // LatestVersion defines the latest version of the config. - LatestVersion config.Version = 1 + LatestVersion base.Version = 1 // Versions holds config types for the supported versions. - Versions = map[config.Version]config.Converter{ + Versions = map[base.Version]base.Converter{ 0: &v0.Config{}, 1: &v1.Config{}, } diff --git a/ignite/chainconfig/chainconfig_test.go b/ignite/chainconfig/chainconfig_test.go index 95279a43ae..c16eb3d25f 100644 --- a/ignite/chainconfig/chainconfig_test.go +++ b/ignite/chainconfig/chainconfig_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" ) func TestCheckVersion(t *testing.T) { @@ -34,5 +33,5 @@ func TestCheckVersionWithOutdatedVersion(t *testing.T) { // Assert require.ErrorAs(t, err, &wantError) - require.Equal(t, wantError.Version, config.Version(0)) + require.Equal(t, wantError.Version, base.Version(0)) } diff --git a/ignite/chainconfig/convert.go b/ignite/chainconfig/convert.go index 4fcb15b775..3e55a977ee 100644 --- a/ignite/chainconfig/convert.go +++ b/ignite/chainconfig/convert.go @@ -4,8 +4,6 @@ import ( "io" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/chainconfig/config" ) // Build time check for the latest config version type. @@ -15,7 +13,7 @@ import ( var _ = Versions[LatestVersion].(*Config) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c config.Converter) (_ *Config, err error) { +func ConvertLatest(c base.Converter) (_ *Config, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { diff --git a/ignite/chainconfig/errors.go b/ignite/chainconfig/errors.go index 01a77107f7..e5e4ff37a7 100644 --- a/ignite/chainconfig/errors.go +++ b/ignite/chainconfig/errors.go @@ -3,8 +3,6 @@ package chainconfig import ( "errors" "fmt" - - "github.com/ignite/cli/ignite/chainconfig/config" ) // ErrConfigNotFound indicates that the config.yml can't be found. @@ -21,7 +19,7 @@ func (e ValidationError) Error() string { // UnsupportedVersionError is returned when the version of the config is not supported. type UnsupportedVersionError struct { - Version config.Version + Version base.Version } func (e UnsupportedVersionError) Error() string { @@ -30,7 +28,7 @@ func (e UnsupportedVersionError) Error() string { // VersionError is returned when config version doesn't match with the version CLI supports. type VersionError struct { - Version config.Version + Version base.Version } func (e VersionError) Error() string { diff --git a/ignite/chainconfig/parser.go b/ignite/chainconfig/parser.go index 83722248bf..1e24e33878 100644 --- a/ignite/chainconfig/parser.go +++ b/ignite/chainconfig/parser.go @@ -8,8 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/chainconfig/config" ) // Parse reads a config file. @@ -92,9 +90,9 @@ func ParseNetworkFile(path string) (*Config, error) { } // ReadConfigVersion reads the config version. -func ReadConfigVersion(configFile io.Reader) (config.Version, error) { +func ReadConfigVersion(configFile io.Reader) (base.Version, error) { c := struct { - Version config.Version `yaml:"version"` + Version base.Version `yaml:"version"` }{} err := yaml.NewDecoder(configFile).Decode(&c) @@ -102,7 +100,7 @@ func ReadConfigVersion(configFile io.Reader) (config.Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version config.Version) (config.Converter, error) { +func decodeConfig(r io.Reader, version base.Version) (base.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} diff --git a/ignite/chainconfig/parser_test.go b/ignite/chainconfig/parser_test.go index c664110ff4..d2ba0441d2 100644 --- a/ignite/chainconfig/parser_test.go +++ b/ignite/chainconfig/parser_test.go @@ -9,14 +9,13 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/chainconfig/testdata" ) func TestReadConfigVersion(t *testing.T) { // Arrange r := strings.NewReader("version: 42") - want := config.Version(42) + want := base.Version(42) // Act version, err := chainconfig.ReadConfigVersion(r) @@ -57,7 +56,7 @@ func TestParseWithCurrentVersion(t *testing.T) { func TestParseWithUnknownVersion(t *testing.T) { // Arrange - version := config.Version(9999) + version := base.Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) var want *chainconfig.UnsupportedVersionError diff --git a/ignite/chainconfig/testdata/testdata.go b/ignite/chainconfig/testdata/testdata.go index 1cbb692a40..4f465ff5dd 100644 --- a/ignite/chainconfig/testdata/testdata.go +++ b/ignite/chainconfig/testdata/testdata.go @@ -4,13 +4,12 @@ import ( "testing" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" networkconfigTestData "github.com/ignite/cli/ignite/chainconfig/networkconfig/testdata" v0testdata "github.com/ignite/cli/ignite/chainconfig/v0/testdata" v1testdata "github.com/ignite/cli/ignite/chainconfig/v1/testdata" ) -var Versions = map[config.Version][]byte{ +var Versions = map[base.Version][]byte{ 0: v0testdata.ConfigYAML, 1: v1testdata.ConfigYAML, } diff --git a/ignite/chainconfig/v0/config.go b/ignite/chainconfig/v0/config.go index a0214b8ff6..dfbe008891 100644 --- a/ignite/chainconfig/v0/config.go +++ b/ignite/chainconfig/v0/config.go @@ -1,25 +1,24 @@ package v0 import ( + "github.com/ignite/cli/ignite/chainconfig/base" "io" "github.com/imdario/mergo" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/chainconfig/config" ) // Config is the user given configuration to do additional setup during serve. type Config struct { - config.BaseConfig `yaml:",inline"` + base.BaseConfig `yaml:",inline"` - Validator Validator `yaml:"validator"` - Init config.Init `yaml:"init"` - Host config.Host `yaml:"host"` + Validator Validator `yaml:"validator"` + Init base.Init `yaml:"init"` + Host base.Host `yaml:"host"` } // Clone returns an identical copy of the instance. -func (c *Config) Clone() (config.Converter, error) { +func (c *Config) Clone() (base.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/chainconfig/v0/config_convert.go b/ignite/chainconfig/v0/config_convert.go index 33955ae23d..009a01f5ed 100644 --- a/ignite/chainconfig/v0/config_convert.go +++ b/ignite/chainconfig/v0/config_convert.go @@ -1,12 +1,11 @@ package v0 import ( - "github.com/ignite/cli/ignite/chainconfig/config" v1 "github.com/ignite/cli/ignite/chainconfig/v1" ) // ConvertNext converts the current config version to the next one. -func (c *Config) ConvertNext() (config.Converter, error) { +func (c *Config) ConvertNext() (base.Converter, error) { targetCfg := v1.DefaultConfig() // All the fields in the base config remain the same diff --git a/ignite/chainconfig/v0/config_convert_test.go b/ignite/chainconfig/v0/config_convert_test.go index ed5c9a2df9..f2bc35ed29 100644 --- a/ignite/chainconfig/v0/config_convert_test.go +++ b/ignite/chainconfig/v0/config_convert_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig/config" v0testdata "github.com/ignite/cli/ignite/chainconfig/v0/testdata" v1 "github.com/ignite/cli/ignite/chainconfig/v1" ) @@ -21,7 +20,7 @@ func TestV0ToV1(t *testing.T) { // Assert require.NoError(t, err) require.NotNilf(t, cfgV1, "expected *v1.Config, got %T", c) - require.Equal(t, config.Version(1), cfgV1.GetVersion()) + require.Equal(t, base.Version(1), cfgV1.GetVersion()) require.Equal(t, cfgV0.Build, cfgV1.Build) require.Equal(t, cfgV0.Accounts, cfgV1.Accounts) require.Equal(t, cfgV0.Faucet, cfgV1.Faucet) diff --git a/ignite/chainconfig/v1/config.go b/ignite/chainconfig/v1/config.go index 76baa4df21..b1406d5a84 100644 --- a/ignite/chainconfig/v1/config.go +++ b/ignite/chainconfig/v1/config.go @@ -6,20 +6,19 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/xnet" ) // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{BaseConfig: config.DefaultBaseConfig()} + c := Config{BaseConfig: base.DefaultBaseConfig()} c.Version = 1 return &c } // Config is the user given configuration to do additional setup during serve. type Config struct { - config.BaseConfig `yaml:",inline"` + base.BaseConfig `yaml:",inline"` Validators []Validator `yaml:"validators"` Plugins []Plugin `yaml:"plugins,omitempty"` @@ -62,7 +61,7 @@ func (c *Config) SetDefaults() error { } // Clone returns an identical copy of the instance -func (c *Config) Clone() (config.Converter, error) { +func (c *Config) Clone() (base.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/chainconfig/v1/config_convert.go b/ignite/chainconfig/v1/config_convert.go index acb0cbbfa0..4eeadb7911 100644 --- a/ignite/chainconfig/v1/config_convert.go +++ b/ignite/chainconfig/v1/config_convert.go @@ -1,9 +1,7 @@ package v1 -import "github.com/ignite/cli/ignite/chainconfig/config" - // ConvertNext implements the conversion of the current config to the next version. -func (c *Config) ConvertNext() (config.Converter, error) { +func (c *Config) ConvertNext() (base.Converter, error) { // v1 is the latest version, there is no need to convert. return c, nil } diff --git a/ignite/chainconfig/v1/config_test.go b/ignite/chainconfig/v1/config_test.go index 0bf3e20ec3..99f6440171 100644 --- a/ignite/chainconfig/v1/config_test.go +++ b/ignite/chainconfig/v1/config_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig/config" v1 "github.com/ignite/cli/ignite/chainconfig/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -24,16 +23,16 @@ func TestConfigDecode(t *testing.T) { require.NoError(err) expected := v1.Config{ - BaseConfig: config.BaseConfig{ + BaseConfig: base.BaseConfig{ Version: 1, - Build: config.Build{ + Build: base.Build{ Binary: "evmosd", - Proto: config.Proto{ + Proto: base.Proto{ Path: "proto", ThirdPartyPaths: []string{"third_party/proto", "proto_vendor"}, }, }, - Accounts: []config.Account{ + Accounts: []base.Account{ { Name: "alice", Coins: []string{"100000000uatom", "100000000000000000000aevmos"}, @@ -45,7 +44,7 @@ func TestConfigDecode(t *testing.T) { Address: "cosmos1adn9gxjmrc3hrsdx5zpc9sj2ra7kgqkmphf8yw", }, }, - Faucet: config.Faucet{ + Faucet: base.Faucet{ Name: &[]string{"bob"}[0], Coins: []string{"10aevmos"}, Host: "0.0.0.0:4600", diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 49d20fb602..51ed5ee6f9 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -7,7 +7,6 @@ import ( "path/filepath" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -334,7 +333,7 @@ func (c Chain) joinGeneratedPath(rootPath string) string { return filepath.Join(c.app.Path, rootPath, "generated") } -func (c Chain) saveClientConfig(client config.Client) error { +func (c Chain) saveClientConfig(client base.Client) error { path := c.ConfigPath() file, err := os.Open(path) if err != nil { diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index afa37a147f..6b16cf7431 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" ) @@ -28,7 +27,7 @@ func TestBankModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []config.Account{ + accounts := []base.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 3e3dfec9e0..1ad798da81 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -29,7 +28,7 @@ func TestCustomModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []config.Account{ + accounts := []base.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 328cc758da..1c086e0529 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -66,14 +65,14 @@ func TestNodeQueryBankBalances(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *chainconfig.Config) { - c.Accounts = []config.Account{ + c.Accounts = []base.Account{ { Name: alice, Mnemonic: aliceMnemonic, Coins: []string{"5600atoken", "1200btoken", "100000000stake"}, }, } - c.Faucet = config.Faucet{} + c.Faucet = base.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index c7b0cd50e5..2dddc04c6e 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" "github.com/ignite/cli/ignite/pkg/cosmosclient" @@ -57,7 +56,7 @@ func TestNodeTxBankSend(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *chainconfig.Config) { - c.Accounts = []config.Account{ + c.Accounts = []base.Account{ { Name: alice, Mnemonic: aliceMnemonic, @@ -69,7 +68,7 @@ func TestNodeTxBankSend(t *testing.T) { Coins: []string{"10000token", "100000000stake"}, }, } - c.Faucet = config.Faucet{} + c.Faucet = base.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) env.Must(env.Exec("import alice", From 93c1ad5fcd01f8a70a61689c0be7c2b9d5c3ccf3 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:09:47 -0500 Subject: [PATCH 02/80] base refactor --- ignite/chainconfig/chainconfig.go | 2 ++ ignite/chainconfig/convert.go | 2 ++ ignite/chainconfig/errors.go | 2 ++ ignite/chainconfig/parser.go | 2 ++ ignite/chainconfig/v0/config_convert.go | 1 + ignite/chainconfig/v1/config.go | 1 + ignite/chainconfig/v1/config_convert.go | 2 ++ ignite/services/chain/generate.go | 1 + 8 files changed, 13 insertions(+) diff --git a/ignite/chainconfig/chainconfig.go b/ignite/chainconfig/chainconfig.go index fc99377c08..20c5bb5fc0 100644 --- a/ignite/chainconfig/chainconfig.go +++ b/ignite/chainconfig/chainconfig.go @@ -2,6 +2,7 @@ package chainconfig import ( "fmt" + "io" "os" "path/filepath" @@ -9,6 +10,7 @@ import ( "gopkg.in/yaml.v2" + "github.com/ignite/cli/ignite/chainconfig/base" v0 "github.com/ignite/cli/ignite/chainconfig/v0" v1 "github.com/ignite/cli/ignite/chainconfig/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" diff --git a/ignite/chainconfig/convert.go b/ignite/chainconfig/convert.go index 3e55a977ee..5a26776189 100644 --- a/ignite/chainconfig/convert.go +++ b/ignite/chainconfig/convert.go @@ -4,6 +4,8 @@ import ( "io" "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/chainconfig/base" ) // Build time check for the latest config version type. diff --git a/ignite/chainconfig/errors.go b/ignite/chainconfig/errors.go index e5e4ff37a7..b8335523ac 100644 --- a/ignite/chainconfig/errors.go +++ b/ignite/chainconfig/errors.go @@ -3,6 +3,8 @@ package chainconfig import ( "errors" "fmt" + + "github.com/ignite/cli/ignite/chainconfig/base" ) // ErrConfigNotFound indicates that the config.yml can't be found. diff --git a/ignite/chainconfig/parser.go b/ignite/chainconfig/parser.go index 1e24e33878..a158ef56f0 100644 --- a/ignite/chainconfig/parser.go +++ b/ignite/chainconfig/parser.go @@ -8,6 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/chainconfig/base" ) // Parse reads a config file. diff --git a/ignite/chainconfig/v0/config_convert.go b/ignite/chainconfig/v0/config_convert.go index 009a01f5ed..f4ff5fab4b 100644 --- a/ignite/chainconfig/v0/config_convert.go +++ b/ignite/chainconfig/v0/config_convert.go @@ -1,6 +1,7 @@ package v0 import ( + "github.com/ignite/cli/ignite/chainconfig/base" v1 "github.com/ignite/cli/ignite/chainconfig/v1" ) diff --git a/ignite/chainconfig/v1/config.go b/ignite/chainconfig/v1/config.go index b1406d5a84..e2758aba32 100644 --- a/ignite/chainconfig/v1/config.go +++ b/ignite/chainconfig/v1/config.go @@ -6,6 +6,7 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" + "github.com/ignite/cli/ignite/chainconfig/base" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/chainconfig/v1/config_convert.go b/ignite/chainconfig/v1/config_convert.go index 4eeadb7911..e7ffc5b655 100644 --- a/ignite/chainconfig/v1/config_convert.go +++ b/ignite/chainconfig/v1/config_convert.go @@ -1,5 +1,7 @@ package v1 +import "github.com/ignite/cli/ignite/chainconfig/base" + // ConvertNext implements the conversion of the current config to the next version. func (c *Config) ConvertNext() (base.Converter, error) { // v1 is the latest version, there is no need to convert. diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 51ed5ee6f9..0575861dff 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/chainconfig/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" From ee162da943ec01fa2a4020313985e5fc1e82d175 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:19:39 -0500 Subject: [PATCH 03/80] refactor --- ignite/chainconfig/testdata/testdata.go | 25 -------------- ignite/cmd/chain.go | 16 ++++----- ignite/cmd/cmd.go | 4 +-- ignite/cmd/ignite/main.go | 4 +-- ignite/cmd/plugin_test.go | 6 ++-- ignite/cmd/scaffold_react.go | 4 +-- ignite/cmd/scaffold_vue.go | 4 +-- ignite/{chainconfig => config}/base/base.go | 0 ignite/{chainconfig => config}/chainconfig.go | 8 ++--- .../chainconfig_test.go | 13 ++++---- ignite/{chainconfig => config}/convert.go | 4 +-- .../{chainconfig => config}/convert_test.go | 18 +++++----- ignite/{chainconfig => config}/errors.go | 4 +-- .../networkconfig/testdata/config.yaml | 0 .../networkconfig}/testdata/testdata.go | 2 +- ignite/{chainconfig => config}/parser.go | 4 +-- ignite/{chainconfig => config}/parser_test.go | 33 ++++++++++--------- ignite/config/testdata/testdata.go | 26 +++++++++++++++ ignite/{chainconfig => config}/v0/config.go | 2 +- .../v0/config_convert.go | 4 +-- .../v0/config_convert_test.go | 5 +-- .../{chainconfig => config}/v0/config_test.go | 2 +- .../v0/testdata/config.yaml | 0 .../v0/testdata/testdata.go | 2 +- ignite/{chainconfig => config}/v1/config.go | 2 +- .../v1/config_convert.go | 2 +- .../{chainconfig => config}/v1/config_test.go | 2 +- .../v1/testdata/config.yaml | 0 .../v1/testdata/config2.yaml | 0 .../v1}/testdata/testdata.go | 2 +- .../{chainconfig => config}/v1/validator.go | 0 .../v1/validator_servers.go | 0 .../v1/validator_servers_test.go | 2 +- ignite/pkg/cosmosgen/generate_vuex.go | 4 +-- ignite/services/chain/chain.go | 11 ++++--- ignite/services/chain/generate.go | 19 ++++++----- ignite/services/chain/init.go | 12 +++---- ignite/services/chain/runtime.go | 12 +++---- ignite/services/chain/serve.go | 20 +++++------ .../network/networkchain/binarycache.go | 4 +-- ignite/services/network/networkchain/init.go | 4 +-- .../network/networkchain/networkchain.go | 6 ++-- ignite/services/plugin/plugin.go | 8 ++--- ignite/services/plugin/plugin_test.go | 22 ++++++------- ignite/services/scaffolder/scaffolder.go | 8 ++--- ignite/version/version.go | 4 +-- integration/app.go | 16 ++++----- integration/chain/config_test.go | 2 +- integration/client.go | 6 ++-- integration/cosmosgen/bank_module_test.go | 2 +- integration/cosmosgen/custom_module_test.go | 2 +- integration/network/network_test.go | 8 ++--- integration/node/cmd_query_bank_test.go | 2 +- integration/node/cmd_tx_bank_send_test.go | 2 +- 54 files changed, 190 insertions(+), 184 deletions(-) delete mode 100644 ignite/chainconfig/testdata/testdata.go rename ignite/{chainconfig => config}/base/base.go (100%) rename ignite/{chainconfig => config}/chainconfig.go (96%) rename ignite/{chainconfig => config}/chainconfig_test.go (63%) rename ignite/{chainconfig => config}/convert.go (93%) rename ignite/{chainconfig => config}/convert_test.go (50%) rename ignite/{chainconfig => config}/errors.go (94%) rename ignite/{chainconfig => config}/networkconfig/testdata/config.yaml (100%) rename ignite/{chainconfig/v1 => config/networkconfig}/testdata/testdata.go (88%) rename ignite/{chainconfig => config}/parser.go (98%) rename ignite/{chainconfig => config}/parser_test.go (68%) create mode 100644 ignite/config/testdata/testdata.go rename ignite/{chainconfig => config}/v0/config.go (94%) rename ignite/{chainconfig => config}/v0/config_convert.go (93%) rename ignite/{chainconfig => config}/v0/config_convert_test.go (91%) rename ignite/{chainconfig => config}/v0/config_test.go (86%) rename ignite/{chainconfig => config}/v0/testdata/config.yaml (100%) rename ignite/{chainconfig => config}/v0/testdata/testdata.go (88%) rename ignite/{chainconfig => config}/v1/config.go (98%) rename ignite/{chainconfig => config}/v1/config_convert.go (80%) rename ignite/{chainconfig => config}/v1/config_test.go (99%) rename ignite/{chainconfig => config}/v1/testdata/config.yaml (100%) rename ignite/{chainconfig => config}/v1/testdata/config2.yaml (100%) rename ignite/{chainconfig/networkconfig => config/v1}/testdata/testdata.go (88%) rename ignite/{chainconfig => config}/v1/validator.go (100%) rename ignite/{chainconfig => config}/v1/validator_servers.go (100%) rename ignite/{chainconfig => config}/v1/validator_servers_test.go (97%) diff --git a/ignite/chainconfig/testdata/testdata.go b/ignite/chainconfig/testdata/testdata.go deleted file mode 100644 index 4f465ff5dd..0000000000 --- a/ignite/chainconfig/testdata/testdata.go +++ /dev/null @@ -1,25 +0,0 @@ -package testdata - -import ( - "testing" - - "github.com/ignite/cli/ignite/chainconfig" - networkconfigTestData "github.com/ignite/cli/ignite/chainconfig/networkconfig/testdata" - v0testdata "github.com/ignite/cli/ignite/chainconfig/v0/testdata" - v1testdata "github.com/ignite/cli/ignite/chainconfig/v1/testdata" -) - -var Versions = map[base.Version][]byte{ - 0: v0testdata.ConfigYAML, - 1: v1testdata.ConfigYAML, -} - -var NetworkConfig = networkconfigTestData.ConfigYAML - -func GetLatestConfig(t *testing.T) *chainconfig.Config { - return v1testdata.GetConfig(t) -} - -func GetLatestNetworkConfig(t *testing.T) *chainconfig.Config { - return networkconfigTestData.GetConfig(t) -} diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 71bcd68eee..582a7d2838 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -9,7 +9,7 @@ import ( "github.com/manifoldco/promptui" "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -100,7 +100,7 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) appPath := flagGetPath(cmd) configPath := getConfig(cmd) if configPath == "" { - if configPath, err = chainconfig.LocateDefault(appPath); err != nil { + if configPath, err = config.LocateDefault(appPath); err != nil { return err } } @@ -110,19 +110,19 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } - version, err := chainconfig.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := config.ReadConfigVersion(bytes.NewReader(rawCfg)) if err != nil { return err } // Config files with older versions must be migrated to the latest before executing the command - if version != chainconfig.LatestVersion { + if version != config.LatestVersion { if !getYes(cmd) { // Confirm before overwritting the config file - question := fmt.Sprintf(msgMigrationPrompt, version, chainconfig.LatestVersion) + question := fmt.Sprintf(msgMigrationPrompt, version, config.LatestVersion) if err := session.AskConfirm(question); err != nil { if errors.Is(err, promptui.ErrAbort) { - return fmt.Errorf(msgMigrationCancel, chainconfig.LatestVersion) + return fmt.Errorf(msgMigrationCancel, config.LatestVersion) } return err @@ -133,12 +133,12 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } } else { - session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chainconfig.LatestVersion)) + session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, config.LatestVersion)) } // Convert the current config to the latest version and update the YAML file var buf bytes.Buffer - if err := chainconfig.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { + if err := config.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { return err } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index f9ff52385f..5ac274cd1a 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -295,7 +295,7 @@ func printSection(session *cliui.Session, title string) error { } func newCache(cmd *cobra.Command) (cache.Storage, error) { - cacheRootDir, err := chainconfig.ConfigDirPath() + cacheRootDir, err := config.ConfigDirPath() if err != nil { return cache.Storage{}, err } diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index a70f7621da..0c885add76 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -6,8 +6,8 @@ import ( "fmt" "os" - "github.com/ignite/cli/ignite/chainconfig" ignitecmd "github.com/ignite/cli/ignite/cmd" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/clictx" "github.com/ignite/cli/ignite/pkg/validation" "github.com/ignite/cli/ignite/pkg/xstrings" @@ -43,7 +43,7 @@ func run() int { if err != nil { var ( validationErr validation.Error - versionErr chainconfig.VersionError + versionErr config.VersionError msg string ) diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index ba23a146c0..1c2c96ca89 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/services/plugin" "github.com/ignite/cli/ignite/services/plugin/mocks" ) @@ -308,7 +308,7 @@ ignite assert := assert.New(t) pi := mocks.NewPluginInterface(t) p := &plugin.Plugin{ - Plugin: chainconfig.Plugin{ + Plugin: config.Plugin{ Path: "foo", With: pluginParams, }, @@ -537,7 +537,7 @@ func TestLinkPluginHooks(t *testing.T) { // assert := assert.New(t) pi := mocks.NewPluginInterface(t) p := &plugin.Plugin{ - Plugin: chainconfig.Plugin{ + Plugin: config.Plugin{ Path: "foo", With: pluginParams, }, diff --git a/ignite/cmd/scaffold_react.go b/ignite/cmd/scaffold_react.go index ab3cb84636..745b622540 100644 --- a/ignite/cmd/scaffold_react.go +++ b/ignite/cmd/scaffold_react.go @@ -3,7 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -19,7 +19,7 @@ func NewScaffoldReact() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+chainconfig.DefaultReactPath, "path to scaffold content of the React app") + c.Flags().StringP(flagPath, "p", "./"+config.DefaultReactPath, "path to scaffold content of the React app") return c } diff --git a/ignite/cmd/scaffold_vue.go b/ignite/cmd/scaffold_vue.go index 6fedf5953c..6856dd497e 100644 --- a/ignite/cmd/scaffold_vue.go +++ b/ignite/cmd/scaffold_vue.go @@ -3,7 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -19,7 +19,7 @@ func NewScaffoldVue() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+chainconfig.DefaultVuePath, "path to scaffold content of the Vue.js app") + c.Flags().StringP(flagPath, "p", "./"+config.DefaultVuePath, "path to scaffold content of the Vue.js app") return c } diff --git a/ignite/chainconfig/base/base.go b/ignite/config/base/base.go similarity index 100% rename from ignite/chainconfig/base/base.go rename to ignite/config/base/base.go diff --git a/ignite/chainconfig/chainconfig.go b/ignite/config/chainconfig.go similarity index 96% rename from ignite/chainconfig/chainconfig.go rename to ignite/config/chainconfig.go index 20c5bb5fc0..dcde83efb4 100644 --- a/ignite/chainconfig/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -1,4 +1,4 @@ -package chainconfig +package config import ( "fmt" @@ -10,9 +10,9 @@ import ( "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/base" - v0 "github.com/ignite/cli/ignite/chainconfig/v0" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + "github.com/ignite/cli/ignite/config/base" + v0 "github.com/ignite/cli/ignite/config/v0" + v1 "github.com/ignite/cli/ignite/config/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" ) diff --git a/ignite/chainconfig/chainconfig_test.go b/ignite/config/chainconfig_test.go similarity index 63% rename from ignite/chainconfig/chainconfig_test.go rename to ignite/config/chainconfig_test.go index c16eb3d25f..80a451e310 100644 --- a/ignite/chainconfig/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -1,4 +1,4 @@ -package chainconfig_test +package config_test import ( "bytes" @@ -7,17 +7,18 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/base" ) func TestCheckVersion(t *testing.T) { // Arrange cfg := bytes.NewBufferString( - fmt.Sprintf("version: %d", chainconfig.LatestVersion), + fmt.Sprintf("version: %d", config.LatestVersion), ) // Act - err := chainconfig.CheckVersion(cfg) + err := config.CheckVersion(cfg) // Assert require.NoError(t, err) @@ -26,10 +27,10 @@ func TestCheckVersion(t *testing.T) { func TestCheckVersionWithOutdatedVersion(t *testing.T) { // Arrange cfg := bytes.NewBufferString("version: 0") - wantError := chainconfig.VersionError{} + wantError := config.VersionError{} // Act - err := chainconfig.CheckVersion(cfg) + err := config.CheckVersion(cfg) // Assert require.ErrorAs(t, err, &wantError) diff --git a/ignite/chainconfig/convert.go b/ignite/config/convert.go similarity index 93% rename from ignite/chainconfig/convert.go rename to ignite/config/convert.go index 5a26776189..024dbe3648 100644 --- a/ignite/chainconfig/convert.go +++ b/ignite/config/convert.go @@ -1,11 +1,11 @@ -package chainconfig +package config import ( "io" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config/base" ) // Build time check for the latest config version type. diff --git a/ignite/chainconfig/convert_test.go b/ignite/config/convert_test.go similarity index 50% rename from ignite/chainconfig/convert_test.go rename to ignite/config/convert_test.go index 313864784c..6d46b110bc 100644 --- a/ignite/chainconfig/convert_test.go +++ b/ignite/config/convert_test.go @@ -1,4 +1,4 @@ -package chainconfig_test +package config_test import ( "bytes" @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/testdata" - v0testdata "github.com/ignite/cli/ignite/chainconfig/v0/testdata" + "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/testdata" + v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" ) func TestConvertLatest(t *testing.T) { @@ -16,22 +16,22 @@ func TestConvertLatest(t *testing.T) { cfgV0 := v0testdata.GetConfig(t) // Act - cfgLatest, err := chainconfig.ConvertLatest(cfgV0) + cfgLatest, err := config.ConvertLatest(cfgV0) // Assert require.NoError(t, err) - require.Equal(t, chainconfig.LatestVersion, cfgLatest.GetVersion()) + require.Equal(t, config.LatestVersion, cfgLatest.GetVersion()) require.Equal(t, testdata.GetLatestConfig(t), cfgLatest) } func TestMigrateLatest(t *testing.T) { // Arrange - current := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion-1]) + current := bytes.NewReader(testdata.Versions[config.LatestVersion-1]) latest := bytes.Buffer{} - want := string(testdata.Versions[chainconfig.LatestVersion]) + want := string(testdata.Versions[config.LatestVersion]) // Act - err := chainconfig.MigrateLatest(current, &latest) + err := config.MigrateLatest(current, &latest) // Assert require.NotEmpty(t, want, "testdata is missing the latest config version") diff --git a/ignite/chainconfig/errors.go b/ignite/config/errors.go similarity index 94% rename from ignite/chainconfig/errors.go rename to ignite/config/errors.go index b8335523ac..fdb9d631bd 100644 --- a/ignite/chainconfig/errors.go +++ b/ignite/config/errors.go @@ -1,10 +1,10 @@ -package chainconfig +package config import ( "errors" "fmt" - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config/base" ) // ErrConfigNotFound indicates that the config.yml can't be found. diff --git a/ignite/chainconfig/networkconfig/testdata/config.yaml b/ignite/config/networkconfig/testdata/config.yaml similarity index 100% rename from ignite/chainconfig/networkconfig/testdata/config.yaml rename to ignite/config/networkconfig/testdata/config.yaml diff --git a/ignite/chainconfig/v1/testdata/testdata.go b/ignite/config/networkconfig/testdata/testdata.go similarity index 88% rename from ignite/chainconfig/v1/testdata/testdata.go rename to ignite/config/networkconfig/testdata/testdata.go index 01750e48de..ba6da10c58 100644 --- a/ignite/chainconfig/v1/testdata/testdata.go +++ b/ignite/config/networkconfig/testdata/testdata.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + v1 "github.com/ignite/cli/ignite/config/v1" ) //go:embed config.yaml diff --git a/ignite/chainconfig/parser.go b/ignite/config/parser.go similarity index 98% rename from ignite/chainconfig/parser.go rename to ignite/config/parser.go index a158ef56f0..fac2ad2cda 100644 --- a/ignite/chainconfig/parser.go +++ b/ignite/config/parser.go @@ -1,4 +1,4 @@ -package chainconfig +package config import ( "bytes" @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config/base" ) // Parse reads a config file. diff --git a/ignite/chainconfig/parser_test.go b/ignite/config/parser_test.go similarity index 68% rename from ignite/chainconfig/parser_test.go rename to ignite/config/parser_test.go index d2ba0441d2..240d863d3d 100644 --- a/ignite/chainconfig/parser_test.go +++ b/ignite/config/parser_test.go @@ -1,4 +1,4 @@ -package chainconfig_test +package config_test import ( "bytes" @@ -8,8 +8,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/testdata" + "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/base" + "github.com/ignite/cli/ignite/config/testdata" ) func TestReadConfigVersion(t *testing.T) { @@ -18,7 +19,7 @@ func TestReadConfigVersion(t *testing.T) { want := base.Version(42) // Act - version, err := chainconfig.ReadConfigVersion(r) + version, err := config.ReadConfigVersion(r) // Assert require.NoError(t, err) @@ -27,30 +28,30 @@ func TestReadConfigVersion(t *testing.T) { func TestParse(t *testing.T) { // Arrange: Initialize a reader with the previous version - ver := chainconfig.LatestVersion - 1 + ver := config.LatestVersion - 1 r := bytes.NewReader(testdata.Versions[ver]) // Act - cfg, err := chainconfig.Parse(r) + cfg, err := config.Parse(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, chainconfig.LatestVersion, cfg.Version) + require.Equal(t, config.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } func TestParseWithCurrentVersion(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion]) + r := bytes.NewReader(testdata.Versions[config.LatestVersion]) // Act - cfg, err := chainconfig.Parse(r) + cfg, err := config.Parse(r) // Assert require.NoError(t, err) - require.Equal(t, chainconfig.LatestVersion, cfg.Version) + require.Equal(t, config.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } @@ -59,10 +60,10 @@ func TestParseWithUnknownVersion(t *testing.T) { version := base.Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) - var want *chainconfig.UnsupportedVersionError + var want *config.UnsupportedVersionError // Act - _, err := chainconfig.Parse(r) + _, err := config.Parse(r) // Assert require.ErrorAs(t, err, &want) @@ -75,23 +76,23 @@ func TestParseNetworkWithCurrentVersion(t *testing.T) { r := bytes.NewReader(testdata.NetworkConfig) // Act - cfg, err := chainconfig.ParseNetwork(r) + cfg, err := config.ParseNetwork(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, chainconfig.LatestVersion, cfg.Version) + require.Equal(t, config.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestNetworkConfig(t).Accounts, cfg.Accounts) require.Equal(t, testdata.GetLatestNetworkConfig(t).Genesis, cfg.Genesis) } func TestParseNetworkWithInvalidData(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion]) + r := bytes.NewReader(testdata.Versions[config.LatestVersion]) // Act - _, err := chainconfig.ParseNetwork(r) + _, err := config.ParseNetwork(r) // Assert error require.True( diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go new file mode 100644 index 0000000000..32199db8ce --- /dev/null +++ b/ignite/config/testdata/testdata.go @@ -0,0 +1,26 @@ +package testdata + +import ( + "testing" + + "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/base" + networkconfigTestData "github.com/ignite/cli/ignite/config/networkconfig/testdata" + v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" + v1testdata "github.com/ignite/cli/ignite/config/v1/testdata" +) + +var Versions = map[base.Version][]byte{ + 0: v0testdata.ConfigYAML, + 1: v1testdata.ConfigYAML, +} + +var NetworkConfig = networkconfigTestData.ConfigYAML + +func GetLatestConfig(t *testing.T) *config.Config { + return v1testdata.GetConfig(t) +} + +func GetLatestNetworkConfig(t *testing.T) *config.Config { + return networkconfigTestData.GetConfig(t) +} diff --git a/ignite/chainconfig/v0/config.go b/ignite/config/v0/config.go similarity index 94% rename from ignite/chainconfig/v0/config.go rename to ignite/config/v0/config.go index dfbe008891..a9ec1db08e 100644 --- a/ignite/chainconfig/v0/config.go +++ b/ignite/config/v0/config.go @@ -1,7 +1,7 @@ package v0 import ( - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config/base" "io" "github.com/imdario/mergo" diff --git a/ignite/chainconfig/v0/config_convert.go b/ignite/config/v0/config_convert.go similarity index 93% rename from ignite/chainconfig/v0/config_convert.go rename to ignite/config/v0/config_convert.go index f4ff5fab4b..a66a3d879a 100644 --- a/ignite/chainconfig/v0/config_convert.go +++ b/ignite/config/v0/config_convert.go @@ -1,8 +1,8 @@ package v0 import ( - "github.com/ignite/cli/ignite/chainconfig/base" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + "github.com/ignite/cli/ignite/config/base" + v1 "github.com/ignite/cli/ignite/config/v1" ) // ConvertNext converts the current config version to the next one. diff --git a/ignite/chainconfig/v0/config_convert_test.go b/ignite/config/v0/config_convert_test.go similarity index 91% rename from ignite/chainconfig/v0/config_convert_test.go rename to ignite/config/v0/config_convert_test.go index f2bc35ed29..38c16e1f07 100644 --- a/ignite/chainconfig/v0/config_convert_test.go +++ b/ignite/config/v0/config_convert_test.go @@ -5,8 +5,9 @@ import ( "github.com/stretchr/testify/require" - v0testdata "github.com/ignite/cli/ignite/chainconfig/v0/testdata" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + "github.com/ignite/cli/ignite/config/base" + v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" + v1 "github.com/ignite/cli/ignite/config/v1" ) func TestV0ToV1(t *testing.T) { diff --git a/ignite/chainconfig/v0/config_test.go b/ignite/config/v0/config_test.go similarity index 86% rename from ignite/chainconfig/v0/config_test.go rename to ignite/config/v0/config_test.go index eed92d178c..5559cbc717 100644 --- a/ignite/chainconfig/v0/config_test.go +++ b/ignite/config/v0/config_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - v0 "github.com/ignite/cli/ignite/chainconfig/v0" + v0 "github.com/ignite/cli/ignite/config/v0" ) func TestClone(t *testing.T) { diff --git a/ignite/chainconfig/v0/testdata/config.yaml b/ignite/config/v0/testdata/config.yaml similarity index 100% rename from ignite/chainconfig/v0/testdata/config.yaml rename to ignite/config/v0/testdata/config.yaml diff --git a/ignite/chainconfig/v0/testdata/testdata.go b/ignite/config/v0/testdata/testdata.go similarity index 88% rename from ignite/chainconfig/v0/testdata/testdata.go rename to ignite/config/v0/testdata/testdata.go index 1e625996f5..20e9b9ef5e 100644 --- a/ignite/chainconfig/v0/testdata/testdata.go +++ b/ignite/config/v0/testdata/testdata.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - v0 "github.com/ignite/cli/ignite/chainconfig/v0" + v0 "github.com/ignite/cli/ignite/config/v0" ) //go:embed config.yaml diff --git a/ignite/chainconfig/v1/config.go b/ignite/config/v1/config.go similarity index 98% rename from ignite/chainconfig/v1/config.go rename to ignite/config/v1/config.go index e2758aba32..126de4f165 100644 --- a/ignite/chainconfig/v1/config.go +++ b/ignite/config/v1/config.go @@ -6,7 +6,7 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config/base" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/chainconfig/v1/config_convert.go b/ignite/config/v1/config_convert.go similarity index 80% rename from ignite/chainconfig/v1/config_convert.go rename to ignite/config/v1/config_convert.go index e7ffc5b655..0b3064a068 100644 --- a/ignite/chainconfig/v1/config_convert.go +++ b/ignite/config/v1/config_convert.go @@ -1,6 +1,6 @@ package v1 -import "github.com/ignite/cli/ignite/chainconfig/base" +import "github.com/ignite/cli/ignite/config/base" // ConvertNext implements the conversion of the current config to the next version. func (c *Config) ConvertNext() (base.Converter, error) { diff --git a/ignite/chainconfig/v1/config_test.go b/ignite/config/v1/config_test.go similarity index 99% rename from ignite/chainconfig/v1/config_test.go rename to ignite/config/v1/config_test.go index 99f6440171..01ae454392 100644 --- a/ignite/chainconfig/v1/config_test.go +++ b/ignite/config/v1/config_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + v1 "github.com/ignite/cli/ignite/config/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/chainconfig/v1/testdata/config.yaml b/ignite/config/v1/testdata/config.yaml similarity index 100% rename from ignite/chainconfig/v1/testdata/config.yaml rename to ignite/config/v1/testdata/config.yaml diff --git a/ignite/chainconfig/v1/testdata/config2.yaml b/ignite/config/v1/testdata/config2.yaml similarity index 100% rename from ignite/chainconfig/v1/testdata/config2.yaml rename to ignite/config/v1/testdata/config2.yaml diff --git a/ignite/chainconfig/networkconfig/testdata/testdata.go b/ignite/config/v1/testdata/testdata.go similarity index 88% rename from ignite/chainconfig/networkconfig/testdata/testdata.go rename to ignite/config/v1/testdata/testdata.go index 01750e48de..ba6da10c58 100644 --- a/ignite/chainconfig/networkconfig/testdata/testdata.go +++ b/ignite/config/v1/testdata/testdata.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + v1 "github.com/ignite/cli/ignite/config/v1" ) //go:embed config.yaml diff --git a/ignite/chainconfig/v1/validator.go b/ignite/config/v1/validator.go similarity index 100% rename from ignite/chainconfig/v1/validator.go rename to ignite/config/v1/validator.go diff --git a/ignite/chainconfig/v1/validator_servers.go b/ignite/config/v1/validator_servers.go similarity index 100% rename from ignite/chainconfig/v1/validator_servers.go rename to ignite/config/v1/validator_servers.go diff --git a/ignite/chainconfig/v1/validator_servers_test.go b/ignite/config/v1/validator_servers_test.go similarity index 97% rename from ignite/chainconfig/v1/validator_servers_test.go rename to ignite/config/v1/validator_servers_test.go index 927c604ffb..5ecda3d288 100644 --- a/ignite/chainconfig/v1/validator_servers_test.go +++ b/ignite/config/v1/validator_servers_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + v1 "github.com/ignite/cli/ignite/config/v1" xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index 069f77c078..cde5088d04 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -11,7 +11,7 @@ import ( "github.com/imdario/mergo" "golang.org/x/sync/errgroup" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" "github.com/ignite/cli/ignite/pkg/gomodulepath" ) @@ -26,7 +26,7 @@ func newVuexGenerator(g *generator) *vuexGenerator { func (g *generator) updateVueDependencies() error { // Init the path to the "vue" folders inside the app - vuePath := filepath.Join(g.appPath, chainconfig.DefaultVuePath) + vuePath := filepath.Join(g.appPath, config.DefaultVuePath) packagesPath := filepath.Join(vuePath, "package.json") if _, err := os.Stat(packagesPath); errors.Is(err, os.ErrNotExist) { return nil diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 6cc878c2c7..46ebe9cfeb 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -2,6 +2,7 @@ package chain import ( "context" + "os" "path/filepath" @@ -9,7 +10,7 @@ import ( "github.com/tendermint/spn/pkg/chainid" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" uilog "github.com/ignite/cli/ignite/pkg/cliui/log" @@ -202,7 +203,7 @@ func (c *Chain) ConfigPath() string { if c.options.ConfigFile != "" { return c.options.ConfigFile } - path, err := chainconfig.LocateDefault(c.app.Path) + path, err := config.LocateDefault(c.app.Path) if err != nil { return "" } @@ -210,12 +211,12 @@ func (c *Chain) ConfigPath() string { } // Config returns the config of the chain -func (c *Chain) Config() (*chainconfig.Config, error) { +func (c *Chain) Config() (*config.Config, error) { configPath := c.ConfigPath() if configPath == "" { - return chainconfig.DefaultConfig(), nil + return config.DefaultConfig(), nil } - return chainconfig.ParseFile(configPath) + return config.ParseFile(configPath) } // ID returns the chain's id. diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 0575861dff..516021ce83 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -3,11 +3,12 @@ package chain import ( "context" "fmt" + "os" "path/filepath" - "github.com/ignite/cli/ignite/chainconfig" - "github.com/ignite/cli/ignite/chainconfig/base" + "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -158,7 +159,7 @@ func (c *Chain) Generate( if targetOptions.isTSClientEnabled { tsClientPath = targetOptions.tsClientPath if tsClientPath == "" { - tsClientPath = chainconfig.TSClientPath(*conf) + tsClientPath = config.TSClientPath(*conf) // When TS client is generated make sure the config is updated // with the output path when the client path option is empty. @@ -185,7 +186,7 @@ func (c *Chain) Generate( //nolint:staticcheck //ignore SA1019 until vuex config option is removed vuexPath = targetOptions.vuexPath if vuexPath == "" { - vuexPath = chainconfig.VuexPath(conf) + vuexPath = config.VuexPath(conf) // When Vuex stores are generated make sure the config is updated // with the output path when the client path option is empty. @@ -211,7 +212,7 @@ func (c *Chain) Generate( composablesPath = targetOptions.composablesPath if composablesPath == "" { - composablesPath = chainconfig.ComposablesPath(conf) + composablesPath = config.ComposablesPath(conf) if conf.Client.Composables.Path == "" { conf.Client.Composables.Path = composablesPath @@ -235,7 +236,7 @@ func (c *Chain) Generate( if targetOptions.isHooksEnabled { hooksPath = targetOptions.hooksPath if hooksPath == "" { - hooksPath = chainconfig.HooksPath(conf) + hooksPath = config.HooksPath(conf) if conf.Client.Hooks.Path == "" { conf.Client.Hooks.Path = hooksPath @@ -259,7 +260,7 @@ func (c *Chain) Generate( if targetOptions.isOpenAPIEnabled { openAPIPath = conf.Client.OpenAPI.Path if openAPIPath == "" { - openAPIPath = chainconfig.DefaultOpenAPIPath + openAPIPath = config.DefaultOpenAPIPath } // Non absolute OpenAPI paths must be treated as relative to the app directory @@ -347,12 +348,12 @@ func (c Chain) saveClientConfig(client base.Client) error { // values that otherwise would be initialized to defaults. // Defaults must be ignored to avoid writing them to the // YAML config file when they are not present. - var cfg chainconfig.Config + var cfg config.Config if err := cfg.Decode(file); err != nil { return err } cfg.Client = client - return chainconfig.Save(cfg, path) + return config.Save(cfg, path) } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index 3e3b3870c5..fa3268cd44 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -8,7 +8,7 @@ import ( "github.com/imdario/mergo" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/view/accountview" "github.com/ignite/cli/ignite/pkg/confile" @@ -86,7 +86,7 @@ func (c *Chain) InitChain(ctx context.Context) error { } // InitAccounts initializes the chain accounts and creates validator gentxs -func (c *Chain) InitAccounts(ctx context.Context, conf *chainconfig.Config) error { +func (c *Chain) InitAccounts(ctx context.Context, cfg *config.Config) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -97,7 +97,7 @@ func (c *Chain) InitAccounts(ctx context.Context, conf *chainconfig.Config) erro var accounts accountview.Accounts // add accounts from config into genesis - for _, account := range conf.Accounts { + for _, account := range cfg.Accounts { var generatedAccount chaincmdrunner.Account accountAddress := account.Address @@ -129,8 +129,8 @@ func (c *Chain) InitAccounts(ctx context.Context, conf *chainconfig.Config) erro c.ev.SendView(accounts) // 0 length validator set when using network config - if len(conf.Validators) != 0 { - _, err = c.IssueGentx(ctx, createValidatorFromConfig(conf)) + if len(cfg.Validators) != 0 { + _, err = c.IssueGentx(ctx, createValidatorFromConfig(cfg)) } return err @@ -222,7 +222,7 @@ type Account struct { Coins string } -func createValidatorFromConfig(conf *chainconfig.Config) (validator Validator) { +func createValidatorFromConfig(conf *config.Config) (validator Validator) { // Currently, we support the config file with one valid validator. validatorFromConfig := conf.Validators[0] validator.Name = validatorFromConfig.Name diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index 62c13082bf..f4e27c9dc7 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -9,7 +9,7 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/pelletier/go-toml" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/xurl" @@ -36,7 +36,7 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida } // Start wraps the "appd start" command to begin running a chain from the daemon -func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chainconfig.Config) error { +func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *config.Config) error { validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { @@ -49,7 +49,7 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *cha } // Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml) -func (c Chain) Configure(homePath string, cfg *chainconfig.Config) error { +func (c Chain) Configure(homePath string, cfg *config.Config) error { if err := c.appTOML(homePath, cfg); err != nil { return err } @@ -59,7 +59,7 @@ func (c Chain) Configure(homePath string, cfg *chainconfig.Config) error { return c.configTOML(homePath, cfg) } -func (c Chain) appTOML(homePath string, cfg *chainconfig.Config) error { +func (c Chain) appTOML(homePath string, cfg *config.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") config, err := toml.LoadFile(path) @@ -106,7 +106,7 @@ func (c Chain) appTOML(homePath string, cfg *chainconfig.Config) error { return err } -func (c Chain) configTOML(homePath string, cfg *chainconfig.Config) error { +func (c Chain) configTOML(homePath string, cfg *config.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") config, err := toml.LoadFile(path) @@ -153,7 +153,7 @@ func (c Chain) configTOML(homePath string, cfg *chainconfig.Config) error { return err } -func (c Chain) clientTOML(homePath string, cfg *chainconfig.Config) error { +func (c Chain) clientTOML(homePath string, cfg *config.Config) error { path := filepath.Join(homePath, "config/client.toml") config, err := toml.LoadFile(path) if os.IsNotExist(err) { diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 61aae8f29e..1f2f25a84e 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -14,7 +14,7 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -53,7 +53,7 @@ var ( // starportSavePath is the place where chain exported genesis are saved starportSavePath = xfilepath.Join( - chainconfig.ConfigDirPath, + config.ConfigDirPath, xfilepath.Path("local-chains"), ) ) @@ -130,7 +130,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . if _, err := os.Stat(c.options.ConfigFile); err != nil { return err } - } else if _, err := chainconfig.LocateDefault(c.app.Path); err != nil { + } else if _, err := config.LocateDefault(c.app.Path); err != nil { return err } @@ -160,7 +160,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . serveCtx context.Context buildErr *CannotBuildAppError startErr *CannotStartAppError - validationErr *chainconfig.ValidationError + validationErr *config.ValidationError ) serveCtx, c.serveCancel = context.WithCancel(ctx) @@ -427,7 +427,7 @@ func (c *Chain) serve( return c.start(ctx, conf) } -func (c *Chain) start(ctx context.Context, config *chainconfig.Config) error { +func (c *Chain) start(ctx context.Context, cfg *config.Config) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -436,7 +436,7 @@ func (c *Chain) start(ctx context.Context, config *chainconfig.Config) error { g, ctx := errgroup.WithContext(ctx) // start the blockchain. - g.Go(func() error { return c.Start(ctx, commands, config) }) + g.Go(func() error { return c.Start(ctx, commands, cfg) }) // start the faucet if enabled. faucet, err := c.Faucet(ctx) @@ -462,7 +462,7 @@ func (c *Chain) start(ctx context.Context, config *chainconfig.Config) error { c.served = true // Get the first validator - validator := config.Validators[0] + validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { return err @@ -485,7 +485,7 @@ func (c *Chain) start(ctx context.Context, config *chainconfig.Config) error { ) if isFaucetEnabled { - faucetAddr, _ := xurl.HTTP(chainconfig.FaucetHost(config)) + faucetAddr, _ := xurl.HTTP(config.FaucetHost(cfg)) c.ev.Send( fmt.Sprintf("Token faucet: %s", faucetAddr), @@ -497,13 +497,13 @@ func (c *Chain) start(ctx context.Context, config *chainconfig.Config) error { } func (c *Chain) runFaucetServer(ctx context.Context, faucet cosmosfaucet.Faucet) error { - config, err := c.Config() + cfg, err := c.Config() if err != nil { return err } return xhttp.Serve(ctx, &http.Server{ - Addr: chainconfig.FaucetHost(config), + Addr: config.FaucetHost(cfg), Handler: faucet, }) } diff --git a/ignite/services/network/networkchain/binarycache.go b/ignite/services/network/networkchain/binarycache.go index d5d39455d3..1833590421 100644 --- a/ignite/services/network/networkchain/binarycache.go +++ b/ignite/services/network/networkchain/binarycache.go @@ -1,7 +1,7 @@ package networkchain import ( - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/checksum" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -78,7 +78,7 @@ func checkBinaryCacheForLaunchID(launchID uint64, binaryHash, sourceHash string) func getBinaryCacheFilepath() (string, error) { return xfilepath.Join( - chainconfig.ConfigDirPath, + config.ConfigDirPath, xfilepath.Path(SPNCacheDirectory), xfilepath.Path(BinaryCacheDirectory), xfilepath.Path(BinaryCacheFilename), diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index 719a52705a..8c3098d0c2 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" cosmosgenesis "github.com/ignite/cli/ignite/pkg/cosmosutil/genesis" "github.com/ignite/cli/ignite/pkg/events" @@ -124,7 +124,7 @@ func (c *Chain) initGenesis(ctx context.Context) error { return fmt.Errorf("the config for genesis doesn't exist: %w", err) } - config, err := chainconfig.ParseNetworkFile(path) + config, err := config.ParseNetworkFile(path) if err != nil { return err } diff --git a/ignite/services/network/networkchain/networkchain.go b/ignite/services/network/networkchain/networkchain.go index a832360651..2f2d8e51e1 100644 --- a/ignite/services/network/networkchain/networkchain.go +++ b/ignite/services/network/networkchain/networkchain.go @@ -11,7 +11,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/chaincmd" "github.com/ignite/cli/ignite/pkg/checksum" @@ -287,7 +287,7 @@ func (c Chain) NodeID(ctx context.Context) (string, error) { func (c Chain) CheckConfigVersion() error { configPath := c.chain.ConfigPath() if configPath == "" { - return chainconfig.ErrConfigNotFound + return config.ErrConfigNotFound } file, err := os.Open(configPath) @@ -297,7 +297,7 @@ func (c Chain) CheckConfigVersion() error { defer file.Close() - return chainconfig.CheckVersion(file) + return config.CheckVersion(file) } // Build builds chain sources, also checks if source was already built diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 2ff4a54f62..b3f2eb25b4 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -20,7 +20,7 @@ import ( hplugin "github.com/hashicorp/go-plugin" "github.com/pkg/errors" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" cliexec "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -31,14 +31,14 @@ import ( // pluginsPath holds the plugin cache directory. var pluginsPath = xfilepath.Join( - chainconfig.ConfigDirPath, + config.ConfigDirPath, xfilepath.Path("plugins"), ) // Plugin represents a ignite plugin. type Plugin struct { // Embed the plugin configuration - chainconfig.Plugin + config.Plugin // Interface allows to communicate with the plugin via net/rpc. Interface Interface // If any error occurred during the plugin load, it's stored here @@ -97,7 +97,7 @@ func Update(plugins ...*Plugin) error { } // newPlugin creates a Plugin from configuration. -func newPlugin(pluginsDir string, cp chainconfig.Plugin) *Plugin { +func newPlugin(pluginsDir string, cp config.Plugin) *Plugin { var ( p = &Plugin{Plugin: cp} pluginPath = cp.Path diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index c324048cc0..6e3b4857d4 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -27,7 +27,7 @@ func TestNewPlugin(t *testing.T) { tests := []struct { name string - pluginCfg chainconfig.Plugin + pluginCfg config.Plugin expectedPlugin Plugin }{ { @@ -38,21 +38,21 @@ func TestNewPlugin(t *testing.T) { }, { name: "fail: local plugin doesnt exists", - pluginCfg: chainconfig.Plugin{Path: "/xxx/yyy/plugin"}, + pluginCfg: config.Plugin{Path: "/xxx/yyy/plugin"}, expectedPlugin: Plugin{ Error: errors.Errorf(`local plugin path "/xxx/yyy/plugin" not found`), }, }, { name: "fail: local plugin is not a dir", - pluginCfg: chainconfig.Plugin{Path: path.Join(wd, "testdata/fakebin")}, + pluginCfg: config.Plugin{Path: path.Join(wd, "testdata/fakebin")}, expectedPlugin: Plugin{ Error: errors.Errorf(fmt.Sprintf("local plugin path %q is not a dir", path.Join(wd, "testdata/fakebin"))), }, }, { name: "ok: local plugin", - pluginCfg: chainconfig.Plugin{Path: path.Join(wd, "testdata")}, + pluginCfg: config.Plugin{Path: path.Join(wd, "testdata")}, expectedPlugin: Plugin{ srcPath: path.Join(wd, "testdata"), binaryName: "testdata", @@ -60,21 +60,21 @@ func TestNewPlugin(t *testing.T) { }, { name: "fail: remote plugin with only domain", - pluginCfg: chainconfig.Plugin{Path: "github.com"}, + pluginCfg: config.Plugin{Path: "github.com"}, expectedPlugin: Plugin{ Error: errors.Errorf(`plugin path "github.com" is not a valid repository URL`), }, }, { name: "fail: remote plugin with incomplete URL", - pluginCfg: chainconfig.Plugin{Path: "github.com/ignite"}, + pluginCfg: config.Plugin{Path: "github.com/ignite"}, expectedPlugin: Plugin{ Error: errors.Errorf(`plugin path "github.com/ignite" is not a valid repository URL`), }, }, { name: "ok: remote plugin", - pluginCfg: chainconfig.Plugin{Path: "github.com/ignite/plugin"}, + pluginCfg: config.Plugin{Path: "github.com/ignite/plugin"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin", cloneURL: "https://github.com/ignite/plugin", @@ -86,7 +86,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with @ref", - pluginCfg: chainconfig.Plugin{Path: "github.com/ignite/plugin@develop"}, + pluginCfg: config.Plugin{Path: "github.com/ignite/plugin@develop"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin@develop", cloneURL: "https://github.com/ignite/plugin", @@ -98,7 +98,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with subpath", - pluginCfg: chainconfig.Plugin{Path: "github.com/ignite/plugin/plugin1"}, + pluginCfg: config.Plugin{Path: "github.com/ignite/plugin/plugin1"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin", cloneURL: "https://github.com/ignite/plugin", @@ -110,7 +110,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with subpath and @ref", - pluginCfg: chainconfig.Plugin{Path: "github.com/ignite/plugin/plugin1@develop"}, + pluginCfg: config.Plugin{Path: "github.com/ignite/plugin/plugin1@develop"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin@develop", cloneURL: "https://github.com/ignite/plugin", @@ -343,7 +343,7 @@ func TestPluginClean(t *testing.T) { { name: "dont clean local plugin", plugin: &Plugin{ - Plugin: chainconfig.Plugin{Path: "/local"}, + Plugin: config.Plugin{Path: "/local"}, }, }, { diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 3823ee5700..1aeb9ff8f1 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -6,7 +6,7 @@ import ( "context" "path/filepath" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cosmosanalysis" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -76,11 +76,11 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP return err } - confpath, err := chainconfig.LocateDefault(projectPath) + confpath, err := config.LocateDefault(projectPath) if err != nil { return err } - conf, err := chainconfig.ParseFile(confpath) + conf, err := config.ParseFile(confpath) if err != nil { return err } @@ -92,7 +92,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP // Generate Typescript client code if it's enabled or when Vuex stores are generated if conf.Client.Typescript.Path != "" || conf.Client.Vuex.Path != "" { //nolint:staticcheck //ignore SA1019 until vuex config option is removed - tsClientPath := chainconfig.TSClientPath(*conf) + tsClientPath := config.TSClientPath(*conf) if !filepath.IsAbs(tsClientPath) { tsClientPath = filepath.Join(projectPath, tsClientPath) } diff --git a/ignite/version/version.go b/ignite/version/version.go index 72ea7bc7d8..560605aaa2 100644 --- a/ignite/version/version.go +++ b/ignite/version/version.go @@ -13,7 +13,7 @@ import ( "github.com/blang/semver/v4" "github.com/google/go-github/v48/github" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gitpod" @@ -103,7 +103,7 @@ func Long(ctx context.Context) string { write("Ignite CLI version", Version) write("Ignite CLI build date", date) write("Ignite CLI source hash", head) - write("Ignite CLI config version", chainconfig.LatestVersion) + write("Ignite CLI config version", config.LatestVersion) write("Cosmos SDK version", sdkVersion) write("Your OS", runtime.GOOS) diff --git a/integration/app.go b/integration/app.go index 88f50c74b5..13493502e2 100644 --- a/integration/app.go +++ b/integration/app.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/chainconfig" - v1 "github.com/ignite/cli/ignite/chainconfig/v1" + "github.com/ignite/cli/ignite/config" + v1 "github.com/ignite/cli/ignite/config/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gocmd" @@ -187,7 +187,7 @@ func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string) { port, err := availableport.Find(1) require.NoError(a.env.t, err) - a.EditConfig(func(c *chainconfig.Config) { + a.EditConfig(func(c *config.Config) { c.Faucet.Port = port[0] c.Faucet.Coins = coins c.Faucet.CoinsMax = coinsMax @@ -219,7 +219,7 @@ func (a App) RandomizeServerPorts() Hosts { API: genAddr(ports[5]), } - a.EditConfig(func(c *chainconfig.Config) { + a.EditConfig(func(c *config.Config) { v := &c.Validators[0] s := v1.Servers{} @@ -241,24 +241,24 @@ func (a App) RandomizeServerPorts() Hosts { func (a App) UseRandomHomeDir() (homeDirPath string) { dir := a.env.TmpDir() - a.EditConfig(func(c *chainconfig.Config) { + a.EditConfig(func(c *config.Config) { c.Validators[0].Home = dir }) return dir } -func (a App) Config() chainconfig.Config { +func (a App) Config() config.Config { bz, err := os.ReadFile(a.configPath) require.NoError(a.env.t, err) - var conf chainconfig.Config + var conf config.Config err = yaml.Unmarshal(bz, &conf) require.NoError(a.env.t, err) return conf } -func (a App) EditConfig(apply func(*chainconfig.Config)) { +func (a App) EditConfig(apply func(*config.Config)) { conf := a.Config() apply(&conf) diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index cf232715e1..8cb447a3aa 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -26,7 +26,7 @@ func TestOverwriteSDKConfigsAndChainID(t *testing.T) { isBackendAliveErr error ) - var cfg chainconfig.Config + var cfg config.Config cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml")) require.NoError(t, cf.Load(&cfg)) diff --git a/integration/client.go b/integration/client.go index 1e29a8b5e3..4ab6622b6c 100644 --- a/integration/client.go +++ b/integration/client.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" ) @@ -68,7 +68,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Absolute path to the blockchain app directory "TEST_CHAIN_PATH": a.path, // Absolute path to the TS client directory - "TEST_TSCLIENT_DIR": filepath.Join(a.path, chainconfig.DefaultTSClientPath), + "TEST_TSCLIENT_DIR": filepath.Join(a.path, config.DefaultTSClientPath), }, } for _, o := range options { @@ -83,7 +83,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Install the dependencies needed to run TS client tests ok = a.env.Exec("install client dependencies", step.NewSteps( step.New( - step.Workdir(filepath.Join(a.path, chainconfig.DefaultTSClientPath)), + step.Workdir(filepath.Join(a.path, config.DefaultTSClientPath)), step.Stdout(&output), step.Exec(npm, "install"), step.PostExec(func(err error) error { diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 6b16cf7431..6b7de60bca 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -57,7 +57,7 @@ func TestBankModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chainconfig.Config) { + app.EditConfig(func(cfg *config.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 1ad798da81..2db079c645 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -40,7 +40,7 @@ func TestCustomModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chainconfig.Config) { + app.EditConfig(func(cfg *config.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/network/network_test.go b/integration/network/network_test.go index d2bab9096c..85eb87f93c 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -74,17 +74,17 @@ func migrateSPNConfig(t *testing.T, spnPath string) { rawCfg, err := os.ReadFile(configPath) require.NoError(t, err) - version, err := chainconfig.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := config.ReadConfigVersion(bytes.NewReader(rawCfg)) require.NoError(t, err) - if version != chainconfig.LatestVersion { - t.Logf("migrating spn config from v%d to v%d", version, chainconfig.LatestVersion) + if version != config.LatestVersion { + t.Logf("migrating spn config from v%d to v%d", version, config.LatestVersion) file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755) require.NoError(t, err) defer file.Close() - err = chainconfig.MigrateLatest(bytes.NewReader(rawCfg), file) + err = config.MigrateLatest(bytes.NewReader(rawCfg), file) require.NoError(t, err) } } diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 1c086e0529..15afdea6fb 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -64,7 +64,7 @@ func TestNodeQueryBankBalances(t *testing.T) { aliceAccount, aliceMnemonic, err := ca.Create(alice) require.NoError(t, err) - app.EditConfig(func(c *chainconfig.Config) { + app.EditConfig(func(c *config.Config) { c.Accounts = []base.Account{ { Name: alice, diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 2dddc04c6e..1042134930 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -55,7 +55,7 @@ func TestNodeTxBankSend(t *testing.T) { bobAccount, bobMnemonic, err := ca.Create(bob) require.NoError(t, err) - app.EditConfig(func(c *chainconfig.Config) { + app.EditConfig(func(c *config.Config) { c.Accounts = []base.Account{ { Name: alice, From 83030688e0d5d757534e0740be91578abcd25c77 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:28:10 -0500 Subject: [PATCH 04/80] rename --- ignite/config/{ => chain}/base/base.go | 0 .../network}/testdata/config.yaml | 0 .../network}/testdata/testdata.go | 3 +- ignite/config/{ => chain}/v0/config.go | 2 +- .../config/{ => chain}/v0/config_convert.go | 10 +-- .../{ => chain}/v0/config_convert_test.go | 7 +- ignite/config/{ => chain}/v0/config_test.go | 3 +- .../{ => chain}/v0/testdata/config.yaml | 0 .../{ => chain}/v0/testdata/testdata.go | 3 +- ignite/config/{ => chain}/v1/config.go | 2 +- .../config/{ => chain}/v1/config_convert.go | 4 +- ignite/config/{ => chain}/v1/config_test.go | 78 +++++++++---------- .../{ => chain}/v1/testdata/config.yaml | 0 .../{ => chain}/v1/testdata/config2.yaml | 0 .../{ => chain}/v1/testdata/testdata.go | 3 +- ignite/config/{ => chain}/v1/validator.go | 0 .../{ => chain}/v1/validator_servers.go | 0 .../{ => chain}/v1/validator_servers_test.go | 10 +-- ignite/config/chainconfig.go | 6 +- ignite/config/chainconfig_test.go | 2 +- ignite/config/convert.go | 3 +- ignite/config/convert_test.go | 2 +- ignite/config/errors.go | 3 +- ignite/config/parser.go | 3 +- ignite/config/parser_test.go | 2 +- ignite/config/testdata/testdata.go | 6 +- ignite/services/chain/generate.go | 2 +- integration/app.go | 2 +- 28 files changed, 75 insertions(+), 81 deletions(-) rename ignite/config/{ => chain}/base/base.go (100%) rename ignite/config/{networkconfig => chain/network}/testdata/config.yaml (100%) rename ignite/config/{networkconfig => chain/network}/testdata/testdata.go (88%) rename ignite/config/{ => chain}/v0/config.go (94%) rename ignite/config/{ => chain}/v0/config_convert.go (86%) rename ignite/config/{ => chain}/v0/config_convert_test.go (91%) rename ignite/config/{ => chain}/v0/config_test.go (86%) rename ignite/config/{ => chain}/v0/testdata/config.yaml (100%) rename ignite/config/{ => chain}/v0/testdata/testdata.go (88%) rename ignite/config/{ => chain}/v1/config.go (98%) rename ignite/config/{ => chain}/v1/config_convert.go (79%) rename ignite/config/{ => chain}/v1/config_test.go (68%) rename ignite/config/{ => chain}/v1/testdata/config.yaml (100%) rename ignite/config/{ => chain}/v1/testdata/config2.yaml (100%) rename ignite/config/{ => chain}/v1/testdata/testdata.go (88%) rename ignite/config/{ => chain}/v1/validator.go (100%) rename ignite/config/{ => chain}/v1/validator_servers.go (100%) rename ignite/config/{ => chain}/v1/validator_servers_test.go (91%) diff --git a/ignite/config/base/base.go b/ignite/config/chain/base/base.go similarity index 100% rename from ignite/config/base/base.go rename to ignite/config/chain/base/base.go diff --git a/ignite/config/networkconfig/testdata/config.yaml b/ignite/config/chain/network/testdata/config.yaml similarity index 100% rename from ignite/config/networkconfig/testdata/config.yaml rename to ignite/config/chain/network/testdata/config.yaml diff --git a/ignite/config/networkconfig/testdata/testdata.go b/ignite/config/chain/network/testdata/testdata.go similarity index 88% rename from ignite/config/networkconfig/testdata/testdata.go rename to ignite/config/chain/network/testdata/testdata.go index ba6da10c58..848952b832 100644 --- a/ignite/config/networkconfig/testdata/testdata.go +++ b/ignite/config/chain/network/testdata/testdata.go @@ -3,12 +3,11 @@ package testdata import ( "bytes" _ "embed" + "github.com/ignite/cli/ignite/config/chain/v1" "testing" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - - v1 "github.com/ignite/cli/ignite/config/v1" ) //go:embed config.yaml diff --git a/ignite/config/v0/config.go b/ignite/config/chain/v0/config.go similarity index 94% rename from ignite/config/v0/config.go rename to ignite/config/chain/v0/config.go index a9ec1db08e..49d0458636 100644 --- a/ignite/config/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -1,7 +1,7 @@ package v0 import ( - "github.com/ignite/cli/ignite/config/base" + "github.com/ignite/cli/ignite/config/chain/base" "io" "github.com/imdario/mergo" diff --git a/ignite/config/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go similarity index 86% rename from ignite/config/v0/config_convert.go rename to ignite/config/chain/v0/config_convert.go index a66a3d879a..ff3a9bea4f 100644 --- a/ignite/config/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -1,20 +1,20 @@ package v0 import ( - "github.com/ignite/cli/ignite/config/base" - v1 "github.com/ignite/cli/ignite/config/v1" + "github.com/ignite/cli/ignite/config/chain/base" + v12 "github.com/ignite/cli/ignite/config/chain/v1" ) // ConvertNext converts the current config version to the next one. func (c *Config) ConvertNext() (base.Converter, error) { - targetCfg := v1.DefaultConfig() + targetCfg := v12.DefaultConfig() // All the fields in the base config remain the same targetCfg.BaseConfig = c.BaseConfig targetCfg.Version = 1 // There is always only one validator in version 0 - validator := v1.Validator{} + validator := v12.Validator{} validator.Name = c.Validator.Name validator.Bonded = c.Validator.Staked validator.Home = c.Init.Home @@ -30,7 +30,7 @@ func (c *Config) ConvertNext() (base.Converter, error) { } // The host configuration must be defined in the validators for version 1 - servers := v1.Servers{} + servers := v12.Servers{} if c.Host.P2P != "" { servers.P2P.Address = c.Host.P2P diff --git a/ignite/config/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go similarity index 91% rename from ignite/config/v0/config_convert_test.go rename to ignite/config/chain/v0/config_convert_test.go index 38c16e1f07..17211bcde6 100644 --- a/ignite/config/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -1,13 +1,12 @@ package v0_test import ( + "github.com/ignite/cli/ignite/config/chain/base" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" + "github.com/ignite/cli/ignite/config/chain/v1" "testing" "github.com/stretchr/testify/require" - - "github.com/ignite/cli/ignite/config/base" - v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" - v1 "github.com/ignite/cli/ignite/config/v1" ) func TestV0ToV1(t *testing.T) { diff --git a/ignite/config/v0/config_test.go b/ignite/config/chain/v0/config_test.go similarity index 86% rename from ignite/config/v0/config_test.go rename to ignite/config/chain/v0/config_test.go index 5559cbc717..bf55bf768e 100644 --- a/ignite/config/v0/config_test.go +++ b/ignite/config/chain/v0/config_test.go @@ -1,11 +1,10 @@ package v0_test import ( + "github.com/ignite/cli/ignite/config/chain/v0" "testing" "github.com/stretchr/testify/require" - - v0 "github.com/ignite/cli/ignite/config/v0" ) func TestClone(t *testing.T) { diff --git a/ignite/config/v0/testdata/config.yaml b/ignite/config/chain/v0/testdata/config.yaml similarity index 100% rename from ignite/config/v0/testdata/config.yaml rename to ignite/config/chain/v0/testdata/config.yaml diff --git a/ignite/config/v0/testdata/testdata.go b/ignite/config/chain/v0/testdata/testdata.go similarity index 88% rename from ignite/config/v0/testdata/testdata.go rename to ignite/config/chain/v0/testdata/testdata.go index 20e9b9ef5e..92b28aab08 100644 --- a/ignite/config/v0/testdata/testdata.go +++ b/ignite/config/chain/v0/testdata/testdata.go @@ -3,12 +3,11 @@ package testdata import ( "bytes" _ "embed" + "github.com/ignite/cli/ignite/config/chain/v0" "testing" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - - v0 "github.com/ignite/cli/ignite/config/v0" ) //go:embed config.yaml diff --git a/ignite/config/v1/config.go b/ignite/config/chain/v1/config.go similarity index 98% rename from ignite/config/v1/config.go rename to ignite/config/chain/v1/config.go index 126de4f165..7e8c48514a 100644 --- a/ignite/config/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -1,12 +1,12 @@ package v1 import ( + "github.com/ignite/cli/ignite/config/chain/base" "io" "github.com/imdario/mergo" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config/base" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/config/v1/config_convert.go b/ignite/config/chain/v1/config_convert.go similarity index 79% rename from ignite/config/v1/config_convert.go rename to ignite/config/chain/v1/config_convert.go index 0b3064a068..3f34d21f55 100644 --- a/ignite/config/v1/config_convert.go +++ b/ignite/config/chain/v1/config_convert.go @@ -1,6 +1,8 @@ package v1 -import "github.com/ignite/cli/ignite/config/base" +import ( + "github.com/ignite/cli/ignite/config/chain/base" +) // ConvertNext implements the conversion of the current config to the next version. func (c *Config) ConvertNext() (base.Converter, error) { diff --git a/ignite/config/v1/config_test.go b/ignite/config/chain/v1/config_test.go similarity index 68% rename from ignite/config/v1/config_test.go rename to ignite/config/chain/v1/config_test.go index 01ae454392..a65cc4821f 100644 --- a/ignite/config/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -1,13 +1,13 @@ package v1_test import ( + v12 "github.com/ignite/cli/ignite/config/chain/v1" "os" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v1 "github.com/ignite/cli/ignite/config/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -17,12 +17,12 @@ func TestConfigDecode(t *testing.T) { f, err := os.Open("testdata/config2.yaml") require.NoError(err) defer f.Close() - var cfg v1.Config + var cfg v12.Config err = cfg.Decode(f) require.NoError(err) - expected := v1.Config{ + expected := v12.Config{ BaseConfig: base.BaseConfig{ Version: 1, Build: base.Build{ @@ -61,7 +61,7 @@ func TestConfigDecode(t *testing.T) { "chain_id": "evmosd_9000-1", }, }, - Validators: []v1.Validator{{ + Validators: []v12.Validator{{ Name: "alice", Bonded: "100000000000000000000aevmos", Home: "$HOME/.evmosd", @@ -72,7 +72,7 @@ func TestConfigDecode(t *testing.T) { }, }, }}, - Plugins: []v1.Plugin{ + Plugins: []v12.Plugin{ { Path: "/path/to/plugin1", }, @@ -87,15 +87,15 @@ func TestConfigDecode(t *testing.T) { func TestConfigValidatorDefaultServers(t *testing.T) { // Arrange - c := v1.Config{ - Validators: []v1.Validator{ + c := v12.Config{ + Validators: []v12.Validator{ { Name: "name-1", Bonded: "100ATOM", }, }, } - servers := v1.Servers{} + servers := v12.Servers{} // Act err := c.SetDefaults() @@ -107,20 +107,20 @@ func TestConfigValidatorDefaultServers(t *testing.T) { require.NoError(t, err) // Assert - require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v1.DefaultAPIAddress, servers.API.Address) - require.Equal(t, v1.DefaultRPCAddress, servers.RPC.Address) - require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v12.DefaultAPIAddress, servers.API.Address) + require.Equal(t, v12.DefaultRPCAddress, servers.RPC.Address) + require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorWithExistingServers(t *testing.T) { // Arrange rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v1.Config{ - Validators: []v1.Validator{ + c := v12.Config{ + Validators: []v12.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -135,7 +135,7 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { }, }, } - servers := v1.Servers{} + servers := v12.Servers{} // Act err := c.SetDefaults() @@ -149,10 +149,10 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { // Assert require.Equal(t, rpcAddr, servers.RPC.Address) require.Equal(t, apiAddr, servers.API.Address) - require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorsWithExistingServers(t *testing.T) { @@ -160,8 +160,8 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { inc := uint64(10) rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v1.Config{ - Validators: []v1.Validator{ + c := v12.Config{ + Validators: []v12.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -180,7 +180,7 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { }, }, } - servers := v1.Servers{} + servers := v12.Servers{} // Act err := c.SetDefaults() @@ -196,17 +196,17 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { require.Equal(t, apiAddr, servers.API.Address) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestConfigValidatorsDefaultServers(t *testing.T) { // Arrange inc := uint64(10) - c := v1.Config{ - Validators: []v1.Validator{ + c := v12.Config{ + Validators: []v12.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -217,7 +217,7 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { }, }, } - servers := v1.Servers{} + servers := v12.Servers{} // Act err := c.SetDefaults() @@ -229,18 +229,18 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { require.NoError(t, err) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultAPIAddress, inc), servers.API.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultRPCAddress, inc), servers.RPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultAPIAddress, inc), servers.API.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultRPCAddress, inc), servers.RPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestClone(t *testing.T) { // Arrange - c := &v1.Config{ - Validators: []v1.Validator{ + c := &v12.Config{ + Validators: []v12.Validator{ { Name: "alice", Bonded: "100000000stake", diff --git a/ignite/config/v1/testdata/config.yaml b/ignite/config/chain/v1/testdata/config.yaml similarity index 100% rename from ignite/config/v1/testdata/config.yaml rename to ignite/config/chain/v1/testdata/config.yaml diff --git a/ignite/config/v1/testdata/config2.yaml b/ignite/config/chain/v1/testdata/config2.yaml similarity index 100% rename from ignite/config/v1/testdata/config2.yaml rename to ignite/config/chain/v1/testdata/config2.yaml diff --git a/ignite/config/v1/testdata/testdata.go b/ignite/config/chain/v1/testdata/testdata.go similarity index 88% rename from ignite/config/v1/testdata/testdata.go rename to ignite/config/chain/v1/testdata/testdata.go index ba6da10c58..848952b832 100644 --- a/ignite/config/v1/testdata/testdata.go +++ b/ignite/config/chain/v1/testdata/testdata.go @@ -3,12 +3,11 @@ package testdata import ( "bytes" _ "embed" + "github.com/ignite/cli/ignite/config/chain/v1" "testing" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - - v1 "github.com/ignite/cli/ignite/config/v1" ) //go:embed config.yaml diff --git a/ignite/config/v1/validator.go b/ignite/config/chain/v1/validator.go similarity index 100% rename from ignite/config/v1/validator.go rename to ignite/config/chain/v1/validator.go diff --git a/ignite/config/v1/validator_servers.go b/ignite/config/chain/v1/validator_servers.go similarity index 100% rename from ignite/config/v1/validator_servers.go rename to ignite/config/chain/v1/validator_servers.go diff --git a/ignite/config/v1/validator_servers_test.go b/ignite/config/chain/v1/validator_servers_test.go similarity index 91% rename from ignite/config/v1/validator_servers_test.go rename to ignite/config/chain/v1/validator_servers_test.go index 5ecda3d288..c15123e9a2 100644 --- a/ignite/config/v1/validator_servers_test.go +++ b/ignite/config/chain/v1/validator_servers_test.go @@ -1,17 +1,17 @@ package v1_test import ( + v12 "github.com/ignite/cli/ignite/config/chain/v1" "testing" "github.com/stretchr/testify/require" - v1 "github.com/ignite/cli/ignite/config/v1" xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) func TestValidatorGetServers(t *testing.T) { // Arrange - want := v1.DefaultServers() + want := v12.DefaultServers() want.RPC.Address = "127.0.0.0:1" want.P2P.Address = "127.0.0.0:2" want.GRPC.Address = "127.0.0.0:3" @@ -19,7 +19,7 @@ func TestValidatorGetServers(t *testing.T) { want.RPC.PProfAddress = "127.0.0.0:5" want.API.Address = "127.0.0.0:6" - v := v1.Validator{ + v := v12.Validator{ App: map[string]interface{}{ "grpc": map[string]interface{}{"address": want.GRPC.Address}, "grpc-web": map[string]interface{}{"address": want.GRPCWeb.Address}, @@ -44,8 +44,8 @@ func TestValidatorGetServers(t *testing.T) { func TestValidatorSetServers(t *testing.T) { // Arrange - v := v1.Validator{} - s := v1.DefaultServers() + v := v12.Validator{} + s := v12.DefaultServers() wantApp := xyaml.Map{ "grpc": map[string]interface{}{"address": s.GRPC.Address}, "grpc-web": map[string]interface{}{"address": s.GRPCWeb.Address}, diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index dcde83efb4..9a4b79fdc5 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -10,9 +10,9 @@ import ( "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config/base" - v0 "github.com/ignite/cli/ignite/config/v0" - v1 "github.com/ignite/cli/ignite/config/v1" + "github.com/ignite/cli/ignite/config/chain/base" + "github.com/ignite/cli/ignite/config/chain/v0" + "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" ) diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chainconfig_test.go index 80a451e310..b9572de0de 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -3,12 +3,12 @@ package config_test import ( "bytes" "fmt" + "github.com/ignite/cli/ignite/config/chain/base" "testing" "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/base" ) func TestCheckVersion(t *testing.T) { diff --git a/ignite/config/convert.go b/ignite/config/convert.go index 024dbe3648..0a57b4f524 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -1,11 +1,10 @@ package config import ( + "github.com/ignite/cli/ignite/config/chain/base" "io" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/config/base" ) // Build time check for the latest config version type. diff --git a/ignite/config/convert_test.go b/ignite/config/convert_test.go index 6d46b110bc..f125bc4d78 100644 --- a/ignite/config/convert_test.go +++ b/ignite/config/convert_test.go @@ -2,13 +2,13 @@ package config_test import ( "bytes" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "testing" "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/testdata" - v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" ) func TestConvertLatest(t *testing.T) { diff --git a/ignite/config/errors.go b/ignite/config/errors.go index fdb9d631bd..dd6027d9e4 100644 --- a/ignite/config/errors.go +++ b/ignite/config/errors.go @@ -3,8 +3,7 @@ package config import ( "errors" "fmt" - - "github.com/ignite/cli/ignite/config/base" + "github.com/ignite/cli/ignite/config/chain/base" ) // ErrConfigNotFound indicates that the config.yml can't be found. diff --git a/ignite/config/parser.go b/ignite/config/parser.go index fac2ad2cda..3b0cdf7cd2 100644 --- a/ignite/config/parser.go +++ b/ignite/config/parser.go @@ -3,13 +3,12 @@ package config import ( "bytes" "fmt" + "github.com/ignite/cli/ignite/config/chain/base" "io" "os" "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/config/base" ) // Parse reads a config file. diff --git a/ignite/config/parser_test.go b/ignite/config/parser_test.go index 240d863d3d..bd1c0d74ba 100644 --- a/ignite/config/parser_test.go +++ b/ignite/config/parser_test.go @@ -3,13 +3,13 @@ package config_test import ( "bytes" "fmt" + "github.com/ignite/cli/ignite/config/chain/base" "strings" "testing" "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/base" "github.com/ignite/cli/ignite/config/testdata" ) diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 32199db8ce..1ac75ea2f3 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -1,13 +1,13 @@ package testdata import ( + "github.com/ignite/cli/ignite/config/chain/base" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" + v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" "testing" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/base" networkconfigTestData "github.com/ignite/cli/ignite/config/networkconfig/testdata" - v0testdata "github.com/ignite/cli/ignite/config/v0/testdata" - v1testdata "github.com/ignite/cli/ignite/config/v1/testdata" ) var Versions = map[base.Version][]byte{ diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 516021ce83..386ea21629 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -3,12 +3,12 @@ package chain import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain/base" "os" "path/filepath" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" diff --git a/integration/app.go b/integration/app.go index 13493502e2..449db93276 100644 --- a/integration/app.go +++ b/integration/app.go @@ -2,6 +2,7 @@ package envtest import ( "fmt" + "github.com/ignite/cli/ignite/config/chain/v1" "os" "path" "path/filepath" @@ -12,7 +13,6 @@ import ( "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config" - v1 "github.com/ignite/cli/ignite/config/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gocmd" From 6565fc52cc1faf7a13a4cf4303859fd62043e83d Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:29:23 -0500 Subject: [PATCH 05/80] rename --- ignite/cmd/cmd.go | 2 +- ignite/config/chainconfig.go | 6 +++--- ignite/services/chain/serve.go | 2 +- ignite/services/network/networkchain/binarycache.go | 2 +- ignite/services/plugin/plugin.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 5ac274cd1a..46436146a7 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -295,7 +295,7 @@ func printSection(session *cliui.Session, title string) error { } func newCache(cmd *cobra.Command) (cache.Storage, error) { - cacheRootDir, err := config.ConfigDirPath() + cacheRootDir, err := config.DirPath() if err != nil { return cache.Storage{}, err } diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index 9a4b79fdc5..2c60cc2e95 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -17,8 +17,8 @@ import ( ) var ( - // ConfigDirPath returns the path of configuration directory of Ignite. - ConfigDirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) + // DirPath returns the path of configuration directory of Ignite. + DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) // ConfigFileNames is a list of recognized names as for Ignite's config file. ConfigFileNames = []string{"config.yml", "config.yaml"} @@ -127,7 +127,7 @@ func HooksPath(conf *Config) string { // CreateConfigDir creates config directory if it is not created yet. func CreateConfigDir() error { - path, err := ConfigDirPath() + path, err := DirPath() if err != nil { return err } diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 1f2f25a84e..97a6674e62 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -53,7 +53,7 @@ var ( // starportSavePath is the place where chain exported genesis are saved starportSavePath = xfilepath.Join( - config.ConfigDirPath, + config.DirPath, xfilepath.Path("local-chains"), ) ) diff --git a/ignite/services/network/networkchain/binarycache.go b/ignite/services/network/networkchain/binarycache.go index 1833590421..2df530f8c3 100644 --- a/ignite/services/network/networkchain/binarycache.go +++ b/ignite/services/network/networkchain/binarycache.go @@ -78,7 +78,7 @@ func checkBinaryCacheForLaunchID(launchID uint64, binaryHash, sourceHash string) func getBinaryCacheFilepath() (string, error) { return xfilepath.Join( - config.ConfigDirPath, + config.DirPath, xfilepath.Path(SPNCacheDirectory), xfilepath.Path(BinaryCacheDirectory), xfilepath.Path(BinaryCacheFilename), diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index b3f2eb25b4..3eb090745a 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -31,7 +31,7 @@ import ( // pluginsPath holds the plugin cache directory. var pluginsPath = xfilepath.Join( - config.ConfigDirPath, + config.DirPath, xfilepath.Path("plugins"), ) From 863876f365fc7a56699fab8653d38a06d432c5b2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 20:52:58 -0500 Subject: [PATCH 06/80] fix comment --- ignite/config/chainconfig.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index 2c60cc2e95..d419ab54df 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -20,8 +20,8 @@ var ( // DirPath returns the path of configuration directory of Ignite. DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) - // ConfigFileNames is a list of recognized names as for Ignite's config file. - ConfigFileNames = []string{"config.yml", "config.yaml"} + // ChainConfigFilenames is a list of recognized names as for Ignite's chain config file. + ChainConfigFilenames = []string{"config.yml", "config.yaml"} // DefaultTSClientPath defines the default relative path to use when generating the TS client. // The path is relative to the app's directory. @@ -47,7 +47,7 @@ var ( // The path is relative to the app's directory. DefaultHooksPath = "react/src/hooks" - // DefaultOpenAPIPath defines the default relative path to use when when generating an OpenAPI schema. + // DefaultOpenAPIPath defines the default relative path to use when generating an OpenAPI schema. // The path is relative to the app's directory. DefaultOpenAPIPath = "docs/static/openapi.yml" @@ -138,7 +138,7 @@ func CreateConfigDir() error { // LocateDefault locates the default path for the config file. // Returns ErrConfigNotFound when no config file found. func LocateDefault(root string) (path string, err error) { - for _, name := range ConfigFileNames { + for _, name := range ChainConfigFilenames { path = filepath.Join(root, name) if _, err := os.Stat(path); err == nil { return path, nil From eaccb71fdf5c5c9ef6ed9149398484bf424457b8 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:17:40 -0500 Subject: [PATCH 07/80] rename file --- ignite/cmd/chain.go | 2 +- ignite/config/chainconfig.go | 26 +++++++--------- ignite/config/convert.go | 6 ++-- ignite/config/{parser.go => parse.go} | 30 ++++++++++--------- .../config/{parser_test.go => parse_test.go} | 0 ignite/config/pluginsconfig.go | 6 ++++ ignite/config/testdata/testdata.go | 4 +-- ignite/services/chain/chain.go | 4 +-- ignite/services/chain/generate.go | 2 +- ignite/services/chain/init.go | 4 +-- ignite/services/chain/runtime.go | 10 +++---- ignite/services/chain/serve.go | 2 +- ignite/services/network/networkchain/init.go | 2 +- integration/app.go | 12 ++++---- 14 files changed, 57 insertions(+), 53 deletions(-) rename ignite/config/{parser.go => parse.go} (84%) rename ignite/config/{parser_test.go => parse_test.go} (100%) create mode 100644 ignite/config/pluginsconfig.go diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 582a7d2838..e1114525bf 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -115,7 +115,7 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } - // Config files with older versions must be migrated to the latest before executing the command + // ChainConfig files with older versions must be migrated to the latest before executing the command if version != config.LatestVersion { if !getYes(cmd) { // Confirm before overwritting the config file diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index d419ab54df..c96690b865 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "io" "os" "path/filepath" @@ -20,7 +19,7 @@ var ( // DirPath returns the path of configuration directory of Ignite. DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) - // ChainConfigFilenames is a list of recognized names as for Ignite's chain config file. + // ChainConfigFilenames is a list of recognized names as Ignite's chain config file. ChainConfigFilenames = []string{"config.yml", "config.yaml"} // DefaultTSClientPath defines the default relative path to use when generating the TS client. @@ -61,19 +60,16 @@ var ( } ) -// Config defines the latest config. -type Config = v1.Config - -// Plugin defines the latest plugin config -type Plugin = v1.Plugin +// ChainConfig defines the latest chain config. +type ChainConfig = v1.Config -// DefaultConfig returns a config for the latest version initialized with default values. -func DefaultConfig() *Config { +// DefaultChainConfig returns a config for the latest version initialized with default values. +func DefaultChainConfig() *ChainConfig { return v1.DefaultConfig() } // FaucetHost returns the faucet host to use. -func FaucetHost(cfg *Config) string { +func FaucetHost(cfg *ChainConfig) string { // We keep supporting Port option for backward compatibility // TODO: drop this option in the future host := cfg.Faucet.Host @@ -86,7 +82,7 @@ func FaucetHost(cfg *Config) string { // TSClientPath returns the relative path to the Typescript client directory. // Path is relative to the app's directory. -func TSClientPath(conf Config) string { +func TSClientPath(conf ChainConfig) string { if path := strings.TrimSpace(conf.Client.Typescript.Path); path != "" { return filepath.Clean(path) } @@ -96,7 +92,7 @@ func TSClientPath(conf Config) string { // VuexPath returns the relative path to the Vuex stores directory. // Path is relative to the app's directory. -func VuexPath(conf *Config) string { +func VuexPath(conf *ChainConfig) string { //nolint:staticcheck //ignore SA1019 until vuex config option is removed if path := strings.TrimSpace(conf.Client.Vuex.Path); path != "" { return filepath.Clean(path) @@ -107,7 +103,7 @@ func VuexPath(conf *Config) string { // ComposablesPath returns the relative path to the Vue useQuery composables directory. // Path is relative to the app's directory. -func ComposablesPath(conf *Config) string { +func ComposablesPath(conf *ChainConfig) string { if path := strings.TrimSpace(conf.Client.Composables.Path); path != "" { return filepath.Clean(path) } @@ -117,7 +113,7 @@ func ComposablesPath(conf *Config) string { // HooksPath returns the relative path to the React useQuery hooks directory. // Path is relative to the app's directory. -func HooksPath(conf *Config) string { +func HooksPath(conf *ChainConfig) string { if path := strings.TrimSpace(conf.Client.Hooks.Path); path != "" { return filepath.Clean(path) } @@ -166,7 +162,7 @@ func CheckVersion(configFile io.Reader) error { } // Save saves a config to a YAML file. -func Save(c Config, path string) error { +func Save(c ChainConfig, path string) error { file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0o755) if err != nil { return err diff --git a/ignite/config/convert.go b/ignite/config/convert.go index 0a57b4f524..472fcf147a 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -11,10 +11,10 @@ import ( // This is required to be sure that conversion to latest // doesn't break when a new config version is added without // updating the references to the previous version. -var _ = Versions[LatestVersion].(*Config) +var _ = Versions[LatestVersion].(*ChainConfig) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c base.Converter) (_ *Config, err error) { +func ConvertLatest(c base.Converter) (_ *ChainConfig, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { @@ -25,7 +25,7 @@ func ConvertLatest(c base.Converter) (_ *Config, err error) { // Cast to the latest version type. // This is safe because there is a build time check that makes sure // the type for the latest config version is the right one here. - return c.(*Config), nil + return c.(*ChainConfig), nil } // MigrateLatest migrates a config file to the latest version. diff --git a/ignite/config/parser.go b/ignite/config/parse.go similarity index 84% rename from ignite/config/parser.go rename to ignite/config/parse.go index 3b0cdf7cd2..65de72b982 100644 --- a/ignite/config/parser.go +++ b/ignite/config/parse.go @@ -3,18 +3,20 @@ package config import ( "bytes" "fmt" - "github.com/ignite/cli/ignite/config/chain/base" + "io" "os" "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/config/chain/base" ) // Parse reads a config file. // When the version of the file being read is not the latest // it is automatically migrated to the latest version. -func Parse(configFile io.Reader) (*Config, error) { +func Parse(configFile io.Reader) (*ChainConfig, error) { cfg, err := parse(configFile) if err != nil { return cfg, fmt.Errorf("error parsing config file: %w", err) @@ -26,7 +28,7 @@ func Parse(configFile io.Reader) (*Config, error) { // ParseNetwork reads a config file for Ignite Network genesis. // When the version of the file being read is not the latest // it is automatically migrated to the latest version. -func ParseNetwork(configFile io.Reader) (*Config, error) { +func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { cfg, err := parse(configFile) if err != nil { return cfg, err @@ -35,42 +37,42 @@ func ParseNetwork(configFile io.Reader) (*Config, error) { return cfg, validateNetworkConfig(cfg) } -func parse(configFile io.Reader) (*Config, error) { +func parse(configFile io.Reader) (*ChainConfig, error) { var buf bytes.Buffer // Read the config file version first to know how to decode it version, err := ReadConfigVersion(io.TeeReader(configFile, &buf)) if err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } // Decode the current config file version and assign default // values for the fields that are empty c, err := decodeConfig(&buf, version) if err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } // Make sure that the empty fields contain default values // after reading the config from the YAML file if err = c.SetDefaults(); err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } // Finally make sure the config is the latest one before validating it cfg, err := ConvertLatest(c) if err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } return cfg, nil } // ParseFile parses a config from a file path. -func ParseFile(path string) (*Config, error) { +func ParseFile(path string) (*ChainConfig, error) { file, err := os.Open(path) if err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } defer file.Close() @@ -79,10 +81,10 @@ func ParseFile(path string) (*Config, error) { } // ParseNetworkFile parses a config for Ignite Network genesis from a file path. -func ParseNetworkFile(path string) (*Config, error) { +func ParseNetworkFile(path string) (*ChainConfig, error) { file, err := os.Open(path) if err != nil { - return DefaultConfig(), err + return DefaultChainConfig(), err } defer file.Close() @@ -119,7 +121,7 @@ func decodeConfig(r io.Reader, version base.Version) (base.Converter, error) { return cfg, nil } -func validateConfig(c *Config) error { +func validateConfig(c *ChainConfig) error { if len(c.Accounts) == 0 { return &ValidationError{"at least one account is required"} } @@ -141,7 +143,7 @@ func validateConfig(c *Config) error { return nil } -func validateNetworkConfig(c *Config) error { +func validateNetworkConfig(c *ChainConfig) error { if len(c.Validators) != 0 { return &ValidationError{"no validators can be used in config for network genesis"} } diff --git a/ignite/config/parser_test.go b/ignite/config/parse_test.go similarity index 100% rename from ignite/config/parser_test.go rename to ignite/config/parse_test.go diff --git a/ignite/config/pluginsconfig.go b/ignite/config/pluginsconfig.go new file mode 100644 index 0000000000..6c651e2f59 --- /dev/null +++ b/ignite/config/pluginsconfig.go @@ -0,0 +1,6 @@ +package config + +import v1 "github.com/ignite/cli/ignite/config/chain/v1" + +// Plugin defines the latest plugin config +type Plugin = v1.Plugin diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 1ac75ea2f3..b80e75be87 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -17,10 +17,10 @@ var Versions = map[base.Version][]byte{ var NetworkConfig = networkconfigTestData.ConfigYAML -func GetLatestConfig(t *testing.T) *config.Config { +func GetLatestConfig(t *testing.T) *config.ChainConfig { return v1testdata.GetConfig(t) } -func GetLatestNetworkConfig(t *testing.T) *config.Config { +func GetLatestNetworkConfig(t *testing.T) *config.ChainConfig { return networkconfigTestData.GetConfig(t) } diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 46ebe9cfeb..60b11bf790 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -211,10 +211,10 @@ func (c *Chain) ConfigPath() string { } // Config returns the config of the chain -func (c *Chain) Config() (*config.Config, error) { +func (c *Chain) Config() (*config.ChainConfig, error) { configPath := c.ConfigPath() if configPath == "" { - return config.DefaultConfig(), nil + return config.DefaultChainConfig(), nil } return config.ParseFile(configPath) } diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 386ea21629..cb10353bbe 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -348,7 +348,7 @@ func (c Chain) saveClientConfig(client base.Client) error { // values that otherwise would be initialized to defaults. // Defaults must be ignored to avoid writing them to the // YAML config file when they are not present. - var cfg config.Config + var cfg config.ChainConfig if err := cfg.Decode(file); err != nil { return err } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index fa3268cd44..6bb050beb7 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -86,7 +86,7 @@ func (c *Chain) InitChain(ctx context.Context) error { } // InitAccounts initializes the chain accounts and creates validator gentxs -func (c *Chain) InitAccounts(ctx context.Context, cfg *config.Config) error { +func (c *Chain) InitAccounts(ctx context.Context, cfg *config.ChainConfig) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -222,7 +222,7 @@ type Account struct { Coins string } -func createValidatorFromConfig(conf *config.Config) (validator Validator) { +func createValidatorFromConfig(conf *config.ChainConfig) (validator Validator) { // Currently, we support the config file with one valid validator. validatorFromConfig := conf.Validators[0] validator.Name = validatorFromConfig.Name diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index f4e27c9dc7..96dc6cc325 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -36,7 +36,7 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida } // Start wraps the "appd start" command to begin running a chain from the daemon -func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *config.Config) error { +func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *config.ChainConfig) error { validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { @@ -49,7 +49,7 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *con } // Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml) -func (c Chain) Configure(homePath string, cfg *config.Config) error { +func (c Chain) Configure(homePath string, cfg *config.ChainConfig) error { if err := c.appTOML(homePath, cfg); err != nil { return err } @@ -59,7 +59,7 @@ func (c Chain) Configure(homePath string, cfg *config.Config) error { return c.configTOML(homePath, cfg) } -func (c Chain) appTOML(homePath string, cfg *config.Config) error { +func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") config, err := toml.LoadFile(path) @@ -106,7 +106,7 @@ func (c Chain) appTOML(homePath string, cfg *config.Config) error { return err } -func (c Chain) configTOML(homePath string, cfg *config.Config) error { +func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") config, err := toml.LoadFile(path) @@ -153,7 +153,7 @@ func (c Chain) configTOML(homePath string, cfg *config.Config) error { return err } -func (c Chain) clientTOML(homePath string, cfg *config.Config) error { +func (c Chain) clientTOML(homePath string, cfg *config.ChainConfig) error { path := filepath.Join(homePath, "config/client.toml") config, err := toml.LoadFile(path) if os.IsNotExist(err) { diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 97a6674e62..138a2970ec 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -427,7 +427,7 @@ func (c *Chain) serve( return c.start(ctx, conf) } -func (c *Chain) start(ctx context.Context, cfg *config.Config) error { +func (c *Chain) start(ctx context.Context, cfg *config.ChainConfig) error { commands, err := c.Commands(ctx) if err != nil { return err diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index 8c3098d0c2..761e2ad63a 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -105,7 +105,7 @@ func (c *Chain) initGenesis(ctx context.Context) error { return err } case c.genesisConfig != "": - c.ev.Send("Fetching custom Genesis from Config", events.ProgressUpdate()) + c.ev.Send("Fetching custom Genesis from ChainConfig", events.ProgressUpdate()) // first, initialize with default genesis cmd, err := c.chain.Commands(ctx) diff --git a/integration/app.go b/integration/app.go index 449db93276..8b91d9277c 100644 --- a/integration/app.go +++ b/integration/app.go @@ -187,7 +187,7 @@ func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string) { port, err := availableport.Find(1) require.NoError(a.env.t, err) - a.EditConfig(func(c *config.Config) { + a.EditConfig(func(c *config.ChainConfig) { c.Faucet.Port = port[0] c.Faucet.Coins = coins c.Faucet.CoinsMax = coinsMax @@ -219,7 +219,7 @@ func (a App) RandomizeServerPorts() Hosts { API: genAddr(ports[5]), } - a.EditConfig(func(c *config.Config) { + a.EditConfig(func(c *config.ChainConfig) { v := &c.Validators[0] s := v1.Servers{} @@ -241,24 +241,24 @@ func (a App) RandomizeServerPorts() Hosts { func (a App) UseRandomHomeDir() (homeDirPath string) { dir := a.env.TmpDir() - a.EditConfig(func(c *config.Config) { + a.EditConfig(func(c *config.ChainConfig) { c.Validators[0].Home = dir }) return dir } -func (a App) Config() config.Config { +func (a App) Config() config.ChainConfig { bz, err := os.ReadFile(a.configPath) require.NoError(a.env.t, err) - var conf config.Config + var conf config.ChainConfig err = yaml.Unmarshal(bz, &conf) require.NoError(a.env.t, err) return conf } -func (a App) EditConfig(apply func(*config.Config)) { +func (a App) EditConfig(apply func(*config.ChainConfig)) { conf := a.Config() apply(&conf) From c490fa5b9941d62619f625ac97c0690938de3bc2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:23:29 -0500 Subject: [PATCH 08/80] format --- ignite/config/chain/network/testdata/testdata.go | 3 ++- ignite/config/chain/v0/config.go | 3 ++- ignite/config/chain/v0/config_convert_test.go | 5 +++-- ignite/config/chain/v0/config_test.go | 3 ++- ignite/config/chain/v0/testdata/testdata.go | 3 ++- ignite/config/chain/v1/config.go | 2 +- ignite/config/chain/v1/config_test.go | 4 +++- ignite/config/chain/v1/testdata/testdata.go | 3 ++- ignite/config/chain/v1/validator_servers_test.go | 3 ++- ignite/config/chainconfig.go | 4 ++-- ignite/config/chainconfig_test.go | 3 ++- ignite/config/convert.go | 3 ++- ignite/config/convert_test.go | 3 ++- ignite/config/errors.go | 1 + ignite/config/parse.go | 1 - ignite/config/parse_test.go | 3 ++- ignite/config/testdata/testdata.go | 12 ++++++------ ignite/services/chain/chain.go | 1 - ignite/services/chain/generate.go | 4 ++-- ignite/services/plugin/plugin_test.go | 2 +- integration/app.go | 3 ++- integration/chain/config_test.go | 2 +- integration/cosmosgen/bank_module_test.go | 3 ++- integration/cosmosgen/custom_module_test.go | 3 ++- integration/network/network_test.go | 2 +- integration/node/cmd_query_bank_test.go | 3 ++- integration/node/cmd_tx_bank_send_test.go | 3 ++- 27 files changed, 51 insertions(+), 34 deletions(-) diff --git a/ignite/config/chain/network/testdata/testdata.go b/ignite/config/chain/network/testdata/testdata.go index 848952b832..a1f57a13d6 100644 --- a/ignite/config/chain/network/testdata/testdata.go +++ b/ignite/config/chain/network/testdata/testdata.go @@ -3,9 +3,10 @@ package testdata import ( "bytes" _ "embed" - "github.com/ignite/cli/ignite/config/chain/v1" "testing" + v1 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" ) diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index 49d0458636..fbf514325b 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -1,9 +1,10 @@ package v0 import ( - "github.com/ignite/cli/ignite/config/chain/base" "io" + "github.com/ignite/cli/ignite/config/chain/base" + "github.com/imdario/mergo" "gopkg.in/yaml.v2" ) diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 17211bcde6..c953d7882f 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -1,10 +1,11 @@ package v0_test import ( + "testing" + "github.com/ignite/cli/ignite/config/chain/base" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" - "github.com/ignite/cli/ignite/config/chain/v1" - "testing" + v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/stretchr/testify/require" ) diff --git a/ignite/config/chain/v0/config_test.go b/ignite/config/chain/v0/config_test.go index bf55bf768e..6c56b94ffc 100644 --- a/ignite/config/chain/v0/config_test.go +++ b/ignite/config/chain/v0/config_test.go @@ -1,9 +1,10 @@ package v0_test import ( - "github.com/ignite/cli/ignite/config/chain/v0" "testing" + v0 "github.com/ignite/cli/ignite/config/chain/v0" + "github.com/stretchr/testify/require" ) diff --git a/ignite/config/chain/v0/testdata/testdata.go b/ignite/config/chain/v0/testdata/testdata.go index 92b28aab08..7fa7fb2fb8 100644 --- a/ignite/config/chain/v0/testdata/testdata.go +++ b/ignite/config/chain/v0/testdata/testdata.go @@ -3,9 +3,10 @@ package testdata import ( "bytes" _ "embed" - "github.com/ignite/cli/ignite/config/chain/v0" "testing" + v0 "github.com/ignite/cli/ignite/config/chain/v0" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" ) diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 7e8c48514a..264da546b4 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -1,12 +1,12 @@ package v1 import ( - "github.com/ignite/cli/ignite/config/chain/base" "io" "github.com/imdario/mergo" "gopkg.in/yaml.v2" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index a65cc4821f..71618d5ba8 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -1,10 +1,12 @@ package v1_test import ( - v12 "github.com/ignite/cli/ignite/config/chain/v1" "os" "testing" + "github.com/ignite/cli/ignite/config/chain/base" + v12 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/ignite/config/chain/v1/testdata/testdata.go b/ignite/config/chain/v1/testdata/testdata.go index 848952b832..a1f57a13d6 100644 --- a/ignite/config/chain/v1/testdata/testdata.go +++ b/ignite/config/chain/v1/testdata/testdata.go @@ -3,9 +3,10 @@ package testdata import ( "bytes" _ "embed" - "github.com/ignite/cli/ignite/config/chain/v1" "testing" + v1 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" ) diff --git a/ignite/config/chain/v1/validator_servers_test.go b/ignite/config/chain/v1/validator_servers_test.go index c15123e9a2..ad04101f0f 100644 --- a/ignite/config/chain/v1/validator_servers_test.go +++ b/ignite/config/chain/v1/validator_servers_test.go @@ -1,9 +1,10 @@ package v1_test import ( - v12 "github.com/ignite/cli/ignite/config/chain/v1" "testing" + v12 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/stretchr/testify/require" xyaml "github.com/ignite/cli/ignite/pkg/yaml" diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index c96690b865..22c6a0d68c 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -10,8 +10,8 @@ import ( "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config/chain/base" - "github.com/ignite/cli/ignite/config/chain/v0" - "github.com/ignite/cli/ignite/config/chain/v1" + v0 "github.com/ignite/cli/ignite/config/chain/v0" + v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" ) diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chainconfig_test.go index b9572de0de..bda1bfa2f1 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -3,9 +3,10 @@ package config_test import ( "bytes" "fmt" - "github.com/ignite/cli/ignite/config/chain/base" "testing" + "github.com/ignite/cli/ignite/config/chain/base" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" diff --git a/ignite/config/convert.go b/ignite/config/convert.go index 472fcf147a..52e0678bcb 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -1,9 +1,10 @@ package config import ( - "github.com/ignite/cli/ignite/config/chain/base" "io" + "github.com/ignite/cli/ignite/config/chain/base" + "gopkg.in/yaml.v2" ) diff --git a/ignite/config/convert_test.go b/ignite/config/convert_test.go index f125bc4d78..8ae981d5df 100644 --- a/ignite/config/convert_test.go +++ b/ignite/config/convert_test.go @@ -2,9 +2,10 @@ package config_test import ( "bytes" - v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "testing" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" diff --git a/ignite/config/errors.go b/ignite/config/errors.go index dd6027d9e4..8dfde6e557 100644 --- a/ignite/config/errors.go +++ b/ignite/config/errors.go @@ -3,6 +3,7 @@ package config import ( "errors" "fmt" + "github.com/ignite/cli/ignite/config/chain/base" ) diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 65de72b982..9a1697eedd 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -3,7 +3,6 @@ package config import ( "bytes" "fmt" - "io" "os" diff --git a/ignite/config/parse_test.go b/ignite/config/parse_test.go index bd1c0d74ba..0f86f3d859 100644 --- a/ignite/config/parse_test.go +++ b/ignite/config/parse_test.go @@ -3,10 +3,11 @@ package config_test import ( "bytes" "fmt" - "github.com/ignite/cli/ignite/config/chain/base" "strings" "testing" + "github.com/ignite/cli/ignite/config/chain/base" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index b80e75be87..8698cdcd1b 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -1,13 +1,13 @@ package testdata import ( - "github.com/ignite/cli/ignite/config/chain/base" - v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" - v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" "testing" "github.com/ignite/cli/ignite/config" - networkconfigTestData "github.com/ignite/cli/ignite/config/networkconfig/testdata" + "github.com/ignite/cli/ignite/config/chain/base" + networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" + v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" ) var Versions = map[base.Version][]byte{ @@ -15,12 +15,12 @@ var Versions = map[base.Version][]byte{ 1: v1testdata.ConfigYAML, } -var NetworkConfig = networkconfigTestData.ConfigYAML +var NetworkConfig = networkconfigTestdata.ConfigYAML func GetLatestConfig(t *testing.T) *config.ChainConfig { return v1testdata.GetConfig(t) } func GetLatestNetworkConfig(t *testing.T) *config.ChainConfig { - return networkconfigTestData.GetConfig(t) + return networkconfigTestdata.GetConfig(t) } diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 60b11bf790..b2710fce10 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -2,7 +2,6 @@ package chain import ( "context" - "os" "path/filepath" diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index cb10353bbe..f5050ed55a 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -3,11 +3,11 @@ package chain import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain/base" - "os" "path/filepath" + "github.com/ignite/cli/ignite/config/chain/base" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 6e3b4857d4..64d5c12b0f 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/gomodule" ) diff --git a/integration/app.go b/integration/app.go index 8b91d9277c..8cc9628e33 100644 --- a/integration/app.go +++ b/integration/app.go @@ -2,13 +2,14 @@ package envtest import ( "fmt" - "github.com/ignite/cli/ignite/config/chain/v1" "os" "path" "path/filepath" "strconv" "time" + v1 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index 8cb447a3aa..4a5467abf4 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/stretchr/testify/require" + "honnef.co/go/tools/config" - "github.com/ignite/cli/ignite/chainconfig" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/randstr" envtest "github.com/ignite/cli/integration" diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 6b7de60bca..2418b00ef2 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/stretchr/testify/require" + "honnef.co/go/tools/config" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" ) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 2db079c645..398f705963 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/stretchr/testify/require" + "honnef.co/go/tools/config" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 85eb87f93c..46b165adfc 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -14,7 +14,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gomodule" envtest "github.com/ignite/cli/integration" diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 15afdea6fb..4937a992d4 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -11,8 +11,9 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "honnef.co/go/tools/config" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 1042134930..bacea44ee3 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -10,8 +10,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/stretchr/testify/require" + "honnef.co/go/tools/config" - "github.com/ignite/cli/ignite/chainconfig" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" "github.com/ignite/cli/ignite/pkg/cosmosclient" From 844c83b9738603cbaee408bce8f8cb6e8775f177 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:24:21 -0500 Subject: [PATCH 09/80] refactor base --- ignite/config/chain/base/base.go | 16 ++++++++-------- ignite/config/chain/v0/config.go | 2 +- ignite/config/chain/v0/config_convert.go | 2 +- ignite/config/chain/v1/config.go | 6 +++--- ignite/config/chain/v1/config_test.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ignite/config/chain/base/base.go b/ignite/config/chain/base/base.go index b950a0b10e..d4519621e4 100644 --- a/ignite/config/chain/base/base.go +++ b/ignite/config/chain/base/base.go @@ -164,8 +164,8 @@ type Host struct { API string `yaml:"api"` } -// BaseConfig defines a struct with the fields that are common to all config versions. -type BaseConfig struct { +// Config defines a struct with the fields that are common to all config versions. +type Config struct { Version Version `yaml:"version"` Build Build `yaml:"build,omitempty"` Accounts []Account `yaml:"accounts"` @@ -175,22 +175,22 @@ type BaseConfig struct { } // GetVersion returns the config version. -func (c BaseConfig) GetVersion() Version { +func (c Config) GetVersion() Version { return c.Version } // SetDefaults assigns default values to empty config fields. -func (c *BaseConfig) SetDefaults() error { - if err := mergo.Merge(c, DefaultBaseConfig()); err != nil { +func (c *Config) SetDefaults() error { + if err := mergo.Merge(c, DefaulConfig()); err != nil { return err } return nil } -// DefaultBaseConfig returns a base config with default values. -func DefaultBaseConfig() BaseConfig { - return BaseConfig{ +// DefaulConfig returns a base config with default values. +func DefaulConfig() Config { + return Config{ Build: Build{ Proto: Proto{ Path: "proto", diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index fbf514325b..dd8d1861e5 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -11,7 +11,7 @@ import ( // Config is the user given configuration to do additional setup during serve. type Config struct { - base.BaseConfig `yaml:",inline"` + base.Config `yaml:",inline"` Validator Validator `yaml:"validator"` Init base.Init `yaml:"init"` diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index ff3a9bea4f..e901eb93a2 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -10,7 +10,7 @@ func (c *Config) ConvertNext() (base.Converter, error) { targetCfg := v12.DefaultConfig() // All the fields in the base config remain the same - targetCfg.BaseConfig = c.BaseConfig + targetCfg.Config = c.Config targetCfg.Version = 1 // There is always only one validator in version 0 diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 264da546b4..07aeb023f4 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -12,14 +12,14 @@ import ( // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{BaseConfig: base.DefaultBaseConfig()} + c := Config{Config: base.DefaultBaseConfig()} c.Version = 1 return &c } // Config is the user given configuration to do additional setup during serve. type Config struct { - base.BaseConfig `yaml:",inline"` + base.Config `yaml:",inline"` Validators []Validator `yaml:"validators"` Plugins []Plugin `yaml:"plugins,omitempty"` @@ -49,7 +49,7 @@ type Plugin struct { } func (c *Config) SetDefaults() error { - if err := c.BaseConfig.SetDefaults(); err != nil { + if err := c.Config.SetDefaults(); err != nil { return err } diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index 71618d5ba8..c3c6db9ae3 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -25,7 +25,7 @@ func TestConfigDecode(t *testing.T) { require.NoError(err) expected := v12.Config{ - BaseConfig: base.BaseConfig{ + Config: base.Config{ Version: 1, Build: base.Build{ Binary: "evmosd", From 82e9ac047bb2b5caa746f44adf725b60078a0aba Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:25:03 -0500 Subject: [PATCH 10/80] format --- ignite/config/chain/v1/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 07aeb023f4..6711af8013 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -12,7 +12,7 @@ import ( // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{Config: base.DefaultBaseConfig()} + c := Config{Config: base.DefaulConfig()} c.Version = 1 return &c } From a8592a53d905797603450e0201dacfca341c9848 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:33:57 -0500 Subject: [PATCH 11/80] refactor some imports --- ignite/config/chain/network/testdata/testdata.go | 4 ++-- ignite/config/chain/v0/config.go | 4 ++-- ignite/config/chain/v0/config_convert.go | 8 ++++---- ignite/config/chain/v0/config_convert_test.go | 4 ++-- ignite/config/chain/v0/config_test.go | 4 ++-- ignite/config/chain/v1/config_test.go | 5 ++--- ignite/config/chain/v1/testdata/testdata.go | 4 ++-- ignite/config/chain/v1/validator_servers_test.go | 11 +++++------ 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/ignite/config/chain/network/testdata/testdata.go b/ignite/config/chain/network/testdata/testdata.go index a1f57a13d6..e8d3c186c2 100644 --- a/ignite/config/chain/network/testdata/testdata.go +++ b/ignite/config/chain/network/testdata/testdata.go @@ -5,10 +5,10 @@ import ( _ "embed" "testing" - v1 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + + v1 "github.com/ignite/cli/ignite/config/chain/v1" ) //go:embed config.yaml diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index dd8d1861e5..5619491ad5 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -3,10 +3,10 @@ package v0 import ( "io" - "github.com/ignite/cli/ignite/config/chain/base" - "github.com/imdario/mergo" "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/config/chain/base" ) // Config is the user given configuration to do additional setup during serve. diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index e901eb93a2..224dcc4be0 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -2,19 +2,19 @@ package v0 import ( "github.com/ignite/cli/ignite/config/chain/base" - v12 "github.com/ignite/cli/ignite/config/chain/v1" + v1 "github.com/ignite/cli/ignite/config/chain/v1" ) // ConvertNext converts the current config version to the next one. func (c *Config) ConvertNext() (base.Converter, error) { - targetCfg := v12.DefaultConfig() + targetCfg := v1.DefaultConfig() // All the fields in the base config remain the same targetCfg.Config = c.Config targetCfg.Version = 1 // There is always only one validator in version 0 - validator := v12.Validator{} + validator := v1.Validator{} validator.Name = c.Validator.Name validator.Bonded = c.Validator.Staked validator.Home = c.Init.Home @@ -30,7 +30,7 @@ func (c *Config) ConvertNext() (base.Converter, error) { } // The host configuration must be defined in the validators for version 1 - servers := v12.Servers{} + servers := v1.Servers{} if c.Host.P2P != "" { servers.P2P.Address = c.Host.P2P diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index c953d7882f..391d9a9e36 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -3,11 +3,11 @@ package v0_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/ignite/cli/ignite/config/chain/base" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" - - "github.com/stretchr/testify/require" ) func TestV0ToV1(t *testing.T) { diff --git a/ignite/config/chain/v0/config_test.go b/ignite/config/chain/v0/config_test.go index 6c56b94ffc..b043994841 100644 --- a/ignite/config/chain/v0/config_test.go +++ b/ignite/config/chain/v0/config_test.go @@ -3,9 +3,9 @@ package v0_test import ( "testing" - v0 "github.com/ignite/cli/ignite/config/chain/v0" - "github.com/stretchr/testify/require" + + v0 "github.com/ignite/cli/ignite/config/chain/v0" ) func TestClone(t *testing.T) { diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index c3c6db9ae3..b070c2bafc 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -4,12 +4,11 @@ import ( "os" "testing" - "github.com/ignite/cli/ignite/config/chain/base" - v12 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/ignite/cli/ignite/config/chain/base" + v12 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/config/chain/v1/testdata/testdata.go b/ignite/config/chain/v1/testdata/testdata.go index a1f57a13d6..e8d3c186c2 100644 --- a/ignite/config/chain/v1/testdata/testdata.go +++ b/ignite/config/chain/v1/testdata/testdata.go @@ -5,10 +5,10 @@ import ( _ "embed" "testing" - v1 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + + v1 "github.com/ignite/cli/ignite/config/chain/v1" ) //go:embed config.yaml diff --git a/ignite/config/chain/v1/validator_servers_test.go b/ignite/config/chain/v1/validator_servers_test.go index ad04101f0f..ac49b00622 100644 --- a/ignite/config/chain/v1/validator_servers_test.go +++ b/ignite/config/chain/v1/validator_servers_test.go @@ -3,16 +3,15 @@ package v1_test import ( "testing" - v12 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/stretchr/testify/require" + v1 "github.com/ignite/cli/ignite/config/chain/v1" xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) func TestValidatorGetServers(t *testing.T) { // Arrange - want := v12.DefaultServers() + want := v1.DefaultServers() want.RPC.Address = "127.0.0.0:1" want.P2P.Address = "127.0.0.0:2" want.GRPC.Address = "127.0.0.0:3" @@ -20,7 +19,7 @@ func TestValidatorGetServers(t *testing.T) { want.RPC.PProfAddress = "127.0.0.0:5" want.API.Address = "127.0.0.0:6" - v := v12.Validator{ + v := v1.Validator{ App: map[string]interface{}{ "grpc": map[string]interface{}{"address": want.GRPC.Address}, "grpc-web": map[string]interface{}{"address": want.GRPCWeb.Address}, @@ -45,8 +44,8 @@ func TestValidatorGetServers(t *testing.T) { func TestValidatorSetServers(t *testing.T) { // Arrange - v := v12.Validator{} - s := v12.DefaultServers() + v := v1.Validator{} + s := v1.DefaultServers() wantApp := xyaml.Map{ "grpc": map[string]interface{}{"address": s.GRPC.Address}, "grpc-web": map[string]interface{}{"address": s.GRPCWeb.Address}, From 1d5bd3e0c8e886fa362daf84fdf37c12e9c4fd9a Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:44:02 -0500 Subject: [PATCH 12/80] imports refactor --- ignite/config/chain/v0/testdata/testdata.go | 4 ++-- ignite/config/chainconfig_test.go | 3 +-- ignite/config/convert.go | 4 ++-- ignite/config/convert_test.go | 3 +-- ignite/config/parse_test.go | 3 +-- ignite/services/chain/generate.go | 3 +-- integration/app.go | 3 +-- integration/chain/config_test.go | 4 ++-- integration/cosmosgen/bank_module_test.go | 4 ++-- integration/node/cmd_query_bank_test.go | 4 ++-- integration/node/cmd_tx_bank_send_test.go | 4 ++-- 11 files changed, 17 insertions(+), 22 deletions(-) diff --git a/ignite/config/chain/v0/testdata/testdata.go b/ignite/config/chain/v0/testdata/testdata.go index 7fa7fb2fb8..9854d79da0 100644 --- a/ignite/config/chain/v0/testdata/testdata.go +++ b/ignite/config/chain/v0/testdata/testdata.go @@ -5,10 +5,10 @@ import ( _ "embed" "testing" - v0 "github.com/ignite/cli/ignite/config/chain/v0" - "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + + v0 "github.com/ignite/cli/ignite/config/chain/v0" ) //go:embed config.yaml diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chainconfig_test.go index bda1bfa2f1..23d40c38d5 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -5,11 +5,10 @@ import ( "fmt" "testing" - "github.com/ignite/cli/ignite/config/chain/base" - "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" ) func TestCheckVersion(t *testing.T) { diff --git a/ignite/config/convert.go b/ignite/config/convert.go index 52e0678bcb..3f37850577 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -3,9 +3,9 @@ package config import ( "io" - "github.com/ignite/cli/ignite/config/chain/base" - "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/config/chain/base" ) // Build time check for the latest config version type. diff --git a/ignite/config/convert_test.go b/ignite/config/convert_test.go index 8ae981d5df..c2905264f0 100644 --- a/ignite/config/convert_test.go +++ b/ignite/config/convert_test.go @@ -4,11 +4,10 @@ import ( "bytes" "testing" - v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" - "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "github.com/ignite/cli/ignite/config/testdata" ) diff --git a/ignite/config/parse_test.go b/ignite/config/parse_test.go index 0f86f3d859..2c6d1a9720 100644 --- a/ignite/config/parse_test.go +++ b/ignite/config/parse_test.go @@ -6,11 +6,10 @@ import ( "strings" "testing" - "github.com/ignite/cli/ignite/config/chain/base" - "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/config/testdata" ) diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index f5050ed55a..21a23b31ad 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -6,9 +6,8 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/config/chain/base" - "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" diff --git a/integration/app.go b/integration/app.go index 8cc9628e33..430b2efa1d 100644 --- a/integration/app.go +++ b/integration/app.go @@ -8,12 +8,11 @@ import ( "strconv" "time" - v1 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config" + v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gocmd" diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index 4a5467abf4..482ab25164 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "honnef.co/go/tools/config" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/randstr" envtest "github.com/ignite/cli/integration" @@ -26,7 +26,7 @@ func TestOverwriteSDKConfigsAndChainID(t *testing.T) { isBackendAliveErr error ) - var cfg config.Config + var cfg config.ChainConfig cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml")) require.NoError(t, cf.Load(&cfg)) diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 2418b00ef2..ae3bf25068 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "honnef.co/go/tools/config" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -58,7 +58,7 @@ func TestBankModule(t *testing.T) { }, } - app.EditConfig(func(cfg *config.Config) { + app.EditConfig(func(cfg *config.ChainConfig) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 4937a992d4..4a4a1a1f76 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -11,8 +11,8 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "honnef.co/go/tools/config" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -65,7 +65,7 @@ func TestNodeQueryBankBalances(t *testing.T) { aliceAccount, aliceMnemonic, err := ca.Create(alice) require.NoError(t, err) - app.EditConfig(func(c *config.Config) { + app.EditConfig(func(c *config.ChainConfig) { c.Accounts = []base.Account{ { Name: alice, diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index bacea44ee3..9c742a7e4b 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/stretchr/testify/require" - "honnef.co/go/tools/config" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -56,7 +56,7 @@ func TestNodeTxBankSend(t *testing.T) { bobAccount, bobMnemonic, err := ca.Create(bob) require.NoError(t, err) - app.EditConfig(func(c *config.Config) { + app.EditConfig(func(c *config.ChainConfig) { c.Accounts = []base.Account{ { Name: alice, From 15e543a00bdc0fd8b77e3edf4595679138ea8c23 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:52:38 -0500 Subject: [PATCH 13/80] fix --- integration/cosmosgen/custom_module_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 398f705963..224db462e1 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" + "testing" "github.com/stretchr/testify/require" - "honnef.co/go/tools/config" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" @@ -41,7 +42,7 @@ func TestCustomModule(t *testing.T) { }, } - app.EditConfig(func(cfg *config.Config) { + app.EditConfig(func(cfg *config.ChainConfig) { cfg.Accounts = append(cfg.Accounts, accounts...) }) From 2cf58e4bc4a3f0ade5999a9a7e229265da4d9a35 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 21:53:49 -0500 Subject: [PATCH 14/80] fix import --- integration/cosmosgen/custom_module_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 224db462e1..7cf75ab308 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "testing" "github.com/stretchr/testify/require" From 5f8c837f7fd2e6ea924cae6bd44546794c137b03 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 22:41:26 -0500 Subject: [PATCH 15/80] refactor: --- ignite/cmd/cmd.go | 13 ++++ ignite/cmd/plugin.go | 18 ++++- ignite/cmd/plugin_test.go | 2 +- ignite/config/chain/v0/config.go | 6 +- ignite/config/chain/v1/config.go | 30 +------- ignite/config/chain/v1/config_test.go | 85 ++++++++++------------ ignite/config/parse.go | 37 ++++++++-- ignite/config/plugins/config.go | 56 ++++++++++++++ ignite/config/plugins/config_test.go | 35 +++++++++ ignite/config/plugins/testdata/plugins.yml | 8 ++ ignite/config/pluginsconfig.go | 6 -- ignite/services/plugin/plugin.go | 18 ++--- ignite/services/plugin/plugin_test.go | 2 +- 13 files changed, 209 insertions(+), 107 deletions(-) create mode 100644 ignite/config/plugins/config.go create mode 100644 ignite/config/plugins/config_test.go create mode 100644 ignite/config/plugins/testdata/plugins.yml delete mode 100644 ignite/config/pluginsconfig.go diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 46436146a7..f9701bba94 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -33,6 +33,7 @@ const ( flagYes = "yes" flagClearCache = "clear-cache" flagSkipProto = "skip-proto" + flagPlugins = "plugins" checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -81,6 +82,7 @@ To get started, create a blockchain: c.AddCommand(NewVersion()) c.AddCommand(NewPlugin()) c.AddCommand(deprecated()...) + c.PersistentFlags().AddFlagSet(flagSetPlugins()) return c } @@ -130,6 +132,17 @@ func getConfig(cmd *cobra.Command) (config string) { return } +func flagSetPlugins() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.StringP(flagPlugins, "x", "", "Ignite plugins file (default: ./plugins.yml)") + return fs +} + +func getPlugins(cmd *cobra.Command) (config string) { + config, _ = cmd.Flags().GetString(flagPlugins) + return +} + func flagSetYes() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) fs.BoolP(flagYes, "y", false, "answers interactive yes/no questions with yes") diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 6dc6017499..da71b8fe28 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -7,9 +7,12 @@ import ( "strings" "time" + "github.com/ignite/cli/ignite/config" + "github.com/pkg/errors" "github.com/spf13/cobra" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/xgit" "github.com/ignite/cli/ignite/services/plugin" @@ -27,18 +30,27 @@ const ( // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { // NOTE(tb) Not sure if it's the right place to load this. - chain, err := newChainWithHomeFlags(rootCmd) + cfg, err := parseLocalPlugins(rootCmd) if err != nil { - // Binary is run outside of an chain app, plugins can't be loaded + // if binary is run where there is no plugin.yml, don't load return nil } - plugins, err = plugin.Load(ctx, chain) + + // TODO: parse global config + + plugins, err = plugin.Load(ctx, cfg) if err != nil { return err } return loadPlugins(rootCmd, plugins) } +func parseLocalPlugins(rootCmd *cobra.Command) (*pluginsconfig.Config, error) { + pluginsPath := getPlugins(rootCmd) + + return config.ParsePluginsFile(pluginsPath) +} + func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { // Link plugins to related commands var loadErrors []string diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index 1c2c96ca89..d07a9516dd 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" + config "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/services/plugin" "github.com/ignite/cli/ignite/services/plugin/mocks" ) diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index 5619491ad5..7e5b96c1c3 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -30,11 +30,7 @@ func (c *Config) Clone() (base.Converter, error) { // Decode decodes the config file values from YAML. func (c *Config) Decode(r io.Reader) error { - if err := yaml.NewDecoder(r).Decode(c); err != nil { - return err - } - - return nil + return yaml.NewDecoder(r).Decode(c) } // Validator holds info related to validator settings. diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 6711af8013..fef0ca0fd1 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -22,30 +22,6 @@ type Config struct { base.Config `yaml:",inline"` Validators []Validator `yaml:"validators"` - Plugins []Plugin `yaml:"plugins,omitempty"` -} - -// Plugin keeps plugin name and location. -type Plugin struct { - // Path holds the location of the plugin. - // A path can be local, in that case it must start with a `/`. - // A remote path on the other hand, is an URL to a public remote git - // repository. For example: - // - // path: github.com/foo/bar - // - // It can contain a path inside that repository, if for instance the repo - // contains multiple plugins, For example: - // - // path: github.com/foo/bar/plugin1 - // - // It can also specify a tag or a branch, by adding a `@` and the branch/tag - // name at the end of the path. For example: - // - // path: github.com/foo/bar/plugin1@v42 - Path string `yaml:"path"` - // With holds arguments passed to the plugin interface - With map[string]string `yaml:"with"` } func (c *Config) SetDefaults() error { @@ -73,11 +49,7 @@ func (c *Config) Clone() (base.Converter, error) { // Decode decodes the config file values from YAML. func (c *Config) Decode(r io.Reader) error { - if err := yaml.NewDecoder(r).Decode(c); err != nil { - return err - } - - return nil + return yaml.NewDecoder(r).Decode(c) } func (c *Config) updateValidatorAddresses() (err error) { diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index b070c2bafc..8427e3641b 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config/chain/base" - v12 "github.com/ignite/cli/ignite/config/chain/v1" + v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -18,12 +18,12 @@ func TestConfigDecode(t *testing.T) { f, err := os.Open("testdata/config2.yaml") require.NoError(err) defer f.Close() - var cfg v12.Config + var cfg v1.Config err = cfg.Decode(f) require.NoError(err) - expected := v12.Config{ + expected := v1.Config{ Config: base.Config{ Version: 1, Build: base.Build{ @@ -62,7 +62,7 @@ func TestConfigDecode(t *testing.T) { "chain_id": "evmosd_9000-1", }, }, - Validators: []v12.Validator{{ + Validators: []v1.Validator{{ Name: "alice", Bonded: "100000000000000000000aevmos", Home: "$HOME/.evmosd", @@ -73,30 +73,21 @@ func TestConfigDecode(t *testing.T) { }, }, }}, - Plugins: []v12.Plugin{ - { - Path: "/path/to/plugin1", - }, - { - Path: "/path/to/plugin2", - With: map[string]string{"foo": "bar", "bar": "baz"}, - }, - }, } assert.Equal(expected, cfg) } func TestConfigValidatorDefaultServers(t *testing.T) { // Arrange - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -108,20 +99,20 @@ func TestConfigValidatorDefaultServers(t *testing.T) { require.NoError(t, err) // Assert - require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v12.DefaultAPIAddress, servers.API.Address) - require.Equal(t, v12.DefaultRPCAddress, servers.RPC.Address) - require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v1.DefaultAPIAddress, servers.API.Address) + require.Equal(t, v1.DefaultRPCAddress, servers.RPC.Address) + require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorWithExistingServers(t *testing.T) { // Arrange rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -136,7 +127,7 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -150,10 +141,10 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { // Assert require.Equal(t, rpcAddr, servers.RPC.Address) require.Equal(t, apiAddr, servers.API.Address) - require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorsWithExistingServers(t *testing.T) { @@ -161,8 +152,8 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { inc := uint64(10) rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -181,7 +172,7 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -197,17 +188,17 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { require.Equal(t, apiAddr, servers.API.Address) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestConfigValidatorsDefaultServers(t *testing.T) { // Arrange inc := uint64(10) - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -218,7 +209,7 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -230,18 +221,18 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { require.NoError(t, err) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultAPIAddress, inc), servers.API.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultRPCAddress, inc), servers.RPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultAPIAddress, inc), servers.API.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultRPCAddress, inc), servers.RPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestClone(t *testing.T) { // Arrange - c := &v12.Config{ - Validators: []v12.Validator{ + c := &v1.Config{ + Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 9a1697eedd..e6740d9575 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -6,6 +6,8 @@ import ( "io" "os" + "github.com/ignite/cli/ignite/config/plugins" + "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" @@ -16,7 +18,7 @@ import ( // When the version of the file being read is not the latest // it is automatically migrated to the latest version. func Parse(configFile io.Reader) (*ChainConfig, error) { - cfg, err := parse(configFile) + cfg, err := parseChainConfig(configFile) if err != nil { return cfg, fmt.Errorf("error parsing config file: %w", err) } @@ -28,7 +30,7 @@ func Parse(configFile io.Reader) (*ChainConfig, error) { // When the version of the file being read is not the latest // it is automatically migrated to the latest version. func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { - cfg, err := parse(configFile) + cfg, err := parseChainConfig(configFile) if err != nil { return cfg, err } @@ -36,7 +38,12 @@ func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { return cfg, validateNetworkConfig(cfg) } -func parse(configFile io.Reader) (*ChainConfig, error) { +// ParsePlugins reads a config file for ignite binary plugins +func ParsePlugins(configFile io.Reader) (*plugins.Config, error) { + return parsePluginsConfig(configFile) +} + +func parseChainConfig(configFile io.Reader) (*ChainConfig, error) { var buf bytes.Buffer // Read the config file version first to know how to decode it @@ -47,7 +54,7 @@ func parse(configFile io.Reader) (*ChainConfig, error) { // Decode the current config file version and assign default // values for the fields that are empty - c, err := decodeConfig(&buf, version) + c, err := decodeChainConfig(&buf, version) if err != nil { return DefaultChainConfig(), err } @@ -67,6 +74,14 @@ func parse(configFile io.Reader) (*ChainConfig, error) { return cfg, nil } +func parsePluginsConfig(configFile io.Reader) (*plugins.Config, error) { + var c plugins.Config + + err := yaml.NewDecoder(configFile).Decode(&c) + + return &c, err +} + // ParseFile parses a config from a file path. func ParseFile(path string) (*ChainConfig, error) { file, err := os.Open(path) @@ -91,6 +106,18 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { return ParseNetwork(file) } +// ParsePluginsFile parses a plugins config. +func ParsePluginsFile(path string) (*plugins.Config, error) { + file, err := os.Open(path) + if err != nil { + return plugins.DefaultConfig(), err + } + + defer file.Close() + + return ParsePlugins(file) +} + // ReadConfigVersion reads the config version. func ReadConfigVersion(configFile io.Reader) (base.Version, error) { c := struct { @@ -102,7 +129,7 @@ func ReadConfigVersion(configFile io.Reader) (base.Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version base.Version) (base.Converter, error) { +func decodeChainConfig(r io.Reader, version base.Version) (base.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go new file mode 100644 index 0000000000..ff0f21ab4d --- /dev/null +++ b/ignite/config/plugins/config.go @@ -0,0 +1,56 @@ +package plugins + +import ( + "io" + + "github.com/imdario/mergo" + "gopkg.in/yaml.v2" +) + +// DefaultConfig returns a config with default values. +func DefaultConfig() *Config { + c := Config{} + return &c +} + +type Config struct { + Plugins []Plugin `yaml:"plugins,omitempty"` +} + +// Plugin keeps plugin name and location. +type Plugin struct { + // Path holds the location of the plugin. + // A path can be local, in that case it must start with a `/`. + // A remote path on the other hand, is an URL to a public remote git + // repository. For example: + // + // path: github.com/foo/bar + // + // It can contain a path inside that repository, if for instance the repo + // contains multiple plugins, For example: + // + // path: github.com/foo/bar/plugin1 + // + // It can also specify a tag or a branch, by adding a `@` and the branch/tag + // name at the end of the path. For example: + // + // path: github.com/foo/bar/plugin1@v42 + Path string `yaml:"path"` + // With holds arguments passed to the plugin interface + With map[string]string `yaml:"with"` +} + +// Clone returns an identical copy of the instance +func (c *Config) Clone() (*Config, error) { + copy := Config{} + if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { + return nil, err + } + + return ©, nil +} + +// Decode decodes the config file values from YAML. +func (c *Config) Decode(r io.Reader) error { + return yaml.NewDecoder(r).Decode(c) +} diff --git a/ignite/config/plugins/config_test.go b/ignite/config/plugins/config_test.go new file mode 100644 index 0000000000..3d5548aba1 --- /dev/null +++ b/ignite/config/plugins/config_test.go @@ -0,0 +1,35 @@ +package plugins_test + +import ( + "os" + "testing" + + "github.com/ignite/cli/ignite/config/plugins" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestConfigDecode(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + f, err := os.Open("testdata/plugins.yml") + require.NoError(err) + defer f.Close() + var cfg plugins.Config + + err = cfg.Decode(f) + + require.NoError(err) + expected := plugins.Config{ + Plugins: []plugins.Plugin{ + { + Path: "/path/to/plugin1", + }, + { + Path: "/path/to/plugin2", + With: map[string]string{"foo": "bar", "bar": "baz"}, + }, + }, + } + assert.Equal(expected, cfg) +} diff --git a/ignite/config/plugins/testdata/plugins.yml b/ignite/config/plugins/testdata/plugins.yml new file mode 100644 index 0000000000..9e268110e2 --- /dev/null +++ b/ignite/config/plugins/testdata/plugins.yml @@ -0,0 +1,8 @@ +plugins: + - name: plugin1 + path: /path/to/plugin1 + - name: plugin2 + path: /path/to/plugin2 + with: + foo: bar + bar: baz diff --git a/ignite/config/pluginsconfig.go b/ignite/config/pluginsconfig.go deleted file mode 100644 index 6c651e2f59..0000000000 --- a/ignite/config/pluginsconfig.go +++ /dev/null @@ -1,6 +0,0 @@ -package config - -import v1 "github.com/ignite/cli/ignite/config/chain/v1" - -// Plugin defines the latest plugin config -type Plugin = v1.Plugin diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 3eb090745a..fad7ae44ac 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -1,5 +1,5 @@ // Package plugin implements ignite plugin management. -// A ignite plugin is a binary which communicates with the ignite binary +// An ignite plugin is a binary which communicates with the ignite binary // via RPC thanks to the github.com/hashicorp/go-plugin library. package plugin @@ -21,12 +21,12 @@ import ( "github.com/pkg/errors" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" cliexec "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/xfilepath" - "github.com/ignite/cli/ignite/services/chain" ) // pluginsPath holds the plugin cache directory. @@ -38,7 +38,7 @@ var pluginsPath = xfilepath.Join( // Plugin represents a ignite plugin. type Plugin struct { // Embed the plugin configuration - config.Plugin + plugins.Plugin // Interface allows to communicate with the plugin via net/rpc. Interface Interface // If any error occurred during the plugin load, it's stored here @@ -66,19 +66,17 @@ type Plugin struct { // If an error occurs during a plugin load, it's not returned but rather stored // in the Plugin.Error field. This prevents the loading of other plugins to be // interrupted. -func Load(ctx context.Context, c *chain.Chain) ([]*Plugin, error) { - conf, err := c.Config() - if err != nil { - return nil, errors.WithStack(err) - } +func Load(ctx context.Context, cfg *plugins.Config) ([]*Plugin, error) { pluginsDir, err := pluginsPath() if err != nil { return nil, errors.WithStack(err) } var plugins []*Plugin - for _, cp := range conf.Plugins { + for _, cp := range cfg.Plugins { p := newPlugin(pluginsDir, cp) p.load(ctx) + + // TODO: override global plugins with locally defined ones plugins = append(plugins, p) } return plugins, nil @@ -97,7 +95,7 @@ func Update(plugins ...*Plugin) error { } // newPlugin creates a Plugin from configuration. -func newPlugin(pluginsDir string, cp config.Plugin) *Plugin { +func newPlugin(pluginsDir string, cp plugins.Plugin) *Plugin { var ( p = &Plugin{Plugin: cp} pluginPath = cp.Path diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 64d5c12b0f..ddd3d56257 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" + config "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/gomodule" ) From 1459f1c3b9ad6e3eee0178e06e96b5215cb26054 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 22:51:34 -0500 Subject: [PATCH 16/80] changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6c71a83674..67cd7f9598 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ ## Unreleased ### Features - +- [#3184](https://github.com/ignite/cli/pull/3184) Separate `plugins.yml` config file. - [#3038](https://github.com/ignite/cli/pull/3038) Addition of Plugin Hooks in Plugin System - [#3056](https://github.com/ignite/cli/pull/3056) Add `--genesis-config` flag option to `ignite network chain publish` - [#2892](https://github.com/ignite/cli/pull/2982/) Add `ignite scaffold react` command. From ea5434a0b6f8b0fd98b7993817e361c4b48cca35 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 27 Nov 2022 22:56:52 -0500 Subject: [PATCH 17/80] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 67cd7f9598..84d71c37dd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ ## Unreleased ### Features + - [#3184](https://github.com/ignite/cli/pull/3184) Separate `plugins.yml` config file. - [#3038](https://github.com/ignite/cli/pull/3038) Addition of Plugin Hooks in Plugin System - [#3056](https://github.com/ignite/cli/pull/3056) Add `--genesis-config` flag option to `ignite network chain publish` From 1a3167e636ebd41b068c78dfbb2d97767e6ea815 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Mon, 28 Nov 2022 08:16:18 -0500 Subject: [PATCH 18/80] Update ignite/services/network/networkchain/init.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jerónimo Albi --- ignite/services/network/networkchain/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index 761e2ad63a..eceecd2bad 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -105,7 +105,7 @@ func (c *Chain) initGenesis(ctx context.Context) error { return err } case c.genesisConfig != "": - c.ev.Send("Fetching custom Genesis from ChainConfig", events.ProgressUpdate()) + c.ev.Send("Fetching custom genesis from chain config", events.ProgressUpdate()) // first, initialize with default genesis cmd, err := c.chain.Commands(ctx) From 0ad9f3dbb2e49bf24c2b39b6ad29cb6292c1626f Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:20:15 -0500 Subject: [PATCH 19/80] base -> baseconfig --- ignite/config/chain/{base => baseconfig}/base.go | 2 +- ignite/config/chain/v0/config.go | 12 +++++------- ignite/config/chain/v0/config_convert.go | 3 +-- ignite/config/chain/v0/config_convert_test.go | 3 +-- ignite/config/chain/v1/config.go | 7 +++---- ignite/config/chain/v1/config_convert.go | 6 +----- ignite/config/chain/v1/config_test.go | 11 +++++------ ignite/config/chainconfig.go | 5 ++--- ignite/config/chainconfig_test.go | 3 +-- ignite/config/convert.go | 4 +--- ignite/config/errors.go | 6 ++---- ignite/config/parse.go | 8 +++----- ignite/config/parse_test.go | 5 ++--- ignite/config/testdata/testdata.go | 3 +-- ignite/services/chain/generate.go | 3 +-- integration/cosmosgen/bank_module_test.go | 3 +-- integration/cosmosgen/custom_module_test.go | 3 +-- integration/node/cmd_query_bank_test.go | 5 ++--- integration/node/cmd_tx_bank_send_test.go | 5 ++--- 19 files changed, 36 insertions(+), 61 deletions(-) rename ignite/config/chain/{base => baseconfig}/base.go (99%) diff --git a/ignite/config/chain/base/base.go b/ignite/config/chain/baseconfig/base.go similarity index 99% rename from ignite/config/chain/base/base.go rename to ignite/config/chain/baseconfig/base.go index d4519621e4..be78357ebd 100644 --- a/ignite/config/chain/base/base.go +++ b/ignite/config/chain/baseconfig/base.go @@ -1,4 +1,4 @@ -package base +package baseconfig import ( "fmt" diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index 5619491ad5..cdfcc6f566 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -5,21 +5,19 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/config/chain/base" ) // Config is the user given configuration to do additional setup during serve. type Config struct { - base.Config `yaml:",inline"` + baseconfig.Config `yaml:",inline"` - Validator Validator `yaml:"validator"` - Init base.Init `yaml:"init"` - Host base.Host `yaml:"host"` + Validator Validator `yaml:"validator"` + Init baseconfig.Init `yaml:"init"` + Host baseconfig.Host `yaml:"host"` } // Clone returns an identical copy of the instance. -func (c *Config) Clone() (base.Converter, error) { +func (c *Config) Clone() (baseconfig.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index 224dcc4be0..e5efd213b3 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -1,12 +1,11 @@ package v0 import ( - "github.com/ignite/cli/ignite/config/chain/base" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) // ConvertNext converts the current config version to the next one. -func (c *Config) ConvertNext() (base.Converter, error) { +func (c *Config) ConvertNext() (baseconfig.Converter, error) { targetCfg := v1.DefaultConfig() // All the fields in the base config remain the same diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 391d9a9e36..7744580b46 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config/chain/base" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) @@ -21,7 +20,7 @@ func TestV0ToV1(t *testing.T) { // Assert require.NoError(t, err) require.NotNilf(t, cfgV1, "expected *v1.Config, got %T", c) - require.Equal(t, base.Version(1), cfgV1.GetVersion()) + require.Equal(t, baseconfig.Version(1), cfgV1.GetVersion()) require.Equal(t, cfgV0.Build, cfgV1.Build) require.Equal(t, cfgV0.Accounts, cfgV1.Accounts) require.Equal(t, cfgV0.Faucet, cfgV1.Faucet) diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 6711af8013..2cc72424cb 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -6,20 +6,19 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{Config: base.DefaulConfig()} + c := Config{Config: baseconfig.DefaulConfig()} c.Version = 1 return &c } // Config is the user given configuration to do additional setup during serve. type Config struct { - base.Config `yaml:",inline"` + baseconfig.Config `yaml:",inline"` Validators []Validator `yaml:"validators"` Plugins []Plugin `yaml:"plugins,omitempty"` @@ -62,7 +61,7 @@ func (c *Config) SetDefaults() error { } // Clone returns an identical copy of the instance -func (c *Config) Clone() (base.Converter, error) { +func (c *Config) Clone() (baseconfig.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/config/chain/v1/config_convert.go b/ignite/config/chain/v1/config_convert.go index 3f34d21f55..faa56e1d2d 100644 --- a/ignite/config/chain/v1/config_convert.go +++ b/ignite/config/chain/v1/config_convert.go @@ -1,11 +1,7 @@ package v1 -import ( - "github.com/ignite/cli/ignite/config/chain/base" -) - // ConvertNext implements the conversion of the current config to the next version. -func (c *Config) ConvertNext() (base.Converter, error) { +func (c *Config) ConvertNext() (baseconfig.Converter, error) { // v1 is the latest version, there is no need to convert. return c, nil } diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index b070c2bafc..ac7cdc773a 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config/chain/base" v12 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -24,16 +23,16 @@ func TestConfigDecode(t *testing.T) { require.NoError(err) expected := v12.Config{ - Config: base.Config{ + Config: baseconfig.Config{ Version: 1, - Build: base.Build{ + Build: baseconfig.Build{ Binary: "evmosd", - Proto: base.Proto{ + Proto: baseconfig.Proto{ Path: "proto", ThirdPartyPaths: []string{"third_party/proto", "proto_vendor"}, }, }, - Accounts: []base.Account{ + Accounts: []baseconfig.Account{ { Name: "alice", Coins: []string{"100000000uatom", "100000000000000000000aevmos"}, @@ -45,7 +44,7 @@ func TestConfigDecode(t *testing.T) { Address: "cosmos1adn9gxjmrc3hrsdx5zpc9sj2ra7kgqkmphf8yw", }, }, - Faucet: base.Faucet{ + Faucet: baseconfig.Faucet{ Name: &[]string{"bob"}[0], Coins: []string{"10aevmos"}, Host: "0.0.0.0:4600", diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index 22c6a0d68c..dc72a70547 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -9,7 +9,6 @@ import ( "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config/chain/base" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -51,10 +50,10 @@ var ( DefaultOpenAPIPath = "docs/static/openapi.yml" // LatestVersion defines the latest version of the config. - LatestVersion base.Version = 1 + LatestVersion baseconfig.Version = 1 // Versions holds config types for the supported versions. - Versions = map[base.Version]base.Converter{ + Versions = map[baseconfig.Version]baseconfig.Converter{ 0: &v0.Config{}, 1: &v1.Config{}, } diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chainconfig_test.go index 23d40c38d5..3ca2dcf954 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" ) func TestCheckVersion(t *testing.T) { @@ -34,5 +33,5 @@ func TestCheckVersionWithOutdatedVersion(t *testing.T) { // Assert require.ErrorAs(t, err, &wantError) - require.Equal(t, wantError.Version, base.Version(0)) + require.Equal(t, wantError.Version, baseconfig.Version(0)) } diff --git a/ignite/config/convert.go b/ignite/config/convert.go index 3f37850577..c8fd9fcbfe 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -4,8 +4,6 @@ import ( "io" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/config/chain/base" ) // Build time check for the latest config version type. @@ -15,7 +13,7 @@ import ( var _ = Versions[LatestVersion].(*ChainConfig) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c base.Converter) (_ *ChainConfig, err error) { +func ConvertLatest(c baseconfig.Converter) (_ *ChainConfig, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { diff --git a/ignite/config/errors.go b/ignite/config/errors.go index 8dfde6e557..74270a8e9f 100644 --- a/ignite/config/errors.go +++ b/ignite/config/errors.go @@ -3,8 +3,6 @@ package config import ( "errors" "fmt" - - "github.com/ignite/cli/ignite/config/chain/base" ) // ErrConfigNotFound indicates that the config.yml can't be found. @@ -21,7 +19,7 @@ func (e ValidationError) Error() string { // UnsupportedVersionError is returned when the version of the config is not supported. type UnsupportedVersionError struct { - Version base.Version + Version baseconfig.Version } func (e UnsupportedVersionError) Error() string { @@ -30,7 +28,7 @@ func (e UnsupportedVersionError) Error() string { // VersionError is returned when config version doesn't match with the version CLI supports. type VersionError struct { - Version base.Version + Version baseconfig.Version } func (e VersionError) Error() string { diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 9a1697eedd..94948f5b59 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -8,8 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" - - "github.com/ignite/cli/ignite/config/chain/base" ) // Parse reads a config file. @@ -92,9 +90,9 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { } // ReadConfigVersion reads the config version. -func ReadConfigVersion(configFile io.Reader) (base.Version, error) { +func ReadConfigVersion(configFile io.Reader) (baseconfig.Version, error) { c := struct { - Version base.Version `yaml:"version"` + Version baseconfig.Version `yaml:"version"` }{} err := yaml.NewDecoder(configFile).Decode(&c) @@ -102,7 +100,7 @@ func ReadConfigVersion(configFile io.Reader) (base.Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version base.Version) (base.Converter, error) { +func decodeConfig(r io.Reader, version baseconfig.Version) (baseconfig.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} diff --git a/ignite/config/parse_test.go b/ignite/config/parse_test.go index 2c6d1a9720..2d1b2f3694 100644 --- a/ignite/config/parse_test.go +++ b/ignite/config/parse_test.go @@ -9,14 +9,13 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/config/testdata" ) func TestReadConfigVersion(t *testing.T) { // Arrange r := strings.NewReader("version: 42") - want := base.Version(42) + want := baseconfig.Version(42) // Act version, err := config.ReadConfigVersion(r) @@ -57,7 +56,7 @@ func TestParseWithCurrentVersion(t *testing.T) { func TestParseWithUnknownVersion(t *testing.T) { // Arrange - version := base.Version(9999) + version := baseconfig.Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) var want *config.UnsupportedVersionError diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 8698cdcd1b..6246e77c74 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -4,13 +4,12 @@ import ( "testing" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" ) -var Versions = map[base.Version][]byte{ +var Versions = map[baseconfig.Version][]byte{ 0: v0testdata.ConfigYAML, 1: v1testdata.ConfigYAML, } diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 21a23b31ad..2a77596be2 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -7,7 +7,6 @@ import ( "path/filepath" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -334,7 +333,7 @@ func (c Chain) joinGeneratedPath(rootPath string) string { return filepath.Join(c.app.Path, rootPath, "generated") } -func (c Chain) saveClientConfig(client base.Client) error { +func (c Chain) saveClientConfig(client baseconfig.Client) error { path := c.ConfigPath() file, err := os.Open(path) if err != nil { diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index ae3bf25068..bcd3fc670b 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" ) @@ -28,7 +27,7 @@ func TestBankModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []base.Account{ + accounts := []baseconfig.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 7cf75ab308..37c0dfbbb5 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -29,7 +28,7 @@ func TestCustomModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []base.Account{ + accounts := []baseconfig.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 4a4a1a1f76..c67a814603 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -66,14 +65,14 @@ func TestNodeQueryBankBalances(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *config.ChainConfig) { - c.Accounts = []base.Account{ + c.Accounts = []baseconfig.Account{ { Name: alice, Mnemonic: aliceMnemonic, Coins: []string{"5600atoken", "1200btoken", "100000000stake"}, }, } - c.Faucet = base.Faucet{} + c.Faucet = baseconfig.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 9c742a7e4b..fa93156f71 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" - "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" "github.com/ignite/cli/ignite/pkg/cosmosclient" @@ -57,7 +56,7 @@ func TestNodeTxBankSend(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *config.ChainConfig) { - c.Accounts = []base.Account{ + c.Accounts = []baseconfig.Account{ { Name: alice, Mnemonic: aliceMnemonic, @@ -69,7 +68,7 @@ func TestNodeTxBankSend(t *testing.T) { Coins: []string{"10000token", "100000000stake"}, }, } - c.Faucet = base.Faucet{} + c.Faucet = baseconfig.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) env.Must(env.Exec("import alice", From 360bc17d3aa74645f195a97e87837e510e88de45 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:39:32 -0500 Subject: [PATCH 20/80] refactoring for clarity --- .../{baseconfig/base.go => base/config.go} | 45 ++++--------------- ignite/config/chain/chain.go | 31 +++++++++++++ ignite/config/chain/v0/config.go | 19 ++++---- ignite/config/chain/v0/config_convert.go | 3 +- ignite/config/chain/v1/config.go | 14 +++--- ignite/config/chain/v1/config_convert.go | 4 +- ignite/config/chainconfig.go | 5 ++- ignite/config/convert.go | 4 +- ignite/config/errors.go | 6 ++- ignite/config/parse.go | 8 ++-- ignite/services/chain/generate.go | 3 +- 11 files changed, 77 insertions(+), 65 deletions(-) rename ignite/config/chain/{baseconfig/base.go => base/config.go} (81%) create mode 100644 ignite/config/chain/chain.go diff --git a/ignite/config/chain/baseconfig/base.go b/ignite/config/chain/base/config.go similarity index 81% rename from ignite/config/chain/baseconfig/base.go rename to ignite/config/chain/base/config.go index be78357ebd..dcee2f8918 100644 --- a/ignite/config/chain/baseconfig/base.go +++ b/ignite/config/chain/base/config.go @@ -1,39 +1,12 @@ -package baseconfig +package base import ( - "fmt" - "io" - "github.com/imdario/mergo" + "github.com/ignite/cli/ignite/config/chain" xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) -// Version defines the type for the config version number. -type Version uint - -func (v Version) String() string { - return fmt.Sprintf("v%d", v) -} - -// Converter defines the interface required to migrate configurations to newer versions. -type Converter interface { - // Clone clones the config by returning a new copy of the current one. - Clone() (Converter, error) - - // SetDefaults assigns default values to empty config fields. - SetDefaults() error - - // GetVersion returns the config version. - GetVersion() Version - - // ConvertNext converts the config to the next version. - ConvertNext() (Converter, error) - - // Decode decodes the config file from YAML and updates it's values. - Decode(io.Reader) error -} - // Account holds the options related to setting up Cosmos wallets. type Account struct { Name string `yaml:"name"` @@ -166,16 +139,16 @@ type Host struct { // Config defines a struct with the fields that are common to all config versions. type Config struct { - Version Version `yaml:"version"` - Build Build `yaml:"build,omitempty"` - Accounts []Account `yaml:"accounts"` - Faucet Faucet `yaml:"faucet,omitempty"` - Client Client `yaml:"client,omitempty"` - Genesis xyaml.Map `yaml:"genesis,omitempty"` + Version chain.Version `yaml:"version"` + Build Build `yaml:"build,omitempty"` + Accounts []Account `yaml:"accounts"` + Faucet Faucet `yaml:"faucet,omitempty"` + Client Client `yaml:"client,omitempty"` + Genesis xyaml.Map `yaml:"genesis,omitempty"` } // GetVersion returns the config version. -func (c Config) GetVersion() Version { +func (c Config) GetVersion() chain.Version { return c.Version } diff --git a/ignite/config/chain/chain.go b/ignite/config/chain/chain.go new file mode 100644 index 0000000000..594406dff1 --- /dev/null +++ b/ignite/config/chain/chain.go @@ -0,0 +1,31 @@ +package chain + +import ( + "fmt" + "io" +) + +// Version defines the type for the config version number. +type Version uint + +func (v Version) String() string { + return fmt.Sprintf("v%d", v) +} + +// Converter defines the interface required to migrate configurations to newer versions. +type Converter interface { + // Clone clones the config by returning a new copy of the current one. + Clone() (Converter, error) + + // SetDefaults assigns default values to empty config fields. + SetDefaults() error + + // GetVersion returns the config version. + GetVersion() Version + + // ConvertNext converts the config to the next version. + ConvertNext() (Converter, error) + + // Decode decodes the config file from YAML and updates its values. + Decode(io.Reader) error +} diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index cdfcc6f566..250740a3ec 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -5,19 +5,22 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" + + chainconfig "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/base" ) // Config is the user given configuration to do additional setup during serve. type Config struct { - baseconfig.Config `yaml:",inline"` + base.Config `yaml:",inline"` - Validator Validator `yaml:"validator"` - Init baseconfig.Init `yaml:"init"` - Host baseconfig.Host `yaml:"host"` + Validator Validator `yaml:"validator"` + Init base.Init `yaml:"init"` + Host base.Host `yaml:"host"` } // Clone returns an identical copy of the instance. -func (c *Config) Clone() (baseconfig.Converter, error) { +func (c *Config) Clone() (chainconfig.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err @@ -28,11 +31,7 @@ func (c *Config) Clone() (baseconfig.Converter, error) { // Decode decodes the config file values from YAML. func (c *Config) Decode(r io.Reader) error { - if err := yaml.NewDecoder(r).Decode(c); err != nil { - return err - } - - return nil + return yaml.NewDecoder(r).Decode(c) } // Validator holds info related to validator settings. diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index e5efd213b3..5a251947d4 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -1,11 +1,12 @@ package v0 import ( + chainconfig "github.com/ignite/cli/ignite/config/chain" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) // ConvertNext converts the current config version to the next one. -func (c *Config) ConvertNext() (baseconfig.Converter, error) { +func (c *Config) ConvertNext() (chainconfig.Converter, error) { targetCfg := v1.DefaultConfig() // All the fields in the base config remain the same diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 2cc72424cb..b123f51f0a 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -6,19 +6,21 @@ import ( "github.com/imdario/mergo" "gopkg.in/yaml.v2" + chainconfig "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{Config: baseconfig.DefaulConfig()} + c := Config{Config: base.DefaulConfig()} c.Version = 1 return &c } // Config is the user given configuration to do additional setup during serve. type Config struct { - baseconfig.Config `yaml:",inline"` + base.Config `yaml:",inline"` Validators []Validator `yaml:"validators"` Plugins []Plugin `yaml:"plugins,omitempty"` @@ -61,7 +63,7 @@ func (c *Config) SetDefaults() error { } // Clone returns an identical copy of the instance -func (c *Config) Clone() (baseconfig.Converter, error) { +func (c *Config) Clone() (chainconfig.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err @@ -72,11 +74,7 @@ func (c *Config) Clone() (baseconfig.Converter, error) { // Decode decodes the config file values from YAML. func (c *Config) Decode(r io.Reader) error { - if err := yaml.NewDecoder(r).Decode(c); err != nil { - return err - } - - return nil + return yaml.NewDecoder(r).Decode(c) } func (c *Config) updateValidatorAddresses() (err error) { diff --git a/ignite/config/chain/v1/config_convert.go b/ignite/config/chain/v1/config_convert.go index faa56e1d2d..2f345533aa 100644 --- a/ignite/config/chain/v1/config_convert.go +++ b/ignite/config/chain/v1/config_convert.go @@ -1,7 +1,9 @@ package v1 +import chainconfig "github.com/ignite/cli/ignite/config/chain" + // ConvertNext implements the conversion of the current config to the next version. -func (c *Config) ConvertNext() (baseconfig.Converter, error) { +func (c *Config) ConvertNext() (chainconfig.Converter, error) { // v1 is the latest version, there is no need to convert. return c, nil } diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index dc72a70547..87820e2685 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -9,6 +9,7 @@ import ( "gopkg.in/yaml.v2" + chainconfig "github.com/ignite/cli/ignite/config/chain" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -50,10 +51,10 @@ var ( DefaultOpenAPIPath = "docs/static/openapi.yml" // LatestVersion defines the latest version of the config. - LatestVersion baseconfig.Version = 1 + LatestVersion chainconfig.Version = 1 // Versions holds config types for the supported versions. - Versions = map[baseconfig.Version]baseconfig.Converter{ + Versions = map[chainconfig.Version]chainconfig.Converter{ 0: &v0.Config{}, 1: &v1.Config{}, } diff --git a/ignite/config/convert.go b/ignite/config/convert.go index c8fd9fcbfe..bd50ef2fec 100644 --- a/ignite/config/convert.go +++ b/ignite/config/convert.go @@ -4,6 +4,8 @@ import ( "io" "gopkg.in/yaml.v2" + + chainconfig "github.com/ignite/cli/ignite/config/chain" ) // Build time check for the latest config version type. @@ -13,7 +15,7 @@ import ( var _ = Versions[LatestVersion].(*ChainConfig) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c baseconfig.Converter) (_ *ChainConfig, err error) { +func ConvertLatest(c chainconfig.Converter) (_ *ChainConfig, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { diff --git a/ignite/config/errors.go b/ignite/config/errors.go index 74270a8e9f..6b36f04759 100644 --- a/ignite/config/errors.go +++ b/ignite/config/errors.go @@ -3,6 +3,8 @@ package config import ( "errors" "fmt" + + chainconfig "github.com/ignite/cli/ignite/config/chain" ) // ErrConfigNotFound indicates that the config.yml can't be found. @@ -19,7 +21,7 @@ func (e ValidationError) Error() string { // UnsupportedVersionError is returned when the version of the config is not supported. type UnsupportedVersionError struct { - Version baseconfig.Version + Version chainconfig.Version } func (e UnsupportedVersionError) Error() string { @@ -28,7 +30,7 @@ func (e UnsupportedVersionError) Error() string { // VersionError is returned when config version doesn't match with the version CLI supports. type VersionError struct { - Version baseconfig.Version + Version chainconfig.Version } func (e VersionError) Error() string { diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 94948f5b59..311c38ca2d 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -8,6 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" + + chainconfig "github.com/ignite/cli/ignite/config/chain" ) // Parse reads a config file. @@ -90,9 +92,9 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { } // ReadConfigVersion reads the config version. -func ReadConfigVersion(configFile io.Reader) (baseconfig.Version, error) { +func ReadConfigVersion(configFile io.Reader) (chainconfig.Version, error) { c := struct { - Version baseconfig.Version `yaml:"version"` + Version chainconfig.Version `yaml:"version"` }{} err := yaml.NewDecoder(configFile).Decode(&c) @@ -100,7 +102,7 @@ func ReadConfigVersion(configFile io.Reader) (baseconfig.Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version baseconfig.Version) (baseconfig.Converter, error) { +func decodeConfig(r io.Reader, version chainconfig.Version) (chainconfig.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 2a77596be2..21a23b31ad 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -333,7 +334,7 @@ func (c Chain) joinGeneratedPath(rootPath string) string { return filepath.Join(c.app.Path, rootPath, "generated") } -func (c Chain) saveClientConfig(client baseconfig.Client) error { +func (c Chain) saveClientConfig(client base.Client) error { path := c.ConfigPath() file, err := os.Open(path) if err != nil { From 71a75aa7188bed55e20ab3c01577fa05aebbd274 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:44:23 -0500 Subject: [PATCH 21/80] v12 -> v1 --- ignite/config/chain/v1/config_test.go | 89 ++++++++++++++------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index ac7cdc773a..da2992c7e9 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -7,7 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v12 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/ignite/cli/ignite/config/chain/base" + v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -17,22 +18,22 @@ func TestConfigDecode(t *testing.T) { f, err := os.Open("testdata/config2.yaml") require.NoError(err) defer f.Close() - var cfg v12.Config + var cfg v1.Config err = cfg.Decode(f) require.NoError(err) - expected := v12.Config{ - Config: baseconfig.Config{ + expected := v1.Config{ + Config: base.Config{ Version: 1, - Build: baseconfig.Build{ + Build: base.Build{ Binary: "evmosd", - Proto: baseconfig.Proto{ + Proto: base.Proto{ Path: "proto", ThirdPartyPaths: []string{"third_party/proto", "proto_vendor"}, }, }, - Accounts: []baseconfig.Account{ + Accounts: []base.Account{ { Name: "alice", Coins: []string{"100000000uatom", "100000000000000000000aevmos"}, @@ -44,7 +45,7 @@ func TestConfigDecode(t *testing.T) { Address: "cosmos1adn9gxjmrc3hrsdx5zpc9sj2ra7kgqkmphf8yw", }, }, - Faucet: baseconfig.Faucet{ + Faucet: base.Faucet{ Name: &[]string{"bob"}[0], Coins: []string{"10aevmos"}, Host: "0.0.0.0:4600", @@ -61,7 +62,7 @@ func TestConfigDecode(t *testing.T) { "chain_id": "evmosd_9000-1", }, }, - Validators: []v12.Validator{{ + Validators: []v1.Validator{{ Name: "alice", Bonded: "100000000000000000000aevmos", Home: "$HOME/.evmosd", @@ -72,7 +73,7 @@ func TestConfigDecode(t *testing.T) { }, }, }}, - Plugins: []v12.Plugin{ + Plugins: []v1.Plugin{ { Path: "/path/to/plugin1", }, @@ -87,15 +88,15 @@ func TestConfigDecode(t *testing.T) { func TestConfigValidatorDefaultServers(t *testing.T) { // Arrange - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -107,20 +108,20 @@ func TestConfigValidatorDefaultServers(t *testing.T) { require.NoError(t, err) // Assert - require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v12.DefaultAPIAddress, servers.API.Address) - require.Equal(t, v12.DefaultRPCAddress, servers.RPC.Address) - require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v1.DefaultAPIAddress, servers.API.Address) + require.Equal(t, v1.DefaultRPCAddress, servers.RPC.Address) + require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorWithExistingServers(t *testing.T) { // Arrange rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -135,7 +136,7 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -149,10 +150,10 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { // Assert require.Equal(t, rpcAddr, servers.RPC.Address) require.Equal(t, apiAddr, servers.API.Address) - require.Equal(t, v12.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v12.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v12.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v12.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorsWithExistingServers(t *testing.T) { @@ -160,8 +161,8 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { inc := uint64(10) rpcAddr := "127.0.0.1:1234" apiAddr := "127.0.0.1:4321" - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -180,7 +181,7 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -196,17 +197,17 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { require.Equal(t, apiAddr, servers.API.Address) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestConfigValidatorsDefaultServers(t *testing.T) { // Arrange inc := uint64(10) - c := v12.Config{ - Validators: []v12.Validator{ + c := v1.Config{ + Validators: []v1.Validator{ { Name: "name-1", Bonded: "100ATOM", @@ -217,7 +218,7 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { }, }, } - servers := v12.Servers{} + servers := v1.Servers{} // Act err := c.SetDefaults() @@ -229,18 +230,18 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { require.NoError(t, err) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultAPIAddress, inc), servers.API.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultRPCAddress, inc), servers.RPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v12.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultAPIAddress, inc), servers.API.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultRPCAddress, inc), servers.RPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestClone(t *testing.T) { // Arrange - c := &v12.Config{ - Validators: []v12.Validator{ + c := &v1.Config{ + Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", From 9b898469d6eb83348ff2941750a337a824d7203b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:46:36 -0500 Subject: [PATCH 22/80] fix tests --- ignite/config/chain/v0/config_convert_test.go | 3 ++- ignite/config/chainconfig_test.go | 3 ++- ignite/config/parse_test.go | 5 +++-- ignite/config/testdata/testdata.go | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 7744580b46..d344f76719 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) @@ -20,7 +21,7 @@ func TestV0ToV1(t *testing.T) { // Assert require.NoError(t, err) require.NotNilf(t, cfgV1, "expected *v1.Config, got %T", c) - require.Equal(t, baseconfig.Version(1), cfgV1.GetVersion()) + require.Equal(t, chainconfig.Version(1), cfgV1.GetVersion()) require.Equal(t, cfgV0.Build, cfgV1.Build) require.Equal(t, cfgV0.Accounts, cfgV1.Accounts) require.Equal(t, cfgV0.Faucet, cfgV1.Faucet) diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chainconfig_test.go index 3ca2dcf954..1227cd197e 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chainconfig_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + chainconfig "github.com/ignite/cli/ignite/config/chain" ) func TestCheckVersion(t *testing.T) { @@ -33,5 +34,5 @@ func TestCheckVersionWithOutdatedVersion(t *testing.T) { // Assert require.ErrorAs(t, err, &wantError) - require.Equal(t, wantError.Version, baseconfig.Version(0)) + require.Equal(t, wantError.Version, chainconfig.Version(0)) } diff --git a/ignite/config/parse_test.go b/ignite/config/parse_test.go index 2d1b2f3694..d624753ff7 100644 --- a/ignite/config/parse_test.go +++ b/ignite/config/parse_test.go @@ -9,13 +9,14 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/testdata" ) func TestReadConfigVersion(t *testing.T) { // Arrange r := strings.NewReader("version: 42") - want := baseconfig.Version(42) + want := chainconfig.Version(42) // Act version, err := config.ReadConfigVersion(r) @@ -56,7 +57,7 @@ func TestParseWithCurrentVersion(t *testing.T) { func TestParseWithUnknownVersion(t *testing.T) { // Arrange - version := baseconfig.Version(9999) + version := chainconfig.Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) var want *config.UnsupportedVersionError diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 6246e77c74..e57a56b8cc 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -4,12 +4,13 @@ import ( "testing" "github.com/ignite/cli/ignite/config" + chainconfig "github.com/ignite/cli/ignite/config/chain" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" ) -var Versions = map[baseconfig.Version][]byte{ +var Versions = map[chainconfig.Version][]byte{ 0: v0testdata.ConfigYAML, 1: v1testdata.ConfigYAML, } From a69a75841acc9ac3e774d42b425d4e29379486b3 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:51:01 -0500 Subject: [PATCH 23/80] fix integration --- integration/cosmosgen/bank_module_test.go | 3 ++- integration/node/cmd_query_bank_test.go | 5 +++-- integration/node/cmd_tx_bank_send_test.go | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index bcd3fc670b..ae3bf25068 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" ) @@ -27,7 +28,7 @@ func TestBankModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []baseconfig.Account{ + accounts := []base.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index c67a814603..4a4a1a1f76 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -65,14 +66,14 @@ func TestNodeQueryBankBalances(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *config.ChainConfig) { - c.Accounts = []baseconfig.Account{ + c.Accounts = []base.Account{ { Name: alice, Mnemonic: aliceMnemonic, Coins: []string{"5600atoken", "1200btoken", "100000000stake"}, }, } - c.Faucet = baseconfig.Faucet{} + c.Faucet = base.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index fa93156f71..9c742a7e4b 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" "github.com/ignite/cli/ignite/pkg/cosmosclient" @@ -56,7 +57,7 @@ func TestNodeTxBankSend(t *testing.T) { require.NoError(t, err) app.EditConfig(func(c *config.ChainConfig) { - c.Accounts = []baseconfig.Account{ + c.Accounts = []base.Account{ { Name: alice, Mnemonic: aliceMnemonic, @@ -68,7 +69,7 @@ func TestNodeTxBankSend(t *testing.T) { Coins: []string{"10000token", "100000000stake"}, }, } - c.Faucet = baseconfig.Faucet{} + c.Faucet = base.Faucet{} c.Validators[0].KeyringBackend = keyring.BackendTest }) env.Must(env.Exec("import alice", From f74180aca895a034ee0c7d2fc3f99d0b62218fd2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:52:17 -0500 Subject: [PATCH 24/80] fix name --- ignite/config/chain/base/config.go | 6 +++--- ignite/config/chain/v1/config.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index dcee2f8918..bb38d92198 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -154,15 +154,15 @@ func (c Config) GetVersion() chain.Version { // SetDefaults assigns default values to empty config fields. func (c *Config) SetDefaults() error { - if err := mergo.Merge(c, DefaulConfig()); err != nil { + if err := mergo.Merge(c, DefaultConfig()); err != nil { return err } return nil } -// DefaulConfig returns a base config with default values. -func DefaulConfig() Config { +// DefaultConfig returns a base config with default values. +func DefaultConfig() Config { return Config{ Build: Build{ Proto: Proto{ diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index b123f51f0a..d5b09a73b0 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -13,7 +13,7 @@ import ( // DefaultConfig returns a config with default values. func DefaultConfig() *Config { - c := Config{Config: base.DefaulConfig()} + c := Config{Config: base.DefaultConfig()} c.Version = 1 return &c } From b57ac111f2e30d2ce1714dd685e33d2e91612833 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 08:52:56 -0500 Subject: [PATCH 25/80] fix integration --- integration/cosmosgen/custom_module_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 37c0dfbbb5..7cf75ab308 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -28,7 +29,7 @@ func TestCustomModule(t *testing.T) { require.NoError(t, err) // Accounts to be included in the genesis - accounts := []baseconfig.Account{ + accounts := []base.Account{ { Name: "account1", Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm", From db2ed0063047aa4dedd164b988592f1955cbb646 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 28 Nov 2022 09:43:17 -0500 Subject: [PATCH 26/80] format --- ignite/config/plugins/config_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ignite/config/plugins/config_test.go b/ignite/config/plugins/config_test.go index 3d5548aba1..e18762c098 100644 --- a/ignite/config/plugins/config_test.go +++ b/ignite/config/plugins/config_test.go @@ -4,9 +4,10 @@ import ( "os" "testing" - "github.com/ignite/cli/ignite/config/plugins" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/ignite/cli/ignite/config/plugins" ) func TestConfigDecode(t *testing.T) { From a40d3dc0260246e7cf852dcf00a07b331c10cc21 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 29 Nov 2022 08:26:37 -0500 Subject: [PATCH 27/80] Update ignite/cmd/cmd.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jerónimo Albi --- ignite/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index f9701bba94..4aedab374d 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -134,7 +134,7 @@ func getConfig(cmd *cobra.Command) (config string) { func flagSetPlugins() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.StringP(flagPlugins, "x", "", "Ignite plugins file (default: ./plugins.yml)") + fs.StringP(flagPlugins, "x", "", "path to Ignite plugins config file (default: ./plugins.yml)") return fs } From e6858996520488ad1297add95c1003835fca0cd4 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 09:30:38 -0500 Subject: [PATCH 28/80] imports --- ignite/cmd/plugin.go | 3 +-- ignite/cmd/plugin_test.go | 6 +++--- ignite/services/plugin/plugin_test.go | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index da71b8fe28..294e504ad3 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -7,11 +7,10 @@ import ( "strings" "time" - "github.com/ignite/cli/ignite/config" - "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/ignite/cli/ignite/config" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/xgit" diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index d07a9516dd..d0a5daff56 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - config "github.com/ignite/cli/ignite/config/plugins" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/services/plugin" "github.com/ignite/cli/ignite/services/plugin/mocks" ) @@ -308,7 +308,7 @@ ignite assert := assert.New(t) pi := mocks.NewPluginInterface(t) p := &plugin.Plugin{ - Plugin: config.Plugin{ + Plugin: pluginsconfig.Plugin{ Path: "foo", With: pluginParams, }, @@ -537,7 +537,7 @@ func TestLinkPluginHooks(t *testing.T) { // assert := assert.New(t) pi := mocks.NewPluginInterface(t) p := &plugin.Plugin{ - Plugin: config.Plugin{ + Plugin: pluginsconfig.Plugin{ Path: "foo", With: pluginParams, }, diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index ddd3d56257..d1c83f76cb 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - config "github.com/ignite/cli/ignite/config/plugins" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/gomodule" ) @@ -27,7 +27,7 @@ func TestNewPlugin(t *testing.T) { tests := []struct { name string - pluginCfg config.Plugin + pluginCfg pluginsconfig.Plugin expectedPlugin Plugin }{ { @@ -38,21 +38,21 @@ func TestNewPlugin(t *testing.T) { }, { name: "fail: local plugin doesnt exists", - pluginCfg: config.Plugin{Path: "/xxx/yyy/plugin"}, + pluginCfg: pluginsconfig.Plugin{Path: "/xxx/yyy/plugin"}, expectedPlugin: Plugin{ Error: errors.Errorf(`local plugin path "/xxx/yyy/plugin" not found`), }, }, { name: "fail: local plugin is not a dir", - pluginCfg: config.Plugin{Path: path.Join(wd, "testdata/fakebin")}, + pluginCfg: pluginsconfig.Plugin{Path: path.Join(wd, "testdata/fakebin")}, expectedPlugin: Plugin{ Error: errors.Errorf(fmt.Sprintf("local plugin path %q is not a dir", path.Join(wd, "testdata/fakebin"))), }, }, { name: "ok: local plugin", - pluginCfg: config.Plugin{Path: path.Join(wd, "testdata")}, + pluginCfg: pluginsconfig.Plugin{Path: path.Join(wd, "testdata")}, expectedPlugin: Plugin{ srcPath: path.Join(wd, "testdata"), binaryName: "testdata", @@ -60,21 +60,21 @@ func TestNewPlugin(t *testing.T) { }, { name: "fail: remote plugin with only domain", - pluginCfg: config.Plugin{Path: "github.com"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com"}, expectedPlugin: Plugin{ Error: errors.Errorf(`plugin path "github.com" is not a valid repository URL`), }, }, { name: "fail: remote plugin with incomplete URL", - pluginCfg: config.Plugin{Path: "github.com/ignite"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite"}, expectedPlugin: Plugin{ Error: errors.Errorf(`plugin path "github.com/ignite" is not a valid repository URL`), }, }, { name: "ok: remote plugin", - pluginCfg: config.Plugin{Path: "github.com/ignite/plugin"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin", cloneURL: "https://github.com/ignite/plugin", @@ -86,7 +86,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with @ref", - pluginCfg: config.Plugin{Path: "github.com/ignite/plugin@develop"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin@develop"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin@develop", cloneURL: "https://github.com/ignite/plugin", @@ -98,7 +98,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with subpath", - pluginCfg: config.Plugin{Path: "github.com/ignite/plugin/plugin1"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin/plugin1"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin", cloneURL: "https://github.com/ignite/plugin", @@ -110,7 +110,7 @@ func TestNewPlugin(t *testing.T) { }, { name: "ok: remote plugin with subpath and @ref", - pluginCfg: config.Plugin{Path: "github.com/ignite/plugin/plugin1@develop"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin/plugin1@develop"}, expectedPlugin: Plugin{ repoPath: "github.com/ignite/plugin@develop", cloneURL: "https://github.com/ignite/plugin", @@ -343,7 +343,7 @@ func TestPluginClean(t *testing.T) { { name: "dont clean local plugin", plugin: &Plugin{ - Plugin: config.Plugin{Path: "/local"}, + Plugin: pluginsconfig.Plugin{Path: "/local"}, }, }, { From 5c429be554601d27def3f0f465e6264ebe9630e7 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 10:36:02 -0500 Subject: [PATCH 29/80] LocateDefault logic --- ignite/cmd/cmd.go | 2 +- ignite/cmd/plugin.go | 12 ++++++++++-- ignite/config/plugins/config.go | 22 ++++++++++++++++++++++ ignite/config/plugins/errors.go | 6 ++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 ignite/config/plugins/errors.go diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 4aedab374d..d1eded5e8a 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -123,7 +123,7 @@ func getHome(cmd *cobra.Command) (home string) { func flagSetConfig() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.StringP(flagConfig, "c", "", "Ignite config file (default: ./config.yml)") + fs.StringP(flagConfig, "c", "", "path to Ignite config file (default: ./config.yml)") return fs } diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 294e504ad3..6b7c0d000f 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -44,10 +44,18 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { return loadPlugins(rootCmd, plugins) } -func parseLocalPlugins(rootCmd *cobra.Command) (*pluginsconfig.Config, error) { +func parseLocalPlugins(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { + appPath := flagGetPath(rootCmd) pluginsPath := getPlugins(rootCmd) + if pluginsPath == "" { + if pluginsPath, err = pluginsconfig.LocateDefault(appPath); err != nil { + return cfg, err + } + } + + cfg, err = config.ParsePluginsFile(pluginsPath) - return config.ParsePluginsFile(pluginsPath) + return cfg, err } func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index ff0f21ab4d..14b84c6b97 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -2,17 +2,39 @@ package plugins import ( "io" + "os" + "path/filepath" "github.com/imdario/mergo" "gopkg.in/yaml.v2" ) +var ( + // PluginsConfigFilenames is a list of recognized names as Ignite's plugins config file. + PluginsConfigFilenames = []string{"plugins.yml", "plugins.yaml"} +) + // DefaultConfig returns a config with default values. func DefaultConfig() *Config { c := Config{} return &c } +// LocateDefault locates the default path for the config file. +// Returns ErrConfigNotFound when no config file found. +func LocateDefault(root string) (path string, err error) { + for _, name := range PluginsConfigFilenames { + path = filepath.Join(root, name) + if _, err := os.Stat(path); err == nil { + return path, nil + } else if !os.IsNotExist(err) { + return "", err + } + } + + return "", ErrConfigNotFound +} + type Config struct { Plugins []Plugin `yaml:"plugins,omitempty"` } diff --git a/ignite/config/plugins/errors.go b/ignite/config/plugins/errors.go new file mode 100644 index 0000000000..747d51e239 --- /dev/null +++ b/ignite/config/plugins/errors.go @@ -0,0 +1,6 @@ +package plugins + +import "errors" + +// ErrConfigNotFound indicates that the plugins.yml can't be found. +var ErrConfigNotFound = errors.New("could not locate a plugins.yml") From a6c78e960e55208833b08bb79a240cc6cb627dfe Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 10:37:44 -0500 Subject: [PATCH 30/80] lint fix --- ignite/config/plugins/config.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 14b84c6b97..2bdffbd540 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -9,10 +9,8 @@ import ( "gopkg.in/yaml.v2" ) -var ( - // PluginsConfigFilenames is a list of recognized names as Ignite's plugins config file. - PluginsConfigFilenames = []string{"plugins.yml", "plugins.yaml"} -) +// PluginsConfigFilenames is a list of recognized names as Ignite's plugins config file. +var PluginsConfigFilenames = []string{"plugins.yml", "plugins.yaml"} // DefaultConfig returns a config with default values. func DefaultConfig() *Config { From 54e7fe3a88084b873f497c9f4ded33dd25ae4f17 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 11:08:27 -0500 Subject: [PATCH 31/80] refactor and test --- ignite/config/parse.go | 26 ----------------- ignite/config/plugins/parse.go | 33 ++++++++++++++++++++++ ignite/config/plugins/parse_test.go | 24 ++++++++++++++++ ignite/config/plugins/testdata/testdata.go | 24 ++++++++++++++++ ignite/config/testdata/testdata.go | 8 ++++++ 5 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 ignite/config/plugins/parse.go create mode 100644 ignite/config/plugins/parse_test.go create mode 100644 ignite/config/plugins/testdata/testdata.go diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 1765510e8e..9ff344c1df 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -10,7 +10,6 @@ import ( "gopkg.in/yaml.v2" chainconfig "github.com/ignite/cli/ignite/config/chain" - "github.com/ignite/cli/ignite/config/plugins" ) // Parse reads a config file. @@ -37,11 +36,6 @@ func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { return cfg, validateNetworkConfig(cfg) } -// ParsePlugins reads a config file for ignite binary plugins -func ParsePlugins(configFile io.Reader) (*plugins.Config, error) { - return parsePluginsConfig(configFile) -} - func parseChainConfig(configFile io.Reader) (*ChainConfig, error) { var buf bytes.Buffer @@ -73,14 +67,6 @@ func parseChainConfig(configFile io.Reader) (*ChainConfig, error) { return cfg, nil } -func parsePluginsConfig(configFile io.Reader) (*plugins.Config, error) { - var c plugins.Config - - err := yaml.NewDecoder(configFile).Decode(&c) - - return &c, err -} - // ParseFile parses a config from a file path. func ParseFile(path string) (*ChainConfig, error) { file, err := os.Open(path) @@ -105,18 +91,6 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { return ParseNetwork(file) } -// ParsePluginsFile parses a plugins config. -func ParsePluginsFile(path string) (*plugins.Config, error) { - file, err := os.Open(path) - if err != nil { - return plugins.DefaultConfig(), err - } - - defer file.Close() - - return ParsePlugins(file) -} - // ReadConfigVersion reads the config version. func ReadConfigVersion(configFile io.Reader) (chainconfig.Version, error) { c := struct { diff --git a/ignite/config/plugins/parse.go b/ignite/config/plugins/parse.go new file mode 100644 index 0000000000..33c9940aea --- /dev/null +++ b/ignite/config/plugins/parse.go @@ -0,0 +1,33 @@ +package plugins + +import ( + "io" + "os" + + "gopkg.in/yaml.v2" +) + +// ParseFile parses a plugins config. +func ParseFile(path string) (*Config, error) { + file, err := os.Open(path) + if err != nil { + return DefaultConfig(), err + } + + defer file.Close() + + return Parse(file) +} + +// Parse reads a config file for ignite binary plugins +func Parse(configFile io.Reader) (*Config, error) { + return parse(configFile) +} + +func parse(configFile io.Reader) (*Config, error) { + var c Config + + err := yaml.NewDecoder(configFile).Decode(&c) + + return &c, err +} diff --git a/ignite/config/plugins/parse_test.go b/ignite/config/plugins/parse_test.go new file mode 100644 index 0000000000..752d47cb74 --- /dev/null +++ b/ignite/config/plugins/parse_test.go @@ -0,0 +1,24 @@ +package plugins_test + +import ( + "bytes" + "testing" + + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" + "github.com/ignite/cli/ignite/config/testdata" + "github.com/stretchr/testify/require" +) + +func TestParse(t *testing.T) { + // Arrange: Initialize a reader with the previous version + r := bytes.NewReader(testdata.PluginsConfig) + + // Act + cfg, err := pluginsconfig.Parse(r) + + // Assert + require.NoError(t, err) + + // Assert: Parse must return the latest version + require.Equal(t, testdata.GetPluginsConfig(t), cfg) +} diff --git a/ignite/config/plugins/testdata/testdata.go b/ignite/config/plugins/testdata/testdata.go new file mode 100644 index 0000000000..4762681280 --- /dev/null +++ b/ignite/config/plugins/testdata/testdata.go @@ -0,0 +1,24 @@ +package testdata + +import ( + "bytes" + _ "embed" + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" + + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" +) + +//go:embed plugins.yml +var ConfigYAML []byte + +func GetConfig(t *testing.T) *pluginsconfig.Config { + c := &pluginsconfig.Config{} + + err := yaml.NewDecoder(bytes.NewReader(ConfigYAML)).Decode(c) + require.NoError(t, err) + + return c +} diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index e57a56b8cc..18313e4717 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -1,6 +1,7 @@ package testdata import ( + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "testing" "github.com/ignite/cli/ignite/config" @@ -8,6 +9,7 @@ import ( networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" + pluginsconfigTestdata "github.com/ignite/cli/ignite/config/plugins/testdata" ) var Versions = map[chainconfig.Version][]byte{ @@ -17,6 +19,8 @@ var Versions = map[chainconfig.Version][]byte{ var NetworkConfig = networkconfigTestdata.ConfigYAML +var PluginsConfig = pluginsconfigTestdata.ConfigYAML + func GetLatestConfig(t *testing.T) *config.ChainConfig { return v1testdata.GetConfig(t) } @@ -24,3 +28,7 @@ func GetLatestConfig(t *testing.T) *config.ChainConfig { func GetLatestNetworkConfig(t *testing.T) *config.ChainConfig { return networkconfigTestdata.GetConfig(t) } + +func GetPluginsConfig(t *testing.T) *pluginsconfig.Config { + return pluginsconfigTestdata.GetConfig(t) +} From 39e92e7a08071f0459322edc24f3cfb2f97fab5f Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 11:10:05 -0500 Subject: [PATCH 32/80] finish refactor --- ignite/cmd/plugin.go | 3 +-- ignite/config/plugins/parse_test.go | 3 ++- ignite/config/testdata/testdata.go | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 6b7c0d000f..a041db2522 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -10,7 +10,6 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/xgit" @@ -53,7 +52,7 @@ func parseLocalPlugins(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err e } } - cfg, err = config.ParsePluginsFile(pluginsPath) + cfg, err = pluginsconfig.ParseFile(pluginsPath) return cfg, err } diff --git a/ignite/config/plugins/parse_test.go b/ignite/config/plugins/parse_test.go index 752d47cb74..deb1aa9309 100644 --- a/ignite/config/plugins/parse_test.go +++ b/ignite/config/plugins/parse_test.go @@ -4,9 +4,10 @@ import ( "bytes" "testing" + "github.com/stretchr/testify/require" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/config/testdata" - "github.com/stretchr/testify/require" ) func TestParse(t *testing.T) { diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 18313e4717..3c9f64a51e 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -1,9 +1,10 @@ package testdata import ( - pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "testing" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" + "github.com/ignite/cli/ignite/config" chainconfig "github.com/ignite/cli/ignite/config/chain" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" From 9f10308e0dc68a377fe9a3bb31ef21154de70a58 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 11:24:34 -0500 Subject: [PATCH 33/80] revert --- ignite/config/parse.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 9ff344c1df..311c38ca2d 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -16,7 +16,7 @@ import ( // When the version of the file being read is not the latest // it is automatically migrated to the latest version. func Parse(configFile io.Reader) (*ChainConfig, error) { - cfg, err := parseChainConfig(configFile) + cfg, err := parse(configFile) if err != nil { return cfg, fmt.Errorf("error parsing config file: %w", err) } @@ -28,7 +28,7 @@ func Parse(configFile io.Reader) (*ChainConfig, error) { // When the version of the file being read is not the latest // it is automatically migrated to the latest version. func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { - cfg, err := parseChainConfig(configFile) + cfg, err := parse(configFile) if err != nil { return cfg, err } @@ -36,7 +36,7 @@ func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { return cfg, validateNetworkConfig(cfg) } -func parseChainConfig(configFile io.Reader) (*ChainConfig, error) { +func parse(configFile io.Reader) (*ChainConfig, error) { var buf bytes.Buffer // Read the config file version first to know how to decode it @@ -47,7 +47,7 @@ func parseChainConfig(configFile io.Reader) (*ChainConfig, error) { // Decode the current config file version and assign default // values for the fields that are empty - c, err := decodeChainConfig(&buf, version) + c, err := decodeConfig(&buf, version) if err != nil { return DefaultChainConfig(), err } @@ -102,7 +102,7 @@ func ReadConfigVersion(configFile io.Reader) (chainconfig.Version, error) { return c.Version, err } -func decodeChainConfig(r io.Reader, version chainconfig.Version) (chainconfig.Converter, error) { +func decodeConfig(r io.Reader, version chainconfig.Version) (chainconfig.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} From 5b4e13b8f2e40866f4240f66d61f5b1b41cfb4f8 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:25:17 -0500 Subject: [PATCH 34/80] move --- ignite/cmd/chain.go | 18 +++++----- ignite/cmd/cmd.go | 4 +-- ignite/cmd/ignite/main.go | 4 +-- ignite/cmd/scaffold_react.go | 4 +-- ignite/cmd/scaffold_vue.go | 4 +-- ignite/config/chain/chain.go | 31 ----------------- ignite/config/{ => chain}/chainconfig.go | 7 ++-- ignite/config/{ => chain}/chainconfig_test.go | 16 ++++----- ignite/config/{ => chain}/convert.go | 32 ++++++++++++++--- ignite/config/{ => chain}/convert_test.go | 13 ++++--- ignite/config/{ => chain}/errors.go | 8 ++--- ignite/config/{ => chain}/parse.go | 10 +++--- ignite/config/{ => chain}/parse_test.go | 34 +++++++++---------- ignite/config/testdata/testdata.go | 5 ++- ignite/pkg/cosmosgen/generate_vuex.go | 4 +-- ignite/services/chain/chain.go | 10 +++--- ignite/services/chain/generate.go | 16 ++++----- ignite/services/chain/init.go | 6 ++-- ignite/services/chain/runtime.go | 12 +++---- ignite/services/chain/serve.go | 14 ++++---- .../network/networkchain/binarycache.go | 4 +-- ignite/services/network/networkchain/init.go | 4 +-- .../network/networkchain/networkchain.go | 6 ++-- ignite/services/plugin/plugin.go | 4 +-- ignite/services/scaffolder/scaffolder.go | 8 ++--- ignite/version/version.go | 4 +-- integration/app.go | 14 ++++---- integration/chain/config_test.go | 4 +-- integration/client.go | 6 ++-- integration/cosmosgen/bank_module_test.go | 4 +-- integration/cosmosgen/custom_module_test.go | 4 +-- integration/network/network_test.go | 10 +++--- integration/node/cmd_query_bank_test.go | 4 +-- integration/node/cmd_tx_bank_send_test.go | 4 +-- 34 files changed, 157 insertions(+), 175 deletions(-) delete mode 100644 ignite/config/chain/chain.go rename ignite/config/{ => chain}/chainconfig.go (96%) rename ignite/config/{ => chain}/chainconfig_test.go (53%) rename ignite/config/{ => chain}/convert.go (54%) rename ignite/config/{ => chain}/convert_test.go (64%) rename ignite/config/{ => chain}/errors.go (89%) rename ignite/config/{ => chain}/parse.go (92%) rename ignite/config/{ => chain}/parse_test.go (68%) diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index ad3572a7fa..7b00698451 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -4,12 +4,12 @@ import ( "bytes" "errors" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "github.com/manifoldco/promptui" "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -101,7 +101,7 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) appPath := flagGetPath(cmd) configPath := getConfig(cmd) if configPath == "" { - if configPath, err = config.LocateDefault(appPath); err != nil { + if configPath, err = chain.LocateDefault(appPath); err != nil { return err } } @@ -111,22 +111,22 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } - version, err := config.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := chain.ReadConfigVersion(bytes.NewReader(rawCfg)) if err != nil { return err } // ChainConfig files with older versions must be migrated to the latest before executing the command - if version != config.LatestVersion { + if version != chain.LatestVersion { if !getYes(cmd) { - prefix := fmt.Sprintf(msgMigrationPrefix, version, config.LatestVersion) - question := fmt.Sprintf(msgMigrationPrompt, config.LatestVersion) + prefix := fmt.Sprintf(msgMigrationPrefix, version, chain.LatestVersion) + question := fmt.Sprintf(msgMigrationPrompt, chain.LatestVersion) // Confirm before overwritting the config file session.Println(prefix) if err := session.AskConfirm(question); err != nil { if errors.Is(err, promptui.ErrAbort) { - return fmt.Errorf(msgMigrationCancel, config.LatestVersion) + return fmt.Errorf(msgMigrationCancel, chain.LatestVersion) } return err @@ -137,12 +137,12 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } } else { - session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, config.LatestVersion)) + session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chain.LatestVersion)) } // Convert the current config to the latest version and update the YAML file var buf bytes.Buffer - if err := config.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { + if err := chain.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { return err } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index d1eded5e8a..d7b59a0ec7 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -3,6 +3,7 @@ package ignitecmd import ( "context" "fmt" + chain2 "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "sort" @@ -12,7 +13,6 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -308,7 +308,7 @@ func printSection(session *cliui.Session, title string) error { } func newCache(cmd *cobra.Command) (cache.Storage, error) { - cacheRootDir, err := config.DirPath() + cacheRootDir, err := chain2.DirPath() if err != nil { return cache.Storage{}, err } diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 0c885add76..8bbdff2634 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -4,10 +4,10 @@ import ( "context" "errors" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" ignitecmd "github.com/ignite/cli/ignite/cmd" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/clictx" "github.com/ignite/cli/ignite/pkg/validation" "github.com/ignite/cli/ignite/pkg/xstrings" @@ -43,7 +43,7 @@ func run() int { if err != nil { var ( validationErr validation.Error - versionErr config.VersionError + versionErr chain.VersionError msg string ) diff --git a/ignite/cmd/scaffold_react.go b/ignite/cmd/scaffold_react.go index 745b622540..c142804d66 100644 --- a/ignite/cmd/scaffold_react.go +++ b/ignite/cmd/scaffold_react.go @@ -1,9 +1,9 @@ package ignitecmd import ( + "github.com/ignite/cli/ignite/config/chain" "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -19,7 +19,7 @@ func NewScaffoldReact() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+config.DefaultReactPath, "path to scaffold content of the React app") + c.Flags().StringP(flagPath, "p", "./"+chain.DefaultReactPath, "path to scaffold content of the React app") return c } diff --git a/ignite/cmd/scaffold_vue.go b/ignite/cmd/scaffold_vue.go index 6856dd497e..d446723edb 100644 --- a/ignite/cmd/scaffold_vue.go +++ b/ignite/cmd/scaffold_vue.go @@ -1,9 +1,9 @@ package ignitecmd import ( + "github.com/ignite/cli/ignite/config/chain" "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -19,7 +19,7 @@ func NewScaffoldVue() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+config.DefaultVuePath, "path to scaffold content of the Vue.js app") + c.Flags().StringP(flagPath, "p", "./"+chain.DefaultVuePath, "path to scaffold content of the Vue.js app") return c } diff --git a/ignite/config/chain/chain.go b/ignite/config/chain/chain.go deleted file mode 100644 index 594406dff1..0000000000 --- a/ignite/config/chain/chain.go +++ /dev/null @@ -1,31 +0,0 @@ -package chain - -import ( - "fmt" - "io" -) - -// Version defines the type for the config version number. -type Version uint - -func (v Version) String() string { - return fmt.Sprintf("v%d", v) -} - -// Converter defines the interface required to migrate configurations to newer versions. -type Converter interface { - // Clone clones the config by returning a new copy of the current one. - Clone() (Converter, error) - - // SetDefaults assigns default values to empty config fields. - SetDefaults() error - - // GetVersion returns the config version. - GetVersion() Version - - // ConvertNext converts the config to the next version. - ConvertNext() (Converter, error) - - // Decode decodes the config file from YAML and updates its values. - Decode(io.Reader) error -} diff --git a/ignite/config/chainconfig.go b/ignite/config/chain/chainconfig.go similarity index 96% rename from ignite/config/chainconfig.go rename to ignite/config/chain/chainconfig.go index 87820e2685..0f0c790769 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chain/chainconfig.go @@ -1,4 +1,4 @@ -package config +package chain import ( "fmt" @@ -9,7 +9,6 @@ import ( "gopkg.in/yaml.v2" - chainconfig "github.com/ignite/cli/ignite/config/chain" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -51,10 +50,10 @@ var ( DefaultOpenAPIPath = "docs/static/openapi.yml" // LatestVersion defines the latest version of the config. - LatestVersion chainconfig.Version = 1 + LatestVersion Version = 1 // Versions holds config types for the supported versions. - Versions = map[chainconfig.Version]chainconfig.Converter{ + Versions = map[Version]Converter{ 0: &v0.Config{}, 1: &v1.Config{}, } diff --git a/ignite/config/chainconfig_test.go b/ignite/config/chain/chainconfig_test.go similarity index 53% rename from ignite/config/chainconfig_test.go rename to ignite/config/chain/chainconfig_test.go index 1227cd197e..7d5a76899a 100644 --- a/ignite/config/chainconfig_test.go +++ b/ignite/config/chain/chainconfig_test.go @@ -1,24 +1,22 @@ -package config_test +package chain_test import ( "bytes" "fmt" + "github.com/ignite/cli/ignite/config/chain" "testing" "github.com/stretchr/testify/require" - - "github.com/ignite/cli/ignite/config" - chainconfig "github.com/ignite/cli/ignite/config/chain" ) func TestCheckVersion(t *testing.T) { // Arrange cfg := bytes.NewBufferString( - fmt.Sprintf("version: %d", config.LatestVersion), + fmt.Sprintf("version: %d", LatestVersion), ) // Act - err := config.CheckVersion(cfg) + err := CheckVersion(cfg) // Assert require.NoError(t, err) @@ -27,12 +25,12 @@ func TestCheckVersion(t *testing.T) { func TestCheckVersionWithOutdatedVersion(t *testing.T) { // Arrange cfg := bytes.NewBufferString("version: 0") - wantError := config.VersionError{} + wantError := chain.VersionError{} // Act - err := config.CheckVersion(cfg) + err := CheckVersion(cfg) // Assert require.ErrorAs(t, err, &wantError) - require.Equal(t, wantError.Version, chainconfig.Version(0)) + require.Equal(t, wantError.Version, Version(0)) } diff --git a/ignite/config/convert.go b/ignite/config/chain/convert.go similarity index 54% rename from ignite/config/convert.go rename to ignite/config/chain/convert.go index bd50ef2fec..40414368b0 100644 --- a/ignite/config/convert.go +++ b/ignite/config/chain/convert.go @@ -1,13 +1,37 @@ -package config +package chain import ( + "fmt" "io" "gopkg.in/yaml.v2" - - chainconfig "github.com/ignite/cli/ignite/config/chain" ) +// Version defines the type for the config version number. +type Version uint + +func (v Version) String() string { + return fmt.Sprintf("v%d", v) +} + +// Converter defines the interface required to migrate configurations to newer versions. +type Converter interface { + // Clone clones the config by returning a new copy of the current one. + Clone() (Converter, error) + + // SetDefaults assigns default values to empty config fields. + SetDefaults() error + + // GetVersion returns the config version. + GetVersion() Version + + // ConvertNext converts the config to the next version. + ConvertNext() (Converter, error) + + // Decode decodes the config file from YAML and updates its values. + Decode(io.Reader) error +} + // Build time check for the latest config version type. // This is required to be sure that conversion to latest // doesn't break when a new config version is added without @@ -15,7 +39,7 @@ import ( var _ = Versions[LatestVersion].(*ChainConfig) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c chainconfig.Converter) (_ *ChainConfig, err error) { +func ConvertLatest(c Converter) (_ *ChainConfig, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { diff --git a/ignite/config/convert_test.go b/ignite/config/chain/convert_test.go similarity index 64% rename from ignite/config/convert_test.go rename to ignite/config/chain/convert_test.go index c2905264f0..32087690d4 100644 --- a/ignite/config/convert_test.go +++ b/ignite/config/chain/convert_test.go @@ -1,4 +1,4 @@ -package config_test +package chain_test import ( "bytes" @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "github.com/ignite/cli/ignite/config/testdata" ) @@ -16,22 +15,22 @@ func TestConvertLatest(t *testing.T) { cfgV0 := v0testdata.GetConfig(t) // Act - cfgLatest, err := config.ConvertLatest(cfgV0) + cfgLatest, err := ConvertLatest(cfgV0) // Assert require.NoError(t, err) - require.Equal(t, config.LatestVersion, cfgLatest.GetVersion()) + require.Equal(t, LatestVersion, cfgLatest.GetVersion()) require.Equal(t, testdata.GetLatestConfig(t), cfgLatest) } func TestMigrateLatest(t *testing.T) { // Arrange - current := bytes.NewReader(testdata.Versions[config.LatestVersion-1]) + current := bytes.NewReader(testdata.Versions[LatestVersion-1]) latest := bytes.Buffer{} - want := string(testdata.Versions[config.LatestVersion]) + want := string(testdata.Versions[LatestVersion]) // Act - err := config.MigrateLatest(current, &latest) + err := MigrateLatest(current, &latest) // Assert require.NotEmpty(t, want, "testdata is missing the latest config version") diff --git a/ignite/config/errors.go b/ignite/config/chain/errors.go similarity index 89% rename from ignite/config/errors.go rename to ignite/config/chain/errors.go index 6b36f04759..cfdd8f54bd 100644 --- a/ignite/config/errors.go +++ b/ignite/config/chain/errors.go @@ -1,10 +1,8 @@ -package config +package chain import ( "errors" "fmt" - - chainconfig "github.com/ignite/cli/ignite/config/chain" ) // ErrConfigNotFound indicates that the config.yml can't be found. @@ -21,7 +19,7 @@ func (e ValidationError) Error() string { // UnsupportedVersionError is returned when the version of the config is not supported. type UnsupportedVersionError struct { - Version chainconfig.Version + Version Version } func (e UnsupportedVersionError) Error() string { @@ -30,7 +28,7 @@ func (e UnsupportedVersionError) Error() string { // VersionError is returned when config version doesn't match with the version CLI supports. type VersionError struct { - Version chainconfig.Version + Version Version } func (e VersionError) Error() string { diff --git a/ignite/config/parse.go b/ignite/config/chain/parse.go similarity index 92% rename from ignite/config/parse.go rename to ignite/config/chain/parse.go index 311c38ca2d..ea1e774e6b 100644 --- a/ignite/config/parse.go +++ b/ignite/config/chain/parse.go @@ -1,4 +1,4 @@ -package config +package chain import ( "bytes" @@ -8,8 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" - - chainconfig "github.com/ignite/cli/ignite/config/chain" ) // Parse reads a config file. @@ -92,9 +90,9 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { } // ReadConfigVersion reads the config version. -func ReadConfigVersion(configFile io.Reader) (chainconfig.Version, error) { +func ReadConfigVersion(configFile io.Reader) (Version, error) { c := struct { - Version chainconfig.Version `yaml:"version"` + Version Version `yaml:"version"` }{} err := yaml.NewDecoder(configFile).Decode(&c) @@ -102,7 +100,7 @@ func ReadConfigVersion(configFile io.Reader) (chainconfig.Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version chainconfig.Version) (chainconfig.Converter, error) { +func decodeConfig(r io.Reader, version Version) (Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} diff --git a/ignite/config/parse_test.go b/ignite/config/chain/parse_test.go similarity index 68% rename from ignite/config/parse_test.go rename to ignite/config/chain/parse_test.go index d624753ff7..9c36a7d201 100644 --- a/ignite/config/parse_test.go +++ b/ignite/config/chain/parse_test.go @@ -1,4 +1,4 @@ -package config_test +package chain_test import ( "bytes" @@ -8,18 +8,16 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" - chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/testdata" ) func TestReadConfigVersion(t *testing.T) { // Arrange r := strings.NewReader("version: 42") - want := chainconfig.Version(42) + want := Version(42) // Act - version, err := config.ReadConfigVersion(r) + version, err := ReadConfigVersion(r) // Assert require.NoError(t, err) @@ -28,42 +26,42 @@ func TestReadConfigVersion(t *testing.T) { func TestParse(t *testing.T) { // Arrange: Initialize a reader with the previous version - ver := config.LatestVersion - 1 + ver := LatestVersion - 1 r := bytes.NewReader(testdata.Versions[ver]) // Act - cfg, err := config.Parse(r) + cfg, err := Parse(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, config.LatestVersion, cfg.Version) + require.Equal(t, LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } func TestParseWithCurrentVersion(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[config.LatestVersion]) + r := bytes.NewReader(testdata.Versions[LatestVersion]) // Act - cfg, err := config.Parse(r) + cfg, err := Parse(r) // Assert require.NoError(t, err) - require.Equal(t, config.LatestVersion, cfg.Version) + require.Equal(t, LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } func TestParseWithUnknownVersion(t *testing.T) { // Arrange - version := chainconfig.Version(9999) + version := Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) - var want *config.UnsupportedVersionError + var want *UnsupportedVersionError // Act - _, err := config.Parse(r) + _, err := Parse(r) // Assert require.ErrorAs(t, err, &want) @@ -76,23 +74,23 @@ func TestParseNetworkWithCurrentVersion(t *testing.T) { r := bytes.NewReader(testdata.NetworkConfig) // Act - cfg, err := config.ParseNetwork(r) + cfg, err := ParseNetwork(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, config.LatestVersion, cfg.Version) + require.Equal(t, LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestNetworkConfig(t).Accounts, cfg.Accounts) require.Equal(t, testdata.GetLatestNetworkConfig(t).Genesis, cfg.Genesis) } func TestParseNetworkWithInvalidData(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[config.LatestVersion]) + r := bytes.NewReader(testdata.Versions[LatestVersion]) // Act - _, err := config.ParseNetwork(r) + _, err := ParseNetwork(r) // Assert error require.True( diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 3c9f64a51e..d30e64a89d 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -5,7 +5,6 @@ import ( pluginsconfig "github.com/ignite/cli/ignite/config/plugins" - "github.com/ignite/cli/ignite/config" chainconfig "github.com/ignite/cli/ignite/config/chain" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" @@ -22,11 +21,11 @@ var NetworkConfig = networkconfigTestdata.ConfigYAML var PluginsConfig = pluginsconfigTestdata.ConfigYAML -func GetLatestConfig(t *testing.T) *config.ChainConfig { +func GetLatestConfig(t *testing.T) *chainconfig.ChainConfig { return v1testdata.GetConfig(t) } -func GetLatestNetworkConfig(t *testing.T) *config.ChainConfig { +func GetLatestNetworkConfig(t *testing.T) *chainconfig.ChainConfig { return networkconfigTestdata.GetConfig(t) } diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index cde5088d04..717bcce72e 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "strings" @@ -11,7 +12,6 @@ import ( "github.com/imdario/mergo" "golang.org/x/sync/errgroup" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" "github.com/ignite/cli/ignite/pkg/gomodulepath" ) @@ -26,7 +26,7 @@ func newVuexGenerator(g *generator) *vuexGenerator { func (g *generator) updateVueDependencies() error { // Init the path to the "vue" folders inside the app - vuePath := filepath.Join(g.appPath, config.DefaultVuePath) + vuePath := filepath.Join(g.appPath, chain.DefaultVuePath) packagesPath := filepath.Join(vuePath, "package.json") if _, err := os.Stat(packagesPath); errors.Is(err, os.ErrNotExist) { return nil diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index bb00d5c380..8a449ccbd1 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -2,13 +2,13 @@ package chain import ( "context" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "github.com/go-git/go-git/v5" "github.com/tendermint/spn/pkg/chainid" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -202,7 +202,7 @@ func (c *Chain) ConfigPath() string { if c.options.ConfigFile != "" { return c.options.ConfigFile } - path, err := config.LocateDefault(c.app.Path) + path, err := chain.LocateDefault(c.app.Path) if err != nil { return "" } @@ -210,12 +210,12 @@ func (c *Chain) ConfigPath() string { } // Config returns the config of the chain -func (c *Chain) Config() (*config.ChainConfig, error) { +func (c *Chain) Config() (*chain.ChainConfig, error) { configPath := c.ConfigPath() if configPath == "" { - return config.DefaultChainConfig(), nil + return chain.DefaultChainConfig(), nil } - return config.ParseFile(configPath) + return chain.ParseFile(configPath) } // ID returns the chain's id. diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 21a23b31ad..4849e30525 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -3,10 +3,10 @@ package chain import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -158,7 +158,7 @@ func (c *Chain) Generate( if targetOptions.isTSClientEnabled { tsClientPath = targetOptions.tsClientPath if tsClientPath == "" { - tsClientPath = config.TSClientPath(*conf) + tsClientPath = chain.TSClientPath(*conf) // When TS client is generated make sure the config is updated // with the output path when the client path option is empty. @@ -185,7 +185,7 @@ func (c *Chain) Generate( //nolint:staticcheck //ignore SA1019 until vuex config option is removed vuexPath = targetOptions.vuexPath if vuexPath == "" { - vuexPath = config.VuexPath(conf) + vuexPath = chain.VuexPath(conf) // When Vuex stores are generated make sure the config is updated // with the output path when the client path option is empty. @@ -211,7 +211,7 @@ func (c *Chain) Generate( composablesPath = targetOptions.composablesPath if composablesPath == "" { - composablesPath = config.ComposablesPath(conf) + composablesPath = chain.ComposablesPath(conf) if conf.Client.Composables.Path == "" { conf.Client.Composables.Path = composablesPath @@ -235,7 +235,7 @@ func (c *Chain) Generate( if targetOptions.isHooksEnabled { hooksPath = targetOptions.hooksPath if hooksPath == "" { - hooksPath = config.HooksPath(conf) + hooksPath = chain.HooksPath(conf) if conf.Client.Hooks.Path == "" { conf.Client.Hooks.Path = hooksPath @@ -259,7 +259,7 @@ func (c *Chain) Generate( if targetOptions.isOpenAPIEnabled { openAPIPath = conf.Client.OpenAPI.Path if openAPIPath == "" { - openAPIPath = config.DefaultOpenAPIPath + openAPIPath = chain.DefaultOpenAPIPath } // Non absolute OpenAPI paths must be treated as relative to the app directory @@ -347,12 +347,12 @@ func (c Chain) saveClientConfig(client base.Client) error { // values that otherwise would be initialized to defaults. // Defaults must be ignored to avoid writing them to the // YAML config file when they are not present. - var cfg config.ChainConfig + var cfg chain.ChainConfig if err := cfg.Decode(file); err != nil { return err } cfg.Client = client - return config.Save(cfg, path) + return chain.Save(cfg, path) } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index 6bb050beb7..c5628a9e0f 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -2,13 +2,13 @@ package chain import ( "context" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "strings" "github.com/imdario/mergo" - "github.com/ignite/cli/ignite/config" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/view/accountview" "github.com/ignite/cli/ignite/pkg/confile" @@ -86,7 +86,7 @@ func (c *Chain) InitChain(ctx context.Context) error { } // InitAccounts initializes the chain accounts and creates validator gentxs -func (c *Chain) InitAccounts(ctx context.Context, cfg *config.ChainConfig) error { +func (c *Chain) InitAccounts(ctx context.Context, cfg *chain.ChainConfig) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -222,7 +222,7 @@ type Account struct { Coins string } -func createValidatorFromConfig(conf *config.ChainConfig) (validator Validator) { +func createValidatorFromConfig(conf *chain.ChainConfig) (validator Validator) { // Currently, we support the config file with one valid validator. validatorFromConfig := conf.Validators[0] validator.Name = validatorFromConfig.Name diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index 96dc6cc325..af3befd5ba 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -3,13 +3,13 @@ package chain import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/pelletier/go-toml" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/xurl" @@ -36,7 +36,7 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida } // Start wraps the "appd start" command to begin running a chain from the daemon -func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *config.ChainConfig) error { +func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chain.ChainConfig) error { validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { @@ -49,7 +49,7 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *con } // Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml) -func (c Chain) Configure(homePath string, cfg *config.ChainConfig) error { +func (c Chain) Configure(homePath string, cfg *chain.ChainConfig) error { if err := c.appTOML(homePath, cfg); err != nil { return err } @@ -59,7 +59,7 @@ func (c Chain) Configure(homePath string, cfg *config.ChainConfig) error { return c.configTOML(homePath, cfg) } -func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { +func (c Chain) appTOML(homePath string, cfg *chain.ChainConfig) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") config, err := toml.LoadFile(path) @@ -106,7 +106,7 @@ func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { return err } -func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { +func (c Chain) configTOML(homePath string, cfg *chain.ChainConfig) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") config, err := toml.LoadFile(path) @@ -153,7 +153,7 @@ func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { return err } -func (c Chain) clientTOML(homePath string, cfg *config.ChainConfig) error { +func (c Chain) clientTOML(homePath string, cfg *chain.ChainConfig) error { path := filepath.Join(homePath, "config/client.toml") config, err := toml.LoadFile(path) if os.IsNotExist(err) { diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 138a2970ec..67464d8c8f 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -3,6 +3,7 @@ package chain import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "net/http" "os" "os/exec" @@ -14,7 +15,6 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -53,7 +53,7 @@ var ( // starportSavePath is the place where chain exported genesis are saved starportSavePath = xfilepath.Join( - config.DirPath, + chain.DirPath, xfilepath.Path("local-chains"), ) ) @@ -130,7 +130,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . if _, err := os.Stat(c.options.ConfigFile); err != nil { return err } - } else if _, err := config.LocateDefault(c.app.Path); err != nil { + } else if _, err := chain.LocateDefault(c.app.Path); err != nil { return err } @@ -160,7 +160,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . serveCtx context.Context buildErr *CannotBuildAppError startErr *CannotStartAppError - validationErr *config.ValidationError + validationErr *chain.ValidationError ) serveCtx, c.serveCancel = context.WithCancel(ctx) @@ -427,7 +427,7 @@ func (c *Chain) serve( return c.start(ctx, conf) } -func (c *Chain) start(ctx context.Context, cfg *config.ChainConfig) error { +func (c *Chain) start(ctx context.Context, cfg *chain.ChainConfig) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -485,7 +485,7 @@ func (c *Chain) start(ctx context.Context, cfg *config.ChainConfig) error { ) if isFaucetEnabled { - faucetAddr, _ := xurl.HTTP(config.FaucetHost(cfg)) + faucetAddr, _ := xurl.HTTP(chain.FaucetHost(cfg)) c.ev.Send( fmt.Sprintf("Token faucet: %s", faucetAddr), @@ -503,7 +503,7 @@ func (c *Chain) runFaucetServer(ctx context.Context, faucet cosmosfaucet.Faucet) } return xhttp.Serve(ctx, &http.Server{ - Addr: config.FaucetHost(cfg), + Addr: chain.FaucetHost(cfg), Handler: faucet, }) } diff --git a/ignite/services/network/networkchain/binarycache.go b/ignite/services/network/networkchain/binarycache.go index 2df530f8c3..b2a8556972 100644 --- a/ignite/services/network/networkchain/binarycache.go +++ b/ignite/services/network/networkchain/binarycache.go @@ -1,7 +1,7 @@ package networkchain import ( - "github.com/ignite/cli/ignite/config" + "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/checksum" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -78,7 +78,7 @@ func checkBinaryCacheForLaunchID(launchID uint64, binaryHash, sourceHash string) func getBinaryCacheFilepath() (string, error) { return xfilepath.Join( - config.DirPath, + chain.DirPath, xfilepath.Path(SPNCacheDirectory), xfilepath.Path(BinaryCacheDirectory), xfilepath.Path(BinaryCacheFilename), diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index eceecd2bad..78ade77d36 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -4,10 +4,10 @@ import ( "context" "errors" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" cosmosgenesis "github.com/ignite/cli/ignite/pkg/cosmosutil/genesis" "github.com/ignite/cli/ignite/pkg/events" @@ -124,7 +124,7 @@ func (c *Chain) initGenesis(ctx context.Context) error { return fmt.Errorf("the config for genesis doesn't exist: %w", err) } - config, err := config.ParseNetworkFile(path) + config, err := chain.ParseNetworkFile(path) if err != nil { return err } diff --git a/ignite/services/network/networkchain/networkchain.go b/ignite/services/network/networkchain/networkchain.go index 2f2d8e51e1..617e721e86 100644 --- a/ignite/services/network/networkchain/networkchain.go +++ b/ignite/services/network/networkchain/networkchain.go @@ -3,6 +3,7 @@ package networkchain import ( "context" "errors" + chain2 "github.com/ignite/cli/ignite/config/chain" "os" "os/exec" "time" @@ -11,7 +12,6 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/chaincmd" "github.com/ignite/cli/ignite/pkg/checksum" @@ -287,7 +287,7 @@ func (c Chain) NodeID(ctx context.Context) (string, error) { func (c Chain) CheckConfigVersion() error { configPath := c.chain.ConfigPath() if configPath == "" { - return config.ErrConfigNotFound + return chain2.ErrConfigNotFound } file, err := os.Open(configPath) @@ -297,7 +297,7 @@ func (c Chain) CheckConfigVersion() error { defer file.Close() - return config.CheckVersion(file) + return chain2.CheckVersion(file) } // Build builds chain sources, also checks if source was already built diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 638af0d6bf..644909dbb9 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -6,6 +6,7 @@ package plugin import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "io/fs" "os" "os/exec" @@ -20,7 +21,6 @@ import ( hplugin "github.com/hashicorp/go-plugin" "github.com/pkg/errors" - "github.com/ignite/cli/ignite/config" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" cliexec "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" @@ -32,7 +32,7 @@ import ( // pluginsPath holds the plugin cache directory. var pluginsPath = xfilepath.Join( - config.DirPath, + chain.DirPath, xfilepath.Path("plugins"), ) diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 1aeb9ff8f1..e54af9e3f1 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -4,9 +4,9 @@ package scaffolder import ( "context" + "github.com/ignite/cli/ignite/config/chain" "path/filepath" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cosmosanalysis" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -76,11 +76,11 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP return err } - confpath, err := config.LocateDefault(projectPath) + confpath, err := chain.LocateDefault(projectPath) if err != nil { return err } - conf, err := config.ParseFile(confpath) + conf, err := chain.ParseFile(confpath) if err != nil { return err } @@ -92,7 +92,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP // Generate Typescript client code if it's enabled or when Vuex stores are generated if conf.Client.Typescript.Path != "" || conf.Client.Vuex.Path != "" { //nolint:staticcheck //ignore SA1019 until vuex config option is removed - tsClientPath := config.TSClientPath(*conf) + tsClientPath := chain.TSClientPath(*conf) if !filepath.IsAbs(tsClientPath) { tsClientPath = filepath.Join(projectPath, tsClientPath) } diff --git a/ignite/version/version.go b/ignite/version/version.go index 560605aaa2..9e5bf1980f 100644 --- a/ignite/version/version.go +++ b/ignite/version/version.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "runtime" "runtime/debug" @@ -13,7 +14,6 @@ import ( "github.com/blang/semver/v4" "github.com/google/go-github/v48/github" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gitpod" @@ -103,7 +103,7 @@ func Long(ctx context.Context) string { write("Ignite CLI version", Version) write("Ignite CLI build date", date) write("Ignite CLI source hash", head) - write("Ignite CLI config version", config.LatestVersion) + write("Ignite CLI config version", chain.LatestVersion) write("Cosmos SDK version", sdkVersion) write("Your OS", runtime.GOOS) diff --git a/integration/app.go b/integration/app.go index 430b2efa1d..3acb71cb5d 100644 --- a/integration/app.go +++ b/integration/app.go @@ -2,6 +2,7 @@ package envtest import ( "fmt" + "github.com/ignite/cli/ignite/config/chain" "os" "path" "path/filepath" @@ -11,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -187,7 +187,7 @@ func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string) { port, err := availableport.Find(1) require.NoError(a.env.t, err) - a.EditConfig(func(c *config.ChainConfig) { + a.EditConfig(func(c *chain.ChainConfig) { c.Faucet.Port = port[0] c.Faucet.Coins = coins c.Faucet.CoinsMax = coinsMax @@ -219,7 +219,7 @@ func (a App) RandomizeServerPorts() Hosts { API: genAddr(ports[5]), } - a.EditConfig(func(c *config.ChainConfig) { + a.EditConfig(func(c *chain.ChainConfig) { v := &c.Validators[0] s := v1.Servers{} @@ -241,24 +241,24 @@ func (a App) RandomizeServerPorts() Hosts { func (a App) UseRandomHomeDir() (homeDirPath string) { dir := a.env.TmpDir() - a.EditConfig(func(c *config.ChainConfig) { + a.EditConfig(func(c *chain.ChainConfig) { c.Validators[0].Home = dir }) return dir } -func (a App) Config() config.ChainConfig { +func (a App) Config() chain.ChainConfig { bz, err := os.ReadFile(a.configPath) require.NoError(a.env.t, err) - var conf config.ChainConfig + var conf chain.ChainConfig err = yaml.Unmarshal(bz, &conf) require.NoError(a.env.t, err) return conf } -func (a App) EditConfig(apply func(*config.ChainConfig)) { +func (a App) EditConfig(apply func(*chain.ChainConfig)) { conf := a.Config() apply(&conf) diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index 482ab25164..aa5b017dad 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -5,12 +5,12 @@ package chain_test import ( "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "path/filepath" "testing" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/randstr" envtest "github.com/ignite/cli/integration" @@ -26,7 +26,7 @@ func TestOverwriteSDKConfigsAndChainID(t *testing.T) { isBackendAliveErr error ) - var cfg config.ChainConfig + var cfg chain.ChainConfig cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml")) require.NoError(t, cf.Load(&cfg)) diff --git a/integration/client.go b/integration/client.go index 4ab6622b6c..a8e70fb3b1 100644 --- a/integration/client.go +++ b/integration/client.go @@ -2,6 +2,7 @@ package envtest import ( "bytes" + "github.com/ignite/cli/ignite/config/chain" "os" "os/exec" "path/filepath" @@ -9,7 +10,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" ) @@ -68,7 +68,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Absolute path to the blockchain app directory "TEST_CHAIN_PATH": a.path, // Absolute path to the TS client directory - "TEST_TSCLIENT_DIR": filepath.Join(a.path, config.DefaultTSClientPath), + "TEST_TSCLIENT_DIR": filepath.Join(a.path, chain.DefaultTSClientPath), }, } for _, o := range options { @@ -83,7 +83,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Install the dependencies needed to run TS client tests ok = a.env.Exec("install client dependencies", step.NewSteps( step.New( - step.Workdir(filepath.Join(a.path, config.DefaultTSClientPath)), + step.Workdir(filepath.Join(a.path, chain.DefaultTSClientPath)), step.Stdout(&output), step.Exec(npm, "install"), step.PostExec(func(err error) error { diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index ae3bf25068..b198c72e96 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" "fmt" + "github.com/ignite/cli/ignite/config/chain" "testing" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -58,7 +58,7 @@ func TestBankModule(t *testing.T) { }, } - app.EditConfig(func(cfg *config.ChainConfig) { + app.EditConfig(func(cfg *chain.ChainConfig) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 7cf75ab308..b4fdb10527 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" "fmt" + "github.com/ignite/cli/ignite/config/chain" "testing" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" @@ -41,7 +41,7 @@ func TestCustomModule(t *testing.T) { }, } - app.EditConfig(func(cfg *config.ChainConfig) { + app.EditConfig(func(cfg *chain.ChainConfig) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 46b165adfc..1fc48bc3f1 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -3,6 +3,7 @@ package network_test import ( "bytes" "context" + "github.com/ignite/cli/ignite/config/chain" "os" "path" "path/filepath" @@ -14,7 +15,6 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gomodule" envtest "github.com/ignite/cli/integration" @@ -74,17 +74,17 @@ func migrateSPNConfig(t *testing.T, spnPath string) { rawCfg, err := os.ReadFile(configPath) require.NoError(t, err) - version, err := config.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := chain.ReadConfigVersion(bytes.NewReader(rawCfg)) require.NoError(t, err) - if version != config.LatestVersion { - t.Logf("migrating spn config from v%d to v%d", version, config.LatestVersion) + if version != chain.LatestVersion { + t.Logf("migrating spn config from v%d to v%d", version, chain.LatestVersion) file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755) require.NoError(t, err) defer file.Close() - err = config.MigrateLatest(bytes.NewReader(rawCfg), file) + err = chain.MigrateLatest(bytes.NewReader(rawCfg), file) require.NoError(t, err) } } diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 4a4a1a1f76..90e0ebe007 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -3,6 +3,7 @@ package node_test import ( "bytes" "context" + "github.com/ignite/cli/ignite/config/chain" "path/filepath" "strings" "testing" @@ -12,7 +13,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -65,7 +65,7 @@ func TestNodeQueryBankBalances(t *testing.T) { aliceAccount, aliceMnemonic, err := ca.Create(alice) require.NoError(t, err) - app.EditConfig(func(c *config.ChainConfig) { + app.EditConfig(func(c *chain.ChainConfig) { c.Accounts = []base.Account{ { Name: alice, diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 9c742a7e4b..7b9f4992e3 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/ignite/cli/ignite/config/chain" "path/filepath" "testing" "time" @@ -11,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -56,7 +56,7 @@ func TestNodeTxBankSend(t *testing.T) { bobAccount, bobMnemonic, err := ca.Create(bob) require.NoError(t, err) - app.EditConfig(func(c *config.ChainConfig) { + app.EditConfig(func(c *chain.ChainConfig) { c.Accounts = []base.Account{ { Name: alice, From 72c312360fd852b4d53de3c023ea82faa96b7d91 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:27:41 -0500 Subject: [PATCH 35/80] move --- ignite/config/chain/{chainconfig.go => config.go} | 12 +++++------- .../chain/{chainconfig_test.go => config_test.go} | 0 ignite/config/config.go | 8 ++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) rename ignite/config/chain/{chainconfig.go => config.go} (92%) rename ignite/config/chain/{chainconfig_test.go => config_test.go} (100%) create mode 100644 ignite/config/config.go diff --git a/ignite/config/chain/chainconfig.go b/ignite/config/chain/config.go similarity index 92% rename from ignite/config/chain/chainconfig.go rename to ignite/config/chain/config.go index 0f0c790769..a9536f3e35 100644 --- a/ignite/config/chain/chainconfig.go +++ b/ignite/config/chain/config.go @@ -9,17 +9,15 @@ import ( "gopkg.in/yaml.v2" + "github.com/ignite/cli/ignite/config" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" - "github.com/ignite/cli/ignite/pkg/xfilepath" ) var ( - // DirPath returns the path of configuration directory of Ignite. - DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) - // ChainConfigFilenames is a list of recognized names as Ignite's chain config file. - ChainConfigFilenames = []string{"config.yml", "config.yaml"} + // ConfigFilenames is a list of recognized names as Ignite's chain config file. + ConfigFilenames = []string{"config.yml", "config.yaml"} // DefaultTSClientPath defines the default relative path to use when generating the TS client. // The path is relative to the app's directory. @@ -122,7 +120,7 @@ func HooksPath(conf *ChainConfig) string { // CreateConfigDir creates config directory if it is not created yet. func CreateConfigDir() error { - path, err := DirPath() + path, err := config.DirPath() if err != nil { return err } @@ -133,7 +131,7 @@ func CreateConfigDir() error { // LocateDefault locates the default path for the config file. // Returns ErrConfigNotFound when no config file found. func LocateDefault(root string) (path string, err error) { - for _, name := range ChainConfigFilenames { + for _, name := range ConfigFilenames { path = filepath.Join(root, name) if _, err := os.Stat(path); err == nil { return path, nil diff --git a/ignite/config/chain/chainconfig_test.go b/ignite/config/chain/config_test.go similarity index 100% rename from ignite/config/chain/chainconfig_test.go rename to ignite/config/chain/config_test.go diff --git a/ignite/config/config.go b/ignite/config/config.go new file mode 100644 index 0000000000..e7cd0e136e --- /dev/null +++ b/ignite/config/config.go @@ -0,0 +1,8 @@ +package config + +import "github.com/ignite/cli/ignite/pkg/xfilepath" + +var ( + // DirPath returns the path of configuration directory of Ignite. + DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) +) From c9c968342a2740cd22538b5dce4c67d4b4b9c38e Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:40:05 -0500 Subject: [PATCH 36/80] rename --- ignite/cmd/chain.go | 20 +++++------ ignite/cmd/cmd.go | 4 +-- ignite/cmd/ignite/main.go | 2 +- ignite/cmd/scaffold_react.go | 3 +- ignite/cmd/scaffold_vue.go | 3 +- ignite/config/chain/base/config.go | 17 ++++----- ignite/config/chain/config.go | 35 +++++++------------ ignite/config/chain/config_test.go | 12 ++++--- ignite/config/chain/convert.go | 34 +++--------------- ignite/config/chain/convert_test.go | 11 +++--- ignite/config/chain/errors.go | 6 ++-- ignite/config/chain/parse.go | 22 ++++++------ ignite/config/chain/v0/config.go | 3 +- ignite/config/chain/v0/config_convert.go | 2 +- ignite/config/chain/v0/config_convert_test.go | 3 +- ignite/config/chain/v1/config.go | 3 +- ignite/config/chain/v1/config_convert.go | 4 ++- ignite/config/chain/version/version.go | 31 ++++++++++++++++ ignite/config/config.go | 20 ++++++++--- ignite/config/testdata/testdata.go | 8 +++-- ignite/pkg/cosmosgen/generate_vuex.go | 3 +- ignite/services/chain/chain.go | 5 +-- ignite/services/chain/generate.go | 5 +-- ignite/services/chain/init.go | 7 ++-- ignite/services/chain/runtime.go | 13 +++---- ignite/services/chain/serve.go | 16 +++++---- .../network/networkchain/binarycache.go | 4 +-- ignite/services/network/networkchain/init.go | 3 +- .../network/networkchain/networkchain.go | 3 +- ignite/services/plugin/plugin.go | 4 +-- ignite/services/scaffolder/scaffolder.go | 3 +- ignite/version/version.go | 3 +- integration/app.go | 14 ++++---- integration/chain/config_test.go | 5 +-- integration/client.go | 3 +- integration/cosmosgen/bank_module_test.go | 5 +-- integration/cosmosgen/custom_module_test.go | 5 +-- integration/network/network_test.go | 5 +-- integration/node/cmd_query_bank_test.go | 5 +-- integration/node/cmd_tx_bank_send_test.go | 5 +-- 40 files changed, 202 insertions(+), 157 deletions(-) create mode 100644 ignite/config/chain/version/version.go diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 7b00698451..e36e8e1611 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -4,12 +4,12 @@ import ( "bytes" "errors" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "github.com/manifoldco/promptui" "github.com/spf13/cobra" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -101,7 +101,7 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) appPath := flagGetPath(cmd) configPath := getConfig(cmd) if configPath == "" { - if configPath, err = chain.LocateDefault(appPath); err != nil { + if configPath, err = chainconfig.LocateDefault(appPath); err != nil { return err } } @@ -111,22 +111,22 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } - version, err := chain.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := chainconfig.ReadConfigVersion(bytes.NewReader(rawCfg)) if err != nil { return err } - // ChainConfig files with older versions must be migrated to the latest before executing the command - if version != chain.LatestVersion { + // Config files with older versions must be migrated to the latest before executing the command + if version != chainconfig.LatestVersion { if !getYes(cmd) { - prefix := fmt.Sprintf(msgMigrationPrefix, version, chain.LatestVersion) - question := fmt.Sprintf(msgMigrationPrompt, chain.LatestVersion) + prefix := fmt.Sprintf(msgMigrationPrefix, version, chainconfig.LatestVersion) + question := fmt.Sprintf(msgMigrationPrompt, chainconfig.LatestVersion) // Confirm before overwritting the config file session.Println(prefix) if err := session.AskConfirm(question); err != nil { if errors.Is(err, promptui.ErrAbort) { - return fmt.Errorf(msgMigrationCancel, chain.LatestVersion) + return fmt.Errorf(msgMigrationCancel, chainconfig.LatestVersion) } return err @@ -137,12 +137,12 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) return err } } else { - session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chain.LatestVersion)) + session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chainconfig.LatestVersion)) } // Convert the current config to the latest version and update the YAML file var buf bytes.Buffer - if err := chain.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { + if err := chainconfig.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil { return err } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index d7b59a0ec7..d1eded5e8a 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -3,7 +3,6 @@ package ignitecmd import ( "context" "fmt" - chain2 "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "sort" @@ -13,6 +12,7 @@ import ( "github.com/spf13/cobra" flag "github.com/spf13/pflag" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -308,7 +308,7 @@ func printSection(session *cliui.Session, title string) error { } func newCache(cmd *cobra.Command) (cache.Storage, error) { - cacheRootDir, err := chain2.DirPath() + cacheRootDir, err := config.DirPath() if err != nil { return cache.Storage{}, err } diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 8bbdff2634..4f05e0ad74 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -4,10 +4,10 @@ import ( "context" "errors" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" ignitecmd "github.com/ignite/cli/ignite/cmd" + "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/clictx" "github.com/ignite/cli/ignite/pkg/validation" "github.com/ignite/cli/ignite/pkg/xstrings" diff --git a/ignite/cmd/scaffold_react.go b/ignite/cmd/scaffold_react.go index c142804d66..3a745bfd8e 100644 --- a/ignite/cmd/scaffold_react.go +++ b/ignite/cmd/scaffold_react.go @@ -1,9 +1,10 @@ package ignitecmd import ( - "github.com/ignite/cli/ignite/config/chain" "github.com/spf13/cobra" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) diff --git a/ignite/cmd/scaffold_vue.go b/ignite/cmd/scaffold_vue.go index d446723edb..32ebcc6f52 100644 --- a/ignite/cmd/scaffold_vue.go +++ b/ignite/cmd/scaffold_vue.go @@ -1,9 +1,10 @@ package ignitecmd import ( - "github.com/ignite/cli/ignite/config/chain" "github.com/spf13/cobra" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index bb38d92198..e5fe84531e 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -3,7 +3,8 @@ package base import ( "github.com/imdario/mergo" - "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/version" + xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) @@ -139,16 +140,16 @@ type Host struct { // Config defines a struct with the fields that are common to all config versions. type Config struct { - Version chain.Version `yaml:"version"` - Build Build `yaml:"build,omitempty"` - Accounts []Account `yaml:"accounts"` - Faucet Faucet `yaml:"faucet,omitempty"` - Client Client `yaml:"client,omitempty"` - Genesis xyaml.Map `yaml:"genesis,omitempty"` + Version version.Version `yaml:"version"` + Build Build `yaml:"build,omitempty"` + Accounts []Account `yaml:"accounts"` + Faucet Faucet `yaml:"faucet,omitempty"` + Client Client `yaml:"client,omitempty"` + Genesis xyaml.Map `yaml:"genesis,omitempty"` } // GetVersion returns the config version. -func (c Config) GetVersion() chain.Version { +func (c Config) GetVersion() version.Version { return c.Version } diff --git a/ignite/config/chain/config.go b/ignite/config/chain/config.go index a9536f3e35..7a17e9b268 100644 --- a/ignite/config/chain/config.go +++ b/ignite/config/chain/config.go @@ -7,9 +7,10 @@ import ( "path/filepath" "strings" + "github.com/ignite/cli/ignite/config/chain/version" + "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) @@ -48,25 +49,25 @@ var ( DefaultOpenAPIPath = "docs/static/openapi.yml" // LatestVersion defines the latest version of the config. - LatestVersion Version = 1 + LatestVersion version.Version = 1 // Versions holds config types for the supported versions. - Versions = map[Version]Converter{ + Versions = map[version.Version]version.Converter{ 0: &v0.Config{}, 1: &v1.Config{}, } ) -// ChainConfig defines the latest chain config. -type ChainConfig = v1.Config +// Config defines the latest chain config. +type Config = v1.Config // DefaultChainConfig returns a config for the latest version initialized with default values. -func DefaultChainConfig() *ChainConfig { +func DefaultChainConfig() *Config { return v1.DefaultConfig() } // FaucetHost returns the faucet host to use. -func FaucetHost(cfg *ChainConfig) string { +func FaucetHost(cfg *Config) string { // We keep supporting Port option for backward compatibility // TODO: drop this option in the future host := cfg.Faucet.Host @@ -79,7 +80,7 @@ func FaucetHost(cfg *ChainConfig) string { // TSClientPath returns the relative path to the Typescript client directory. // Path is relative to the app's directory. -func TSClientPath(conf ChainConfig) string { +func TSClientPath(conf Config) string { if path := strings.TrimSpace(conf.Client.Typescript.Path); path != "" { return filepath.Clean(path) } @@ -89,7 +90,7 @@ func TSClientPath(conf ChainConfig) string { // VuexPath returns the relative path to the Vuex stores directory. // Path is relative to the app's directory. -func VuexPath(conf *ChainConfig) string { +func VuexPath(conf *Config) string { //nolint:staticcheck //ignore SA1019 until vuex config option is removed if path := strings.TrimSpace(conf.Client.Vuex.Path); path != "" { return filepath.Clean(path) @@ -100,7 +101,7 @@ func VuexPath(conf *ChainConfig) string { // ComposablesPath returns the relative path to the Vue useQuery composables directory. // Path is relative to the app's directory. -func ComposablesPath(conf *ChainConfig) string { +func ComposablesPath(conf *Config) string { if path := strings.TrimSpace(conf.Client.Composables.Path); path != "" { return filepath.Clean(path) } @@ -110,7 +111,7 @@ func ComposablesPath(conf *ChainConfig) string { // HooksPath returns the relative path to the React useQuery hooks directory. // Path is relative to the app's directory. -func HooksPath(conf *ChainConfig) string { +func HooksPath(conf *Config) string { if path := strings.TrimSpace(conf.Client.Hooks.Path); path != "" { return filepath.Clean(path) } @@ -118,16 +119,6 @@ func HooksPath(conf *ChainConfig) string { return DefaultHooksPath } -// CreateConfigDir creates config directory if it is not created yet. -func CreateConfigDir() error { - path, err := config.DirPath() - if err != nil { - return err - } - - return os.MkdirAll(path, 0o755) -} - // LocateDefault locates the default path for the config file. // Returns ErrConfigNotFound when no config file found. func LocateDefault(root string) (path string, err error) { @@ -159,7 +150,7 @@ func CheckVersion(configFile io.Reader) error { } // Save saves a config to a YAML file. -func Save(c ChainConfig, path string) error { +func Save(c Config, path string) error { file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0o755) if err != nil { return err diff --git a/ignite/config/chain/config_test.go b/ignite/config/chain/config_test.go index 7d5a76899a..dd1b170279 100644 --- a/ignite/config/chain/config_test.go +++ b/ignite/config/chain/config_test.go @@ -3,20 +3,22 @@ package chain_test import ( "bytes" "fmt" - "github.com/ignite/cli/ignite/config/chain" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/version" + "github.com/stretchr/testify/require" ) func TestCheckVersion(t *testing.T) { // Arrange cfg := bytes.NewBufferString( - fmt.Sprintf("version: %d", LatestVersion), + fmt.Sprintf("version: %d", chain.LatestVersion), ) // Act - err := CheckVersion(cfg) + err := chain.CheckVersion(cfg) // Assert require.NoError(t, err) @@ -28,9 +30,9 @@ func TestCheckVersionWithOutdatedVersion(t *testing.T) { wantError := chain.VersionError{} // Act - err := CheckVersion(cfg) + err := chain.CheckVersion(cfg) // Assert require.ErrorAs(t, err, &wantError) - require.Equal(t, wantError.Version, Version(0)) + require.Equal(t, wantError.Version, version.Version(0)) } diff --git a/ignite/config/chain/convert.go b/ignite/config/chain/convert.go index 40414368b0..7cd02b99d3 100644 --- a/ignite/config/chain/convert.go +++ b/ignite/config/chain/convert.go @@ -1,45 +1,21 @@ package chain import ( - "fmt" "io" "gopkg.in/yaml.v2" -) - -// Version defines the type for the config version number. -type Version uint - -func (v Version) String() string { - return fmt.Sprintf("v%d", v) -} - -// Converter defines the interface required to migrate configurations to newer versions. -type Converter interface { - // Clone clones the config by returning a new copy of the current one. - Clone() (Converter, error) - // SetDefaults assigns default values to empty config fields. - SetDefaults() error - - // GetVersion returns the config version. - GetVersion() Version - - // ConvertNext converts the config to the next version. - ConvertNext() (Converter, error) - - // Decode decodes the config file from YAML and updates its values. - Decode(io.Reader) error -} + "github.com/ignite/cli/ignite/config/chain/version" +) // Build time check for the latest config version type. // This is required to be sure that conversion to latest // doesn't break when a new config version is added without // updating the references to the previous version. -var _ = Versions[LatestVersion].(*ChainConfig) +var _ = Versions[LatestVersion].(*Config) // ConvertLatest converts a config to the latest version. -func ConvertLatest(c Converter) (_ *ChainConfig, err error) { +func ConvertLatest(c version.Converter) (_ *Config, err error) { for c.GetVersion() < LatestVersion { c, err = c.ConvertNext() if err != nil { @@ -50,7 +26,7 @@ func ConvertLatest(c Converter) (_ *ChainConfig, err error) { // Cast to the latest version type. // This is safe because there is a build time check that makes sure // the type for the latest config version is the right one here. - return c.(*ChainConfig), nil + return c.(*Config), nil } // MigrateLatest migrates a config file to the latest version. diff --git a/ignite/config/chain/convert_test.go b/ignite/config/chain/convert_test.go index 32087690d4..c7a9f74f31 100644 --- a/ignite/config/chain/convert_test.go +++ b/ignite/config/chain/convert_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/ignite/cli/ignite/config/chain" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "github.com/ignite/cli/ignite/config/testdata" ) @@ -15,22 +16,22 @@ func TestConvertLatest(t *testing.T) { cfgV0 := v0testdata.GetConfig(t) // Act - cfgLatest, err := ConvertLatest(cfgV0) + cfgLatest, err := chain.ConvertLatest(cfgV0) // Assert require.NoError(t, err) - require.Equal(t, LatestVersion, cfgLatest.GetVersion()) + require.Equal(t, chain.LatestVersion, cfgLatest.GetVersion()) require.Equal(t, testdata.GetLatestConfig(t), cfgLatest) } func TestMigrateLatest(t *testing.T) { // Arrange - current := bytes.NewReader(testdata.Versions[LatestVersion-1]) + current := bytes.NewReader(testdata.Versions[chain.LatestVersion-1]) latest := bytes.Buffer{} - want := string(testdata.Versions[LatestVersion]) + want := string(testdata.Versions[chain.LatestVersion]) // Act - err := MigrateLatest(current, &latest) + err := chain.MigrateLatest(current, &latest) // Assert require.NotEmpty(t, want, "testdata is missing the latest config version") diff --git a/ignite/config/chain/errors.go b/ignite/config/chain/errors.go index cfdd8f54bd..b3f43ed551 100644 --- a/ignite/config/chain/errors.go +++ b/ignite/config/chain/errors.go @@ -3,6 +3,8 @@ package chain import ( "errors" "fmt" + + "github.com/ignite/cli/ignite/config/chain/version" ) // ErrConfigNotFound indicates that the config.yml can't be found. @@ -19,7 +21,7 @@ func (e ValidationError) Error() string { // UnsupportedVersionError is returned when the version of the config is not supported. type UnsupportedVersionError struct { - Version Version + Version version.Version } func (e UnsupportedVersionError) Error() string { @@ -28,7 +30,7 @@ func (e UnsupportedVersionError) Error() string { // VersionError is returned when config version doesn't match with the version CLI supports. type VersionError struct { - Version Version + Version version.Version } func (e VersionError) Error() string { diff --git a/ignite/config/chain/parse.go b/ignite/config/chain/parse.go index ea1e774e6b..3a80937c13 100644 --- a/ignite/config/chain/parse.go +++ b/ignite/config/chain/parse.go @@ -6,6 +6,8 @@ import ( "io" "os" + "github.com/ignite/cli/ignite/config/chain/version" + "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" ) @@ -13,7 +15,7 @@ import ( // Parse reads a config file. // When the version of the file being read is not the latest // it is automatically migrated to the latest version. -func Parse(configFile io.Reader) (*ChainConfig, error) { +func Parse(configFile io.Reader) (*Config, error) { cfg, err := parse(configFile) if err != nil { return cfg, fmt.Errorf("error parsing config file: %w", err) @@ -25,7 +27,7 @@ func Parse(configFile io.Reader) (*ChainConfig, error) { // ParseNetwork reads a config file for Ignite Network genesis. // When the version of the file being read is not the latest // it is automatically migrated to the latest version. -func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { +func ParseNetwork(configFile io.Reader) (*Config, error) { cfg, err := parse(configFile) if err != nil { return cfg, err @@ -34,7 +36,7 @@ func ParseNetwork(configFile io.Reader) (*ChainConfig, error) { return cfg, validateNetworkConfig(cfg) } -func parse(configFile io.Reader) (*ChainConfig, error) { +func parse(configFile io.Reader) (*Config, error) { var buf bytes.Buffer // Read the config file version first to know how to decode it @@ -66,7 +68,7 @@ func parse(configFile io.Reader) (*ChainConfig, error) { } // ParseFile parses a config from a file path. -func ParseFile(path string) (*ChainConfig, error) { +func ParseFile(path string) (*Config, error) { file, err := os.Open(path) if err != nil { return DefaultChainConfig(), err @@ -78,7 +80,7 @@ func ParseFile(path string) (*ChainConfig, error) { } // ParseNetworkFile parses a config for Ignite Network genesis from a file path. -func ParseNetworkFile(path string) (*ChainConfig, error) { +func ParseNetworkFile(path string) (*Config, error) { file, err := os.Open(path) if err != nil { return DefaultChainConfig(), err @@ -90,9 +92,9 @@ func ParseNetworkFile(path string) (*ChainConfig, error) { } // ReadConfigVersion reads the config version. -func ReadConfigVersion(configFile io.Reader) (Version, error) { +func ReadConfigVersion(configFile io.Reader) (version.Version, error) { c := struct { - Version Version `yaml:"version"` + Version version.Version `yaml:"version"` }{} err := yaml.NewDecoder(configFile).Decode(&c) @@ -100,7 +102,7 @@ func ReadConfigVersion(configFile io.Reader) (Version, error) { return c.Version, err } -func decodeConfig(r io.Reader, version Version) (Converter, error) { +func decodeConfig(r io.Reader, version version.Version) (version.Converter, error) { c, ok := Versions[version] if !ok { return nil, &UnsupportedVersionError{version} @@ -118,7 +120,7 @@ func decodeConfig(r io.Reader, version Version) (Converter, error) { return cfg, nil } -func validateConfig(c *ChainConfig) error { +func validateConfig(c *Config) error { if len(c.Accounts) == 0 { return &ValidationError{"at least one account is required"} } @@ -140,7 +142,7 @@ func validateConfig(c *ChainConfig) error { return nil } -func validateNetworkConfig(c *ChainConfig) error { +func validateNetworkConfig(c *Config) error { if len(c.Validators) != 0 { return &ValidationError{"no validators can be used in config for network genesis"} } diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index 250740a3ec..f319a6f6a7 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -3,10 +3,11 @@ package v0 import ( "io" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/imdario/mergo" "gopkg.in/yaml.v2" - chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" ) diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index 5a251947d4..7ef2f8bac6 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -1,8 +1,8 @@ package v0 import ( - chainconfig "github.com/ignite/cli/ignite/config/chain" v1 "github.com/ignite/cli/ignite/config/chain/v1" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" ) // ConvertNext converts the current config version to the next one. diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index d344f76719..56342242e4 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -3,9 +3,10 @@ package v0_test import ( "testing" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/stretchr/testify/require" - chainconfig "github.com/ignite/cli/ignite/config/chain" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" ) diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 6cf0fefaa9..1bd28901a4 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -3,10 +3,11 @@ package v1 import ( "io" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/imdario/mergo" "gopkg.in/yaml.v2" - chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/config/chain/v1/config_convert.go b/ignite/config/chain/v1/config_convert.go index 2f345533aa..ce57a99e6c 100644 --- a/ignite/config/chain/v1/config_convert.go +++ b/ignite/config/chain/v1/config_convert.go @@ -1,6 +1,8 @@ package v1 -import chainconfig "github.com/ignite/cli/ignite/config/chain" +import ( + chainconfig "github.com/ignite/cli/ignite/config/chain/version" +) // ConvertNext implements the conversion of the current config to the next version. func (c *Config) ConvertNext() (chainconfig.Converter, error) { diff --git a/ignite/config/chain/version/version.go b/ignite/config/chain/version/version.go new file mode 100644 index 0000000000..70a536912e --- /dev/null +++ b/ignite/config/chain/version/version.go @@ -0,0 +1,31 @@ +package version + +import ( + "fmt" + "io" +) + +// Version defines the type for the config version number. +type Version uint + +func (v Version) String() string { + return fmt.Sprintf("v%d", v) +} + +// Converter defines the interface required to migrate configurations to newer versions. +type Converter interface { + // Clone clones the config by returning a new copy of the current one. + Clone() (Converter, error) + + // SetDefaults assigns default values to empty config fields. + SetDefaults() error + + // GetVersion returns the config version. + GetVersion() Version + + // ConvertNext converts the config to the next version. + ConvertNext() (Converter, error) + + // Decode decodes the config file from YAML and updates its values. + Decode(io.Reader) error +} diff --git a/ignite/config/config.go b/ignite/config/config.go index e7cd0e136e..2217fa486a 100644 --- a/ignite/config/config.go +++ b/ignite/config/config.go @@ -1,8 +1,20 @@ package config -import "github.com/ignite/cli/ignite/pkg/xfilepath" +import ( + "os" -var ( - // DirPath returns the path of configuration directory of Ignite. - DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) + "github.com/ignite/cli/ignite/pkg/xfilepath" ) + +// DirPath returns the path of configuration directory of Ignite. +var DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) + +// CreateConfigDir creates config directory if it is not created yet. +func CreateConfigDir() error { + path, err := DirPath() + if err != nil { + return err + } + + return os.MkdirAll(path, 0o755) +} diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index d30e64a89d..eea7c283e8 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -3,6 +3,8 @@ package testdata import ( "testing" + "github.com/ignite/cli/ignite/config/chain/version" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" chainconfig "github.com/ignite/cli/ignite/config/chain" @@ -12,7 +14,7 @@ import ( pluginsconfigTestdata "github.com/ignite/cli/ignite/config/plugins/testdata" ) -var Versions = map[chainconfig.Version][]byte{ +var Versions = map[version.Version][]byte{ 0: v0testdata.ConfigYAML, 1: v1testdata.ConfigYAML, } @@ -21,11 +23,11 @@ var NetworkConfig = networkconfigTestdata.ConfigYAML var PluginsConfig = pluginsconfigTestdata.ConfigYAML -func GetLatestConfig(t *testing.T) *chainconfig.ChainConfig { +func GetLatestConfig(t *testing.T) *chainconfig.Config { return v1testdata.GetConfig(t) } -func GetLatestNetworkConfig(t *testing.T) *chainconfig.ChainConfig { +func GetLatestNetworkConfig(t *testing.T) *chainconfig.Config { return networkconfigTestdata.GetConfig(t) } diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index 717bcce72e..9ffe27ae37 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "strings" + "github.com/ignite/cli/ignite/config/chain" + "github.com/imdario/mergo" "golang.org/x/sync/errgroup" diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 8a449ccbd1..aab9b39a7e 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -2,10 +2,11 @@ package chain import ( "context" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" + "github.com/ignite/cli/ignite/config/chain" + "github.com/go-git/go-git/v5" "github.com/tendermint/spn/pkg/chainid" @@ -210,7 +211,7 @@ func (c *Chain) ConfigPath() string { } // Config returns the config of the chain -func (c *Chain) Config() (*chain.ChainConfig, error) { +func (c *Chain) Config() (*chain.Config, error) { configPath := c.ConfigPath() if configPath == "" { return chain.DefaultChainConfig(), nil diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 4849e30525..e8cb7dfbf5 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -3,10 +3,11 @@ package chain import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -347,7 +348,7 @@ func (c Chain) saveClientConfig(client base.Client) error { // values that otherwise would be initialized to defaults. // Defaults must be ignored to avoid writing them to the // YAML config file when they are not present. - var cfg chain.ChainConfig + var cfg chain.Config if err := cfg.Decode(file); err != nil { return err } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index c5628a9e0f..93feadd07d 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -2,11 +2,12 @@ package chain import ( "context" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" "strings" + "github.com/ignite/cli/ignite/config/chain" + "github.com/imdario/mergo" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" @@ -86,7 +87,7 @@ func (c *Chain) InitChain(ctx context.Context) error { } // InitAccounts initializes the chain accounts and creates validator gentxs -func (c *Chain) InitAccounts(ctx context.Context, cfg *chain.ChainConfig) error { +func (c *Chain) InitAccounts(ctx context.Context, cfg *chain.Config) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -222,7 +223,7 @@ type Account struct { Coins string } -func createValidatorFromConfig(conf *chain.ChainConfig) (validator Validator) { +func createValidatorFromConfig(conf *chain.Config) (validator Validator) { // Currently, we support the config file with one valid validator. validatorFromConfig := conf.Validators[0] validator.Name = validatorFromConfig.Name diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index af3befd5ba..9ceba5ab10 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -3,10 +3,11 @@ package chain import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" + "github.com/ignite/cli/ignite/config/chain" + sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/pelletier/go-toml" @@ -36,7 +37,7 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida } // Start wraps the "appd start" command to begin running a chain from the daemon -func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chain.ChainConfig) error { +func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chain.Config) error { validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { @@ -49,7 +50,7 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *cha } // Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml) -func (c Chain) Configure(homePath string, cfg *chain.ChainConfig) error { +func (c Chain) Configure(homePath string, cfg *chain.Config) error { if err := c.appTOML(homePath, cfg); err != nil { return err } @@ -59,7 +60,7 @@ func (c Chain) Configure(homePath string, cfg *chain.ChainConfig) error { return c.configTOML(homePath, cfg) } -func (c Chain) appTOML(homePath string, cfg *chain.ChainConfig) error { +func (c Chain) appTOML(homePath string, cfg *chain.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") config, err := toml.LoadFile(path) @@ -106,7 +107,7 @@ func (c Chain) appTOML(homePath string, cfg *chain.ChainConfig) error { return err } -func (c Chain) configTOML(homePath string, cfg *chain.ChainConfig) error { +func (c Chain) configTOML(homePath string, cfg *chain.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") config, err := toml.LoadFile(path) @@ -153,7 +154,7 @@ func (c Chain) configTOML(homePath string, cfg *chain.ChainConfig) error { return err } -func (c Chain) clientTOML(homePath string, cfg *chain.ChainConfig) error { +func (c Chain) clientTOML(homePath string, cfg *chain.Config) error { path := filepath.Join(homePath, "config/client.toml") config, err := toml.LoadFile(path) if os.IsNotExist(err) { diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 67464d8c8f..8bdaf5cf4a 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -3,7 +3,7 @@ package chain import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" + "net/http" "os" "os/exec" @@ -15,6 +15,8 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" + "github.com/ignite/cli/ignite/config" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cache" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -53,7 +55,7 @@ var ( // starportSavePath is the place where chain exported genesis are saved starportSavePath = xfilepath.Join( - chain.DirPath, + config.DirPath, xfilepath.Path("local-chains"), ) ) @@ -130,7 +132,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . if _, err := os.Stat(c.options.ConfigFile); err != nil { return err } - } else if _, err := chain.LocateDefault(c.app.Path); err != nil { + } else if _, err := chainconfig.LocateDefault(c.app.Path); err != nil { return err } @@ -160,7 +162,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . serveCtx context.Context buildErr *CannotBuildAppError startErr *CannotStartAppError - validationErr *chain.ValidationError + validationErr *chainconfig.ValidationError ) serveCtx, c.serveCancel = context.WithCancel(ctx) @@ -427,7 +429,7 @@ func (c *Chain) serve( return c.start(ctx, conf) } -func (c *Chain) start(ctx context.Context, cfg *chain.ChainConfig) error { +func (c *Chain) start(ctx context.Context, cfg *chainconfig.Config) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -485,7 +487,7 @@ func (c *Chain) start(ctx context.Context, cfg *chain.ChainConfig) error { ) if isFaucetEnabled { - faucetAddr, _ := xurl.HTTP(chain.FaucetHost(cfg)) + faucetAddr, _ := xurl.HTTP(chainconfig.FaucetHost(cfg)) c.ev.Send( fmt.Sprintf("Token faucet: %s", faucetAddr), @@ -503,7 +505,7 @@ func (c *Chain) runFaucetServer(ctx context.Context, faucet cosmosfaucet.Faucet) } return xhttp.Serve(ctx, &http.Server{ - Addr: chain.FaucetHost(cfg), + Addr: chainconfig.FaucetHost(cfg), Handler: faucet, }) } diff --git a/ignite/services/network/networkchain/binarycache.go b/ignite/services/network/networkchain/binarycache.go index b2a8556972..2df530f8c3 100644 --- a/ignite/services/network/networkchain/binarycache.go +++ b/ignite/services/network/networkchain/binarycache.go @@ -1,7 +1,7 @@ package networkchain import ( - "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config" "github.com/ignite/cli/ignite/pkg/checksum" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -78,7 +78,7 @@ func checkBinaryCacheForLaunchID(launchID uint64, binaryHash, sourceHash string) func getBinaryCacheFilepath() (string, error) { return xfilepath.Join( - chain.DirPath, + config.DirPath, xfilepath.Path(SPNCacheDirectory), xfilepath.Path(BinaryCacheDirectory), xfilepath.Path(BinaryCacheFilename), diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index 78ade77d36..fdeabf0810 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "path/filepath" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/pkg/cache" cosmosgenesis "github.com/ignite/cli/ignite/pkg/cosmosutil/genesis" "github.com/ignite/cli/ignite/pkg/events" diff --git a/ignite/services/network/networkchain/networkchain.go b/ignite/services/network/networkchain/networkchain.go index 617e721e86..944d7d59b4 100644 --- a/ignite/services/network/networkchain/networkchain.go +++ b/ignite/services/network/networkchain/networkchain.go @@ -3,11 +3,12 @@ package networkchain import ( "context" "errors" - chain2 "github.com/ignite/cli/ignite/config/chain" "os" "os/exec" "time" + chain2 "github.com/ignite/cli/ignite/config/chain" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 644909dbb9..638af0d6bf 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -6,7 +6,6 @@ package plugin import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "io/fs" "os" "os/exec" @@ -21,6 +20,7 @@ import ( hplugin "github.com/hashicorp/go-plugin" "github.com/pkg/errors" + "github.com/ignite/cli/ignite/config" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cliui" cliexec "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" @@ -32,7 +32,7 @@ import ( // pluginsPath holds the plugin cache directory. var pluginsPath = xfilepath.Join( - chain.DirPath, + config.DirPath, xfilepath.Path("plugins"), ) diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index e54af9e3f1..0d8cb762c1 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -4,9 +4,10 @@ package scaffolder import ( "context" - "github.com/ignite/cli/ignite/config/chain" "path/filepath" + "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cosmosanalysis" "github.com/ignite/cli/ignite/pkg/cosmosgen" diff --git a/ignite/version/version.go b/ignite/version/version.go index 9e5bf1980f..8d5acc9aeb 100644 --- a/ignite/version/version.go +++ b/ignite/version/version.go @@ -4,13 +4,14 @@ import ( "bytes" "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "runtime" "runtime/debug" "strings" "text/tabwriter" + "github.com/ignite/cli/ignite/config/chain" + "github.com/blang/semver/v4" "github.com/google/go-github/v48/github" diff --git a/integration/app.go b/integration/app.go index 3acb71cb5d..7cb0af54d8 100644 --- a/integration/app.go +++ b/integration/app.go @@ -2,7 +2,6 @@ package envtest import ( "fmt" - "github.com/ignite/cli/ignite/config/chain" "os" "path" "path/filepath" @@ -12,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" + "github.com/ignite/cli/ignite/config/chain" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -187,7 +187,7 @@ func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string) { port, err := availableport.Find(1) require.NoError(a.env.t, err) - a.EditConfig(func(c *chain.ChainConfig) { + a.EditConfig(func(c *chain.Config) { c.Faucet.Port = port[0] c.Faucet.Coins = coins c.Faucet.CoinsMax = coinsMax @@ -219,7 +219,7 @@ func (a App) RandomizeServerPorts() Hosts { API: genAddr(ports[5]), } - a.EditConfig(func(c *chain.ChainConfig) { + a.EditConfig(func(c *chain.Config) { v := &c.Validators[0] s := v1.Servers{} @@ -241,24 +241,24 @@ func (a App) RandomizeServerPorts() Hosts { func (a App) UseRandomHomeDir() (homeDirPath string) { dir := a.env.TmpDir() - a.EditConfig(func(c *chain.ChainConfig) { + a.EditConfig(func(c *chain.Config) { c.Validators[0].Home = dir }) return dir } -func (a App) Config() chain.ChainConfig { +func (a App) Config() chain.Config { bz, err := os.ReadFile(a.configPath) require.NoError(a.env.t, err) - var conf chain.ChainConfig + var conf chain.Config err = yaml.Unmarshal(bz, &conf) require.NoError(a.env.t, err) return conf } -func (a App) EditConfig(apply func(*chain.ChainConfig)) { +func (a App) EditConfig(apply func(*chain.Config)) { conf := a.Config() apply(&conf) diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index aa5b017dad..bf3e4fa143 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -5,10 +5,11 @@ package chain_test import ( "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "path/filepath" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/pkg/confile" @@ -26,7 +27,7 @@ func TestOverwriteSDKConfigsAndChainID(t *testing.T) { isBackendAliveErr error ) - var cfg chain.ChainConfig + var cfg chain.Config cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml")) require.NoError(t, cf.Load(&cfg)) diff --git a/integration/client.go b/integration/client.go index a8e70fb3b1..ea413ad33d 100644 --- a/integration/client.go +++ b/integration/client.go @@ -2,12 +2,13 @@ package envtest import ( "bytes" - "github.com/ignite/cli/ignite/config/chain" "os" "os/exec" "path/filepath" "runtime" + "github.com/ignite/cli/ignite/config/chain" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/pkg/cmdrunner" diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index b198c72e96..2a2d6bcc90 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "fmt" - "github.com/ignite/cli/ignite/config/chain" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config/chain/base" @@ -58,7 +59,7 @@ func TestBankModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chain.ChainConfig) { + app.EditConfig(func(cfg *chain.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index b4fdb10527..1b684e6cce 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "fmt" - "github.com/ignite/cli/ignite/config/chain" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/config/chain/base" @@ -41,7 +42,7 @@ func TestCustomModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chain.ChainConfig) { + app.EditConfig(func(cfg *chain.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 1fc48bc3f1..72c796d657 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -3,13 +3,14 @@ package network_test import ( "bytes" "context" - "github.com/ignite/cli/ignite/config/chain" "os" "path" "path/filepath" "strings" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/blang/semver/v4" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" @@ -84,7 +85,7 @@ func migrateSPNConfig(t *testing.T, spnPath string) { defer file.Close() - err = chain.MigrateLatest(bytes.NewReader(rawCfg), file) + err = version.MigrateLatest(bytes.NewReader(rawCfg), file) require.NoError(t, err) } } diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 90e0ebe007..6dfc621950 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -3,11 +3,12 @@ package node_test import ( "bytes" "context" - "github.com/ignite/cli/ignite/config/chain" "path/filepath" "strings" "testing" + "github.com/ignite/cli/ignite/config/chain" + "github.com/cosmos/cosmos-sdk/crypto/keyring" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" @@ -65,7 +66,7 @@ func TestNodeQueryBankBalances(t *testing.T) { aliceAccount, aliceMnemonic, err := ca.Create(alice) require.NoError(t, err) - app.EditConfig(func(c *chain.ChainConfig) { + app.EditConfig(func(c *chain.Config) { c.Accounts = []base.Account{ { Name: alice, diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 7b9f4992e3..452b745946 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/ignite/cli/ignite/config/chain" "path/filepath" "testing" "time" + "github.com/ignite/cli/ignite/config/chain" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/stretchr/testify/require" @@ -56,7 +57,7 @@ func TestNodeTxBankSend(t *testing.T) { bobAccount, bobMnemonic, err := ca.Create(bob) require.NoError(t, err) - app.EditConfig(func(c *chain.ChainConfig) { + app.EditConfig(func(c *chain.Config) { c.Accounts = []base.Account{ { Name: alice, From f5c490d20f27601abf48ff4c39175fe4444d5ba6 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:43:35 -0500 Subject: [PATCH 37/80] fix tests --- ignite/config/chain/parse_test.go | 32 ++++++++++++++++--------------- ignite/services/chain/serve.go | 1 - 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ignite/config/chain/parse_test.go b/ignite/config/chain/parse_test.go index 9c36a7d201..3a15d69b84 100644 --- a/ignite/config/chain/parse_test.go +++ b/ignite/config/chain/parse_test.go @@ -8,16 +8,18 @@ import ( "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" + "github.com/ignite/cli/ignite/config/chain/version" "github.com/ignite/cli/ignite/config/testdata" ) func TestReadConfigVersion(t *testing.T) { // Arrange r := strings.NewReader("version: 42") - want := Version(42) + want := version.Version(42) // Act - version, err := ReadConfigVersion(r) + version, err := chainconfig.ReadConfigVersion(r) // Assert require.NoError(t, err) @@ -26,42 +28,42 @@ func TestReadConfigVersion(t *testing.T) { func TestParse(t *testing.T) { // Arrange: Initialize a reader with the previous version - ver := LatestVersion - 1 + ver := chainconfig.LatestVersion - 1 r := bytes.NewReader(testdata.Versions[ver]) // Act - cfg, err := Parse(r) + cfg, err := chainconfig.Parse(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, LatestVersion, cfg.Version) + require.Equal(t, chainconfig.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } func TestParseWithCurrentVersion(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[LatestVersion]) + r := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion]) // Act - cfg, err := Parse(r) + cfg, err := chainconfig.Parse(r) // Assert require.NoError(t, err) - require.Equal(t, LatestVersion, cfg.Version) + require.Equal(t, chainconfig.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestConfig(t), cfg) } func TestParseWithUnknownVersion(t *testing.T) { // Arrange - version := Version(9999) + version := version.Version(9999) r := strings.NewReader(fmt.Sprintf("version: %d", version)) - var want *UnsupportedVersionError + var want *chainconfig.UnsupportedVersionError // Act - _, err := Parse(r) + _, err := chainconfig.Parse(r) // Assert require.ErrorAs(t, err, &want) @@ -74,23 +76,23 @@ func TestParseNetworkWithCurrentVersion(t *testing.T) { r := bytes.NewReader(testdata.NetworkConfig) // Act - cfg, err := ParseNetwork(r) + cfg, err := chainconfig.ParseNetwork(r) // Assert require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, LatestVersion, cfg.Version) + require.Equal(t, chainconfig.LatestVersion, cfg.Version) require.Equal(t, testdata.GetLatestNetworkConfig(t).Accounts, cfg.Accounts) require.Equal(t, testdata.GetLatestNetworkConfig(t).Genesis, cfg.Genesis) } func TestParseNetworkWithInvalidData(t *testing.T) { // Arrange - r := bytes.NewReader(testdata.Versions[LatestVersion]) + r := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion]) // Act - _, err := ParseNetwork(r) + _, err := chainconfig.ParseNetwork(r) // Assert error require.True( diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 8bdaf5cf4a..3537d04823 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -3,7 +3,6 @@ package chain import ( "context" "fmt" - "net/http" "os" "os/exec" From 69ca93494bd3d9f4197516bad933b28ee260fed8 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:49:17 -0500 Subject: [PATCH 38/80] fix test --- integration/network/network_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 72c796d657..4c94615f42 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -9,13 +9,12 @@ import ( "strings" "testing" - "github.com/ignite/cli/ignite/config/chain" - "github.com/blang/semver/v4" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gomodule" envtest "github.com/ignite/cli/integration" @@ -75,17 +74,17 @@ func migrateSPNConfig(t *testing.T, spnPath string) { rawCfg, err := os.ReadFile(configPath) require.NoError(t, err) - version, err := chain.ReadConfigVersion(bytes.NewReader(rawCfg)) + version, err := chainconfig.ReadConfigVersion(bytes.NewReader(rawCfg)) require.NoError(t, err) - if version != chain.LatestVersion { - t.Logf("migrating spn config from v%d to v%d", version, chain.LatestVersion) + if version != chainconfig.LatestVersion { + t.Logf("migrating spn config from v%d to v%d", version, chainconfig.LatestVersion) file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755) require.NoError(t, err) defer file.Close() - err = version.MigrateLatest(bytes.NewReader(rawCfg), file) + err = chainconfig.MigrateLatest(bytes.NewReader(rawCfg), file) require.NoError(t, err) } } From 290d98365b27e5657fe5aa040748149a4c9011f5 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 12:53:38 -0500 Subject: [PATCH 39/80] rename --- ignite/config/plugins/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 2bdffbd540..bf963f0200 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -9,8 +9,8 @@ import ( "gopkg.in/yaml.v2" ) -// PluginsConfigFilenames is a list of recognized names as Ignite's plugins config file. -var PluginsConfigFilenames = []string{"plugins.yml", "plugins.yaml"} +// ConfigFilenames is a list of recognized names as Ignite's plugins config file. +var ConfigFilenames = []string{"plugins.yml", "plugins.yaml"} // DefaultConfig returns a config with default values. func DefaultConfig() *Config { @@ -21,7 +21,7 @@ func DefaultConfig() *Config { // LocateDefault locates the default path for the config file. // Returns ErrConfigNotFound when no config file found. func LocateDefault(root string) (path string, err error) { - for _, name := range PluginsConfigFilenames { + for _, name := range ConfigFilenames { path = filepath.Join(root, name) if _, err := os.Stat(path); err == nil { return path, nil From bc69558d99c6fa1182c63a862ef8616502f5d70c Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 13:31:29 -0500 Subject: [PATCH 40/80] add global --- ignite/cmd/plugin.go | 49 ++++++++++++++++++++++++++------ ignite/config/config.go | 6 ++-- ignite/services/plugin/plugin.go | 6 ++-- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index a041db2522..98d70d9bee 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -16,34 +16,49 @@ import ( "github.com/ignite/cli/ignite/services/plugin" ) -// plugins hold the list of plugin declared in the config. -// A global variable is used so the list is accessible to the plugin commands. -var plugins []*plugin.Plugin - const ( igniteCmdPrefix = "ignite " ) +var ( + // plugins hold the list of plugin declared in the config. + // A global variable is used so the list is accessible to the plugin commands. + plugins []*plugin.Plugin +) + // LoadPlugins tries to load all the plugins found in configuration. // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { // NOTE(tb) Not sure if it's the right place to load this. - cfg, err := parseLocalPlugins(rootCmd) + localCfg, err := parseLocalConfig(rootCmd) if err != nil { // if binary is run where there is no plugin.yml, don't load return nil } - // TODO: parse global config + localPlugins, err := plugin.Load(ctx, localCfg) + if err != nil { + return err + } + + globalCfg, err := parseGlobalConfig(rootCmd) + if err != nil { + return nil + } - plugins, err = plugin.Load(ctx, cfg) + globalPlugins, err := plugin.Load(ctx, globalCfg) if err != nil { return err } + + plugins = append(localPlugins, globalPlugins...) + + // TODO: sort duplicates + return loadPlugins(rootCmd, plugins) } -func parseLocalPlugins(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { +func parseLocalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { appPath := flagGetPath(rootCmd) pluginsPath := getPlugins(rootCmd) if pluginsPath == "" { @@ -57,6 +72,24 @@ func parseLocalPlugins(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err e return cfg, err } +func parseGlobalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { + globalPath, err := plugin.PluginsPath() + if err != nil { + return cfg, err + } + + pluginsPath := getPlugins(rootCmd) + if pluginsPath == "" { + if pluginsPath, err = pluginsconfig.LocateDefault(globalPath); err != nil { + return cfg, err + } + } + + cfg, err = pluginsconfig.ParseFile(pluginsPath) + + return cfg, err +} + func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { // Link plugins to related commands var loadErrors []string diff --git a/ignite/config/config.go b/ignite/config/config.go index 2217fa486a..790f500f86 100644 --- a/ignite/config/config.go +++ b/ignite/config/config.go @@ -6,8 +6,10 @@ import ( "github.com/ignite/cli/ignite/pkg/xfilepath" ) -// DirPath returns the path of configuration directory of Ignite. -var DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) +var ( + // DirPath returns the path of configuration directory of Ignite. + DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) +) // CreateConfigDir creates config directory if it is not created yet. func CreateConfigDir() error { diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 638af0d6bf..b37f4beb30 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -30,8 +30,8 @@ import ( "github.com/ignite/cli/ignite/pkg/xfilepath" ) -// pluginsPath holds the plugin cache directory. -var pluginsPath = xfilepath.Join( +// PluginsPath holds the plugin cache directory. +var PluginsPath = xfilepath.Join( config.DirPath, xfilepath.Path("plugins"), ) @@ -68,7 +68,7 @@ type Plugin struct { // in the Plugin.Error field. This prevents the loading of other plugins to be // interrupted. func Load(ctx context.Context, cfg *pluginsconfig.Config) ([]*Plugin, error) { - pluginsDir, err := pluginsPath() + pluginsDir, err := PluginsPath() if err != nil { return nil, errors.WithStack(err) } From 681159224c047a1ac81ea71e0dcb035ef0f20535 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 18:45:36 -0500 Subject: [PATCH 41/80] functionality --- ignite/cmd/ignite/main.go | 2 +- ignite/cmd/plugin.go | 42 +++++++++++++++++--------------- ignite/config/plugins/parse.go | 1 - ignite/services/plugin/plugin.go | 1 - 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 4f05e0ad74..19b2412666 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -28,7 +28,7 @@ func run() int { // Load plugins if any if err := ignitecmd.LoadPlugins(ctx, cmd); err != nil { - fmt.Printf("Error while loading chain's plugins: %v\n", err) + fmt.Printf("Error while loading plugins: %v\n", err) return exitCodeError } defer ignitecmd.UnloadPlugins() diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 98d70d9bee..3b9e5d5acc 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -29,29 +29,35 @@ var ( // LoadPlugins tries to load all the plugins found in configuration. // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { + var ( + localPlugins []*plugin.Plugin + globalPlugins []*plugin.Plugin + ) + // NOTE(tb) Not sure if it's the right place to load this. localCfg, err := parseLocalConfig(rootCmd) - if err != nil { - // if binary is run where there is no plugin.yml, don't load - return nil - } - - localPlugins, err := plugin.Load(ctx, localCfg) - if err != nil { - return err + // if binary is run where there is no cfg, don't load + if err == nil { + localPlugins, err = plugin.Load(ctx, localCfg) + if err != nil { + return err + } } globalCfg, err := parseGlobalConfig(rootCmd) - if err != nil { - return nil - } + // if binary is run where there is no cfg, don't load + if err == nil { + globalPlugins, err = plugin.Load(ctx, globalCfg) + if err != nil { + return err + } - globalPlugins, err := plugin.Load(ctx, globalCfg) - if err != nil { - return err } plugins = append(localPlugins, globalPlugins...) + if len(plugins) == 0 { + return nil + } // TODO: sort duplicates @@ -67,9 +73,7 @@ func parseLocalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err er } } - cfg, err = pluginsconfig.ParseFile(pluginsPath) - - return cfg, err + return pluginsconfig.ParseFile(pluginsPath) } func parseGlobalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { @@ -85,9 +89,7 @@ func parseGlobalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err e } } - cfg, err = pluginsconfig.ParseFile(pluginsPath) - - return cfg, err + return pluginsconfig.ParseFile(pluginsPath) } func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { diff --git a/ignite/config/plugins/parse.go b/ignite/config/plugins/parse.go index 33c9940aea..d1c8efed6e 100644 --- a/ignite/config/plugins/parse.go +++ b/ignite/config/plugins/parse.go @@ -28,6 +28,5 @@ func parse(configFile io.Reader) (*Config, error) { var c Config err := yaml.NewDecoder(configFile).Decode(&c) - return &c, err } diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index b37f4beb30..887c64f933 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -77,7 +77,6 @@ func Load(ctx context.Context, cfg *pluginsconfig.Config) ([]*Plugin, error) { p := newPlugin(pluginsDir, cp) p.load(ctx) - // TODO: override global plugins with locally defined ones plugins = append(plugins, p) } return plugins, nil From ce5d761a2ec66702c3938617978a4cb52ce478c6 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 18:46:31 -0500 Subject: [PATCH 42/80] format --- ignite/cmd/plugin.go | 9 ++++----- ignite/config/config.go | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 3b9e5d5acc..73cd5fa353 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -20,11 +20,9 @@ const ( igniteCmdPrefix = "ignite " ) -var ( - // plugins hold the list of plugin declared in the config. - // A global variable is used so the list is accessible to the plugin commands. - plugins []*plugin.Plugin -) +// plugins hold the list of plugin declared in the config. +// A global variable is used so the list is accessible to the plugin commands. +var plugins []*plugin.Plugin // LoadPlugins tries to load all the plugins found in configuration. // If no configuration found, it returns w/o error. @@ -54,6 +52,7 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { } + // nolint: appendAssign plugins = append(localPlugins, globalPlugins...) if len(plugins) == 0 { return nil diff --git a/ignite/config/config.go b/ignite/config/config.go index 790f500f86..2217fa486a 100644 --- a/ignite/config/config.go +++ b/ignite/config/config.go @@ -6,10 +6,8 @@ import ( "github.com/ignite/cli/ignite/pkg/xfilepath" ) -var ( - // DirPath returns the path of configuration directory of Ignite. - DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) -) +// DirPath returns the path of configuration directory of Ignite. +var DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) // CreateConfigDir creates config directory if it is not created yet. func CreateConfigDir() error { From a368b6a4cde5e1d374f85b044c079eec5238f549 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 18:50:43 -0500 Subject: [PATCH 43/80] fix error statement for global plugins --- ignite/cmd/ignite/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 4f05e0ad74..19b2412666 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -28,7 +28,7 @@ func run() int { // Load plugins if any if err := ignitecmd.LoadPlugins(ctx, cmd); err != nil { - fmt.Printf("Error while loading chain's plugins: %v\n", err) + fmt.Printf("Error while loading plugins: %v\n", err) return exitCodeError } defer ignitecmd.UnloadPlugins() From 6579c11118ab9e0138290f81f7f1e1d8e8f168ce Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 19:07:38 -0500 Subject: [PATCH 44/80] typo --- ignite/cmd/chain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index e36e8e1611..27801b7c41 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -122,7 +122,7 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error) prefix := fmt.Sprintf(msgMigrationPrefix, version, chainconfig.LatestVersion) question := fmt.Sprintf(msgMigrationPrompt, chainconfig.LatestVersion) - // Confirm before overwritting the config file + // Confirm before overwriting the config file session.Println(prefix) if err := session.AskConfirm(question); err != nil { if errors.Is(err, promptui.ErrAbort) { From dcdaa2dd512baf1ee3e8d4b9b25afa65e9cf96ae Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 19:10:30 -0500 Subject: [PATCH 45/80] chainconfig --- ignite/cmd/ignite/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index 19b2412666..200dd8e461 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -7,7 +7,7 @@ import ( "os" ignitecmd "github.com/ignite/cli/ignite/cmd" - "github.com/ignite/cli/ignite/config/chain" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/clictx" "github.com/ignite/cli/ignite/pkg/validation" "github.com/ignite/cli/ignite/pkg/xstrings" @@ -43,7 +43,7 @@ func run() int { if err != nil { var ( validationErr validation.Error - versionErr chain.VersionError + versionErr chainconfig.VersionError msg string ) From e7b53a7922d824f62de437e42ffdb4e51cd64980 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 19:21:19 -0500 Subject: [PATCH 46/80] imports --- ignite/cmd/scaffold_react.go | 5 ++--- ignite/cmd/scaffold_vue.go | 5 ++--- ignite/config/chain/base/config.go | 1 - ignite/config/chain/config.go | 3 +-- ignite/config/chain/config_test.go | 4 ++-- ignite/config/chain/convert_test.go | 12 ++++++------ ignite/config/chain/parse.go | 4 ++-- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ignite/cmd/scaffold_react.go b/ignite/cmd/scaffold_react.go index 3a745bfd8e..5d8cf77ca5 100644 --- a/ignite/cmd/scaffold_react.go +++ b/ignite/cmd/scaffold_react.go @@ -3,8 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config/chain" - + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -20,7 +19,7 @@ func NewScaffoldReact() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+chain.DefaultReactPath, "path to scaffold content of the React app") + c.Flags().StringP(flagPath, "p", "./"+chainconfig.DefaultReactPath, "path to scaffold content of the React app") return c } diff --git a/ignite/cmd/scaffold_vue.go b/ignite/cmd/scaffold_vue.go index 32ebcc6f52..82b9435adf 100644 --- a/ignite/cmd/scaffold_vue.go +++ b/ignite/cmd/scaffold_vue.go @@ -3,8 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" - "github.com/ignite/cli/ignite/config/chain" - + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/cosmosgen" ) @@ -20,7 +19,7 @@ func NewScaffoldVue() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().StringP(flagPath, "p", "./"+chain.DefaultVuePath, "path to scaffold content of the Vue.js app") + c.Flags().StringP(flagPath, "p", "./"+chainconfig.DefaultVuePath, "path to scaffold content of the Vue.js app") return c } diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index e5fe84531e..d6b7842f8e 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -4,7 +4,6 @@ import ( "github.com/imdario/mergo" "github.com/ignite/cli/ignite/config/chain/version" - xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) diff --git a/ignite/config/chain/config.go b/ignite/config/chain/config.go index 7a17e9b268..59568901c1 100644 --- a/ignite/config/chain/config.go +++ b/ignite/config/chain/config.go @@ -7,12 +7,11 @@ import ( "path/filepath" "strings" - "github.com/ignite/cli/ignite/config/chain/version" - "gopkg.in/yaml.v2" v0 "github.com/ignite/cli/ignite/config/chain/v0" v1 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/ignite/cli/ignite/config/chain/version" ) var ( diff --git a/ignite/config/chain/config_test.go b/ignite/config/chain/config_test.go index dd1b170279..651b329143 100644 --- a/ignite/config/chain/config_test.go +++ b/ignite/config/chain/config_test.go @@ -5,10 +5,10 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/version" - - "github.com/stretchr/testify/require" ) func TestCheckVersion(t *testing.T) { diff --git a/ignite/config/chain/convert_test.go b/ignite/config/chain/convert_test.go index c7a9f74f31..3b431bd58d 100644 --- a/ignite/config/chain/convert_test.go +++ b/ignite/config/chain/convert_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ignite/cli/ignite/config/chain" + chainconfig "github.com/ignite/cli/ignite/config/chain" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" "github.com/ignite/cli/ignite/config/testdata" ) @@ -16,22 +16,22 @@ func TestConvertLatest(t *testing.T) { cfgV0 := v0testdata.GetConfig(t) // Act - cfgLatest, err := chain.ConvertLatest(cfgV0) + cfgLatest, err := chainconfig.ConvertLatest(cfgV0) // Assert require.NoError(t, err) - require.Equal(t, chain.LatestVersion, cfgLatest.GetVersion()) + require.Equal(t, chainconfig.LatestVersion, cfgLatest.GetVersion()) require.Equal(t, testdata.GetLatestConfig(t), cfgLatest) } func TestMigrateLatest(t *testing.T) { // Arrange - current := bytes.NewReader(testdata.Versions[chain.LatestVersion-1]) + current := bytes.NewReader(testdata.Versions[chainconfig.LatestVersion-1]) latest := bytes.Buffer{} - want := string(testdata.Versions[chain.LatestVersion]) + want := string(testdata.Versions[chainconfig.LatestVersion]) // Act - err := chain.MigrateLatest(current, &latest) + err := chainconfig.MigrateLatest(current, &latest) // Assert require.NotEmpty(t, want, "testdata is missing the latest config version") diff --git a/ignite/config/chain/parse.go b/ignite/config/chain/parse.go index 3a80937c13..bb8c535abd 100644 --- a/ignite/config/chain/parse.go +++ b/ignite/config/chain/parse.go @@ -6,10 +6,10 @@ import ( "io" "os" - "github.com/ignite/cli/ignite/config/chain/version" - "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v2" + + "github.com/ignite/cli/ignite/config/chain/version" ) // Parse reads a config file. From d5da513edeb3f2a14142445ffcd633bfdbe64bcf Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 29 Nov 2022 19:34:29 -0500 Subject: [PATCH 47/80] fix imports --- ignite/config/chain/v0/config.go | 3 +-- ignite/config/chain/v0/config_convert_test.go | 3 +-- ignite/config/chain/v1/config.go | 3 +-- ignite/config/testdata/testdata.go | 6 ++---- ignite/pkg/cosmosgen/generate_vuex.go | 5 ++--- ignite/services/chain/chain.go | 11 +++++------ ignite/services/chain/generate.go | 17 ++++++++--------- ignite/services/chain/init.go | 7 +++---- ignite/services/chain/runtime.go | 13 ++++++------- ignite/services/network/networkchain/init.go | 5 ++--- .../network/networkchain/networkchain.go | 7 +++---- ignite/services/scaffolder/scaffolder.go | 9 ++++----- ignite/version/version.go | 5 ++--- integration/app.go | 14 +++++++------- integration/chain/config_test.go | 5 ++--- integration/client.go | 7 +++---- integration/cosmosgen/bank_module_test.go | 5 ++--- integration/cosmosgen/custom_module_test.go | 5 ++--- integration/node/cmd_query_bank_test.go | 5 ++--- integration/node/cmd_tx_bank_send_test.go | 5 ++--- 20 files changed, 60 insertions(+), 80 deletions(-) diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index f319a6f6a7..8f25d1561c 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -3,12 +3,11 @@ package v0 import ( "io" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" - "github.com/imdario/mergo" "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config/chain/base" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" ) // Config is the user given configuration to do additional setup during serve. diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 56342242e4..3760b97188 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -3,12 +3,11 @@ package v0_test import ( "testing" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" - "github.com/stretchr/testify/require" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" ) func TestV0ToV1(t *testing.T) { diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 1bd28901a4..94e9f1f541 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -3,12 +3,11 @@ package v1 import ( "io" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" - "github.com/imdario/mergo" "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config/chain/base" + chainconfig "github.com/ignite/cli/ignite/config/chain/version" "github.com/ignite/cli/ignite/pkg/xnet" ) diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index eea7c283e8..e00ca241de 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -3,14 +3,12 @@ package testdata import ( "testing" - "github.com/ignite/cli/ignite/config/chain/version" - - pluginsconfig "github.com/ignite/cli/ignite/config/plugins" - chainconfig "github.com/ignite/cli/ignite/config/chain" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" + "github.com/ignite/cli/ignite/config/chain/version" + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" pluginsconfigTestdata "github.com/ignite/cli/ignite/config/plugins/testdata" ) diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index 9ffe27ae37..35ff5ebf86 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -8,11 +8,10 @@ import ( "path/filepath" "strings" - "github.com/ignite/cli/ignite/config/chain" - "github.com/imdario/mergo" "golang.org/x/sync/errgroup" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" "github.com/ignite/cli/ignite/pkg/gomodulepath" ) @@ -27,7 +26,7 @@ func newVuexGenerator(g *generator) *vuexGenerator { func (g *generator) updateVueDependencies() error { // Init the path to the "vue" folders inside the app - vuePath := filepath.Join(g.appPath, chain.DefaultVuePath) + vuePath := filepath.Join(g.appPath, chainconfig.DefaultVuePath) packagesPath := filepath.Join(vuePath, "package.json") if _, err := os.Stat(packagesPath); errors.Is(err, os.ErrNotExist) { return nil diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index aab9b39a7e..75da847a26 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -5,11 +5,10 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/config/chain" - "github.com/go-git/go-git/v5" "github.com/tendermint/spn/pkg/chainid" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -203,7 +202,7 @@ func (c *Chain) ConfigPath() string { if c.options.ConfigFile != "" { return c.options.ConfigFile } - path, err := chain.LocateDefault(c.app.Path) + path, err := chainconfig.LocateDefault(c.app.Path) if err != nil { return "" } @@ -211,12 +210,12 @@ func (c *Chain) ConfigPath() string { } // Config returns the config of the chain -func (c *Chain) Config() (*chain.Config, error) { +func (c *Chain) Config() (*chainconfig.Config, error) { configPath := c.ConfigPath() if configPath == "" { - return chain.DefaultChainConfig(), nil + return chainconfig.DefaultChainConfig(), nil } - return chain.ParseFile(configPath) + return chainconfig.ParseFile(configPath) } // ID returns the chain's id. diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index e8cb7dfbf5..d11f79325b 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -6,8 +6,7 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/config/chain" - + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cliui/icons" @@ -159,7 +158,7 @@ func (c *Chain) Generate( if targetOptions.isTSClientEnabled { tsClientPath = targetOptions.tsClientPath if tsClientPath == "" { - tsClientPath = chain.TSClientPath(*conf) + tsClientPath = chainconfig.TSClientPath(*conf) // When TS client is generated make sure the config is updated // with the output path when the client path option is empty. @@ -186,7 +185,7 @@ func (c *Chain) Generate( //nolint:staticcheck //ignore SA1019 until vuex config option is removed vuexPath = targetOptions.vuexPath if vuexPath == "" { - vuexPath = chain.VuexPath(conf) + vuexPath = chainconfig.VuexPath(conf) // When Vuex stores are generated make sure the config is updated // with the output path when the client path option is empty. @@ -212,7 +211,7 @@ func (c *Chain) Generate( composablesPath = targetOptions.composablesPath if composablesPath == "" { - composablesPath = chain.ComposablesPath(conf) + composablesPath = chainconfig.ComposablesPath(conf) if conf.Client.Composables.Path == "" { conf.Client.Composables.Path = composablesPath @@ -236,7 +235,7 @@ func (c *Chain) Generate( if targetOptions.isHooksEnabled { hooksPath = targetOptions.hooksPath if hooksPath == "" { - hooksPath = chain.HooksPath(conf) + hooksPath = chainconfig.HooksPath(conf) if conf.Client.Hooks.Path == "" { conf.Client.Hooks.Path = hooksPath @@ -260,7 +259,7 @@ func (c *Chain) Generate( if targetOptions.isOpenAPIEnabled { openAPIPath = conf.Client.OpenAPI.Path if openAPIPath == "" { - openAPIPath = chain.DefaultOpenAPIPath + openAPIPath = chainconfig.DefaultOpenAPIPath } // Non absolute OpenAPI paths must be treated as relative to the app directory @@ -348,12 +347,12 @@ func (c Chain) saveClientConfig(client base.Client) error { // values that otherwise would be initialized to defaults. // Defaults must be ignored to avoid writing them to the // YAML config file when they are not present. - var cfg chain.Config + var cfg chainconfig.Config if err := cfg.Decode(file); err != nil { return err } cfg.Client = client - return chain.Save(cfg, path) + return chainconfig.Save(cfg, path) } diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index 93feadd07d..4f1d76786c 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -6,10 +6,9 @@ import ( "path/filepath" "strings" - "github.com/ignite/cli/ignite/config/chain" - "github.com/imdario/mergo" + chainconfig "github.com/ignite/cli/ignite/config/chain" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/view/accountview" "github.com/ignite/cli/ignite/pkg/confile" @@ -87,7 +86,7 @@ func (c *Chain) InitChain(ctx context.Context) error { } // InitAccounts initializes the chain accounts and creates validator gentxs -func (c *Chain) InitAccounts(ctx context.Context, cfg *chain.Config) error { +func (c *Chain) InitAccounts(ctx context.Context, cfg *chainconfig.Config) error { commands, err := c.Commands(ctx) if err != nil { return err @@ -223,7 +222,7 @@ type Account struct { Coins string } -func createValidatorFromConfig(conf *chain.Config) (validator Validator) { +func createValidatorFromConfig(conf *chainconfig.Config) (validator Validator) { // Currently, we support the config file with one valid validator. validatorFromConfig := conf.Validators[0] validator.Name = validatorFromConfig.Name diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index 9ceba5ab10..2ad3d096c1 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -6,11 +6,10 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/config/chain" - sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/pelletier/go-toml" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/xurl" @@ -37,7 +36,7 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida } // Start wraps the "appd start" command to begin running a chain from the daemon -func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chain.Config) error { +func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chainconfig.Config) error { validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { @@ -50,7 +49,7 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *cha } // Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml) -func (c Chain) Configure(homePath string, cfg *chain.Config) error { +func (c Chain) Configure(homePath string, cfg *chainconfig.Config) error { if err := c.appTOML(homePath, cfg); err != nil { return err } @@ -60,7 +59,7 @@ func (c Chain) Configure(homePath string, cfg *chain.Config) error { return c.configTOML(homePath, cfg) } -func (c Chain) appTOML(homePath string, cfg *chain.Config) error { +func (c Chain) appTOML(homePath string, cfg *chainconfig.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") config, err := toml.LoadFile(path) @@ -107,7 +106,7 @@ func (c Chain) appTOML(homePath string, cfg *chain.Config) error { return err } -func (c Chain) configTOML(homePath string, cfg *chain.Config) error { +func (c Chain) configTOML(homePath string, cfg *chainconfig.Config) error { // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") config, err := toml.LoadFile(path) @@ -154,7 +153,7 @@ func (c Chain) configTOML(homePath string, cfg *chain.Config) error { return err } -func (c Chain) clientTOML(homePath string, cfg *chain.Config) error { +func (c Chain) clientTOML(homePath string, cfg *chainconfig.Config) error { path := filepath.Join(homePath, "config/client.toml") config, err := toml.LoadFile(path) if os.IsNotExist(err) { diff --git a/ignite/services/network/networkchain/init.go b/ignite/services/network/networkchain/init.go index fdeabf0810..bc3a06cc36 100644 --- a/ignite/services/network/networkchain/init.go +++ b/ignite/services/network/networkchain/init.go @@ -7,8 +7,7 @@ import ( "os" "path/filepath" - "github.com/ignite/cli/ignite/config/chain" - + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cache" cosmosgenesis "github.com/ignite/cli/ignite/pkg/cosmosutil/genesis" "github.com/ignite/cli/ignite/pkg/events" @@ -125,7 +124,7 @@ func (c *Chain) initGenesis(ctx context.Context) error { return fmt.Errorf("the config for genesis doesn't exist: %w", err) } - config, err := chain.ParseNetworkFile(path) + config, err := chainconfig.ParseNetworkFile(path) if err != nil { return err } diff --git a/ignite/services/network/networkchain/networkchain.go b/ignite/services/network/networkchain/networkchain.go index 944d7d59b4..a66fa98133 100644 --- a/ignite/services/network/networkchain/networkchain.go +++ b/ignite/services/network/networkchain/networkchain.go @@ -7,12 +7,11 @@ import ( "os/exec" "time" - chain2 "github.com/ignite/cli/ignite/config/chain" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/chaincmd" "github.com/ignite/cli/ignite/pkg/checksum" @@ -288,7 +287,7 @@ func (c Chain) NodeID(ctx context.Context) (string, error) { func (c Chain) CheckConfigVersion() error { configPath := c.chain.ConfigPath() if configPath == "" { - return chain2.ErrConfigNotFound + return chainconfig.ErrConfigNotFound } file, err := os.Open(configPath) @@ -298,7 +297,7 @@ func (c Chain) CheckConfigVersion() error { defer file.Close() - return chain2.CheckVersion(file) + return chainconfig.CheckVersion(file) } // Build builds chain sources, also checks if source was already built diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 0d8cb762c1..b6b45bbc4a 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -6,8 +6,7 @@ import ( "context" "path/filepath" - "github.com/ignite/cli/ignite/config/chain" - + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cosmosanalysis" "github.com/ignite/cli/ignite/pkg/cosmosgen" @@ -77,11 +76,11 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP return err } - confpath, err := chain.LocateDefault(projectPath) + confpath, err := chainconfig.LocateDefault(projectPath) if err != nil { return err } - conf, err := chain.ParseFile(confpath) + conf, err := chainconfig.ParseFile(confpath) if err != nil { return err } @@ -93,7 +92,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP // Generate Typescript client code if it's enabled or when Vuex stores are generated if conf.Client.Typescript.Path != "" || conf.Client.Vuex.Path != "" { //nolint:staticcheck //ignore SA1019 until vuex config option is removed - tsClientPath := chain.TSClientPath(*conf) + tsClientPath := chainconfig.TSClientPath(*conf) if !filepath.IsAbs(tsClientPath) { tsClientPath = filepath.Join(projectPath, tsClientPath) } diff --git a/ignite/version/version.go b/ignite/version/version.go index 8d5acc9aeb..7089158d2b 100644 --- a/ignite/version/version.go +++ b/ignite/version/version.go @@ -10,11 +10,10 @@ import ( "strings" "text/tabwriter" - "github.com/ignite/cli/ignite/config/chain" - "github.com/blang/semver/v4" "github.com/google/go-github/v48/github" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/gitpod" @@ -104,7 +103,7 @@ func Long(ctx context.Context) string { write("Ignite CLI version", Version) write("Ignite CLI build date", date) write("Ignite CLI source hash", head) - write("Ignite CLI config version", chain.LatestVersion) + write("Ignite CLI config version", chainconfig.LatestVersion) write("Cosmos SDK version", sdkVersion) write("Your OS", runtime.GOOS) diff --git a/integration/app.go b/integration/app.go index 7cb0af54d8..a4b86fb1d9 100644 --- a/integration/app.go +++ b/integration/app.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - "github.com/ignite/cli/ignite/config/chain" + chainconfig "github.com/ignite/cli/ignite/config/chain" v1 "github.com/ignite/cli/ignite/config/chain/v1" "github.com/ignite/cli/ignite/pkg/availableport" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -187,7 +187,7 @@ func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string) { port, err := availableport.Find(1) require.NoError(a.env.t, err) - a.EditConfig(func(c *chain.Config) { + a.EditConfig(func(c *chainconfig.Config) { c.Faucet.Port = port[0] c.Faucet.Coins = coins c.Faucet.CoinsMax = coinsMax @@ -219,7 +219,7 @@ func (a App) RandomizeServerPorts() Hosts { API: genAddr(ports[5]), } - a.EditConfig(func(c *chain.Config) { + a.EditConfig(func(c *chainconfig.Config) { v := &c.Validators[0] s := v1.Servers{} @@ -241,24 +241,24 @@ func (a App) RandomizeServerPorts() Hosts { func (a App) UseRandomHomeDir() (homeDirPath string) { dir := a.env.TmpDir() - a.EditConfig(func(c *chain.Config) { + a.EditConfig(func(c *chainconfig.Config) { c.Validators[0].Home = dir }) return dir } -func (a App) Config() chain.Config { +func (a App) Config() chainconfig.Config { bz, err := os.ReadFile(a.configPath) require.NoError(a.env.t, err) - var conf chain.Config + var conf chainconfig.Config err = yaml.Unmarshal(bz, &conf) require.NoError(a.env.t, err) return conf } -func (a App) EditConfig(apply func(*chain.Config)) { +func (a App) EditConfig(apply func(*chainconfig.Config)) { conf := a.Config() apply(&conf) diff --git a/integration/chain/config_test.go b/integration/chain/config_test.go index bf3e4fa143..cd51d6b1a0 100644 --- a/integration/chain/config_test.go +++ b/integration/chain/config_test.go @@ -8,10 +8,9 @@ import ( "path/filepath" "testing" - "github.com/ignite/cli/ignite/config/chain" - "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/confile" "github.com/ignite/cli/ignite/pkg/randstr" envtest "github.com/ignite/cli/integration" @@ -27,7 +26,7 @@ func TestOverwriteSDKConfigsAndChainID(t *testing.T) { isBackendAliveErr error ) - var cfg chain.Config + var cfg chainconfig.Config cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml")) require.NoError(t, cf.Load(&cfg)) diff --git a/integration/client.go b/integration/client.go index ea413ad33d..7ed43a645b 100644 --- a/integration/client.go +++ b/integration/client.go @@ -7,10 +7,9 @@ import ( "path/filepath" "runtime" - "github.com/ignite/cli/ignite/config/chain" - "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cmdrunner" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" ) @@ -69,7 +68,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Absolute path to the blockchain app directory "TEST_CHAIN_PATH": a.path, // Absolute path to the TS client directory - "TEST_TSCLIENT_DIR": filepath.Join(a.path, chain.DefaultTSClientPath), + "TEST_TSCLIENT_DIR": filepath.Join(a.path, chainconfig.DefaultTSClientPath), }, } for _, o := range options { @@ -84,7 +83,7 @@ func (a App) RunClientTests(options ...ClientOption) bool { // Install the dependencies needed to run TS client tests ok = a.env.Exec("install client dependencies", step.NewSteps( step.New( - step.Workdir(filepath.Join(a.path, chain.DefaultTSClientPath)), + step.Workdir(filepath.Join(a.path, chainconfig.DefaultTSClientPath)), step.Stdout(&output), step.Exec(npm, "install"), step.PostExec(func(err error) error { diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 2a2d6bcc90..209c62657f 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -6,10 +6,9 @@ import ( "fmt" "testing" - "github.com/ignite/cli/ignite/config/chain" - "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xurl" envtest "github.com/ignite/cli/integration" @@ -59,7 +58,7 @@ func TestBankModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chain.Config) { + app.EditConfig(func(cfg *chainconfig.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/cosmosgen/custom_module_test.go b/integration/cosmosgen/custom_module_test.go index 1b684e6cce..c06137bac8 100644 --- a/integration/cosmosgen/custom_module_test.go +++ b/integration/cosmosgen/custom_module_test.go @@ -6,10 +6,9 @@ import ( "fmt" "testing" - "github.com/ignite/cli/ignite/config/chain" - "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/xurl" @@ -42,7 +41,7 @@ func TestCustomModule(t *testing.T) { }, } - app.EditConfig(func(cfg *chain.Config) { + app.EditConfig(func(cfg *chainconfig.Config) { cfg.Accounts = append(cfg.Accounts, accounts...) }) diff --git a/integration/node/cmd_query_bank_test.go b/integration/node/cmd_query_bank_test.go index 6dfc621950..6a7063a0c2 100644 --- a/integration/node/cmd_query_bank_test.go +++ b/integration/node/cmd_query_bank_test.go @@ -7,13 +7,12 @@ import ( "strings" "testing" - "github.com/ignite/cli/ignite/config/chain" - "github.com/cosmos/cosmos-sdk/crypto/keyring" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cliui/entrywriter" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" @@ -66,7 +65,7 @@ func TestNodeQueryBankBalances(t *testing.T) { aliceAccount, aliceMnemonic, err := ca.Create(alice) require.NoError(t, err) - app.EditConfig(func(c *chain.Config) { + app.EditConfig(func(c *chainconfig.Config) { c.Accounts = []base.Account{ { Name: alice, diff --git a/integration/node/cmd_tx_bank_send_test.go b/integration/node/cmd_tx_bank_send_test.go index 452b745946..3f55087999 100644 --- a/integration/node/cmd_tx_bank_send_test.go +++ b/integration/node/cmd_tx_bank_send_test.go @@ -8,11 +8,10 @@ import ( "testing" "time" - "github.com/ignite/cli/ignite/config/chain" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/stretchr/testify/require" + chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosaccount" @@ -57,7 +56,7 @@ func TestNodeTxBankSend(t *testing.T) { bobAccount, bobMnemonic, err := ca.Create(bob) require.NoError(t, err) - app.EditConfig(func(c *chain.Config) { + app.EditConfig(func(c *chainconfig.Config) { c.Accounts = []base.Account{ { Name: alice, From 631d64efbab7cdbca5f65ef428d885c57e64a21b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 30 Nov 2022 07:57:53 -0500 Subject: [PATCH 48/80] address review --- ignite/cmd/plugin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index a041db2522..ea2969a2b8 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -27,10 +27,9 @@ const ( // LoadPlugins tries to load all the plugins found in configuration. // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { - // NOTE(tb) Not sure if it's the right place to load this. cfg, err := parseLocalPlugins(rootCmd) if err != nil { - // if binary is run where there is no plugin.yml, don't load + // if binary is run where there is no plugins.yml, don't load return nil } From e2d5f56c5a68d5ba3aeabd6c46cf00e1192797b5 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 30 Nov 2022 07:59:54 -0500 Subject: [PATCH 49/80] testdata --- ignite/config/plugins/parse_test.go | 6 +++--- ignite/config/testdata/testdata.go | 9 --------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ignite/config/plugins/parse_test.go b/ignite/config/plugins/parse_test.go index deb1aa9309..a0f2434f74 100644 --- a/ignite/config/plugins/parse_test.go +++ b/ignite/config/plugins/parse_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/require" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" - "github.com/ignite/cli/ignite/config/testdata" + "github.com/ignite/cli/ignite/config/plugins/testdata" ) func TestParse(t *testing.T) { // Arrange: Initialize a reader with the previous version - r := bytes.NewReader(testdata.PluginsConfig) + r := bytes.NewReader(testdata.ConfigYAML) // Act cfg, err := pluginsconfig.Parse(r) @@ -21,5 +21,5 @@ func TestParse(t *testing.T) { require.NoError(t, err) // Assert: Parse must return the latest version - require.Equal(t, testdata.GetPluginsConfig(t), cfg) + require.Equal(t, testdata.GetConfig(t), cfg) } diff --git a/ignite/config/testdata/testdata.go b/ignite/config/testdata/testdata.go index 3c9f64a51e..e57a56b8cc 100644 --- a/ignite/config/testdata/testdata.go +++ b/ignite/config/testdata/testdata.go @@ -3,14 +3,11 @@ package testdata import ( "testing" - pluginsconfig "github.com/ignite/cli/ignite/config/plugins" - "github.com/ignite/cli/ignite/config" chainconfig "github.com/ignite/cli/ignite/config/chain" networkconfigTestdata "github.com/ignite/cli/ignite/config/chain/network/testdata" v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1testdata "github.com/ignite/cli/ignite/config/chain/v1/testdata" - pluginsconfigTestdata "github.com/ignite/cli/ignite/config/plugins/testdata" ) var Versions = map[chainconfig.Version][]byte{ @@ -20,8 +17,6 @@ var Versions = map[chainconfig.Version][]byte{ var NetworkConfig = networkconfigTestdata.ConfigYAML -var PluginsConfig = pluginsconfigTestdata.ConfigYAML - func GetLatestConfig(t *testing.T) *config.ChainConfig { return v1testdata.GetConfig(t) } @@ -29,7 +24,3 @@ func GetLatestConfig(t *testing.T) *config.ChainConfig { func GetLatestNetworkConfig(t *testing.T) *config.ChainConfig { return networkconfigTestdata.GetConfig(t) } - -func GetPluginsConfig(t *testing.T) *pluginsconfig.Config { - return pluginsconfigTestdata.GetConfig(t) -} From 49c68012bd4449fd2ad042fe592e80b25086e153 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 1 Dec 2022 10:39:22 -0500 Subject: [PATCH 50/80] better import --- go.sum | 4 ---- ignite/config/chain/v0/config.go | 4 ++-- ignite/config/chain/v0/config_convert.go | 4 ++-- ignite/config/chain/v0/config_convert_test.go | 1 - ignite/config/chain/v1/config.go | 4 ++-- ignite/config/chain/v1/config_convert.go | 4 ++-- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/go.sum b/go.sum index cacec400d5..47f128df2d 100644 --- a/go.sum +++ b/go.sum @@ -1700,10 +1700,6 @@ github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/tbruyelle/mdgofmt v0.1.0 h1:sk48Z/BoOccm6DaZI3zqgK+cs2BveF+DgiZqDIPzOh8= -github.com/tbruyelle/mdgofmt v0.1.0/go.mod h1:D3fyKvx4oZq99YeQm5j/gnGmc9w4HogvQMujPVzW+zQ= -github.com/tbruyelle/mdgofmt v0.1.1 h1:ZH/n+jGxWz7ilP9dpeIgSgjPHDRafDdfzPpkILjjjSQ= -github.com/tbruyelle/mdgofmt v0.1.1/go.mod h1:D3fyKvx4oZq99YeQm5j/gnGmc9w4HogvQMujPVzW+zQ= github.com/tbruyelle/mdgofmt v0.1.2 h1:/UZaC5YTKdneMtLhDNe6328DjO2oDFCslmJJ1fqnjCQ= github.com/tbruyelle/mdgofmt v0.1.2/go.mod h1:D3fyKvx4oZq99YeQm5j/gnGmc9w4HogvQMujPVzW+zQ= github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I= diff --git a/ignite/config/chain/v0/config.go b/ignite/config/chain/v0/config.go index 8f25d1561c..a5d9019b3e 100644 --- a/ignite/config/chain/v0/config.go +++ b/ignite/config/chain/v0/config.go @@ -7,7 +7,7 @@ import ( "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config/chain/base" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/ignite/cli/ignite/config/chain/version" ) // Config is the user given configuration to do additional setup during serve. @@ -20,7 +20,7 @@ type Config struct { } // Clone returns an identical copy of the instance. -func (c *Config) Clone() (chainconfig.Converter, error) { +func (c *Config) Clone() (version.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/config/chain/v0/config_convert.go b/ignite/config/chain/v0/config_convert.go index 45de95da2c..7719dc087b 100644 --- a/ignite/config/chain/v0/config_convert.go +++ b/ignite/config/chain/v0/config_convert.go @@ -2,11 +2,11 @@ package v0 import ( v1 "github.com/ignite/cli/ignite/config/chain/v1" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/ignite/cli/ignite/config/chain/version" ) // ConvertNext converts the current config version to the next one. -func (c *Config) ConvertNext() (chainconfig.Converter, error) { +func (c *Config) ConvertNext() (version.Converter, error) { targetCfg := v1.DefaultConfig() // All the fields in the base config remain the same diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 80d96d3819..890b819153 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -7,7 +7,6 @@ import ( v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" ) func TestV0ToV1(t *testing.T) { diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 94e9f1f541..726dcc5f28 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -7,7 +7,7 @@ import ( "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/config/chain/base" - chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/ignite/cli/ignite/config/chain/version" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -39,7 +39,7 @@ func (c *Config) SetDefaults() error { } // Clone returns an identical copy of the instance -func (c *Config) Clone() (chainconfig.Converter, error) { +func (c *Config) Clone() (version.Converter, error) { copy := Config{} if err := mergo.Merge(©, c, mergo.WithAppendSlice); err != nil { return nil, err diff --git a/ignite/config/chain/v1/config_convert.go b/ignite/config/chain/v1/config_convert.go index ce57a99e6c..135fd05f9a 100644 --- a/ignite/config/chain/v1/config_convert.go +++ b/ignite/config/chain/v1/config_convert.go @@ -1,11 +1,11 @@ package v1 import ( - chainconfig "github.com/ignite/cli/ignite/config/chain/version" + "github.com/ignite/cli/ignite/config/chain/version" ) // ConvertNext implements the conversion of the current config to the next version. -func (c *Config) ConvertNext() (chainconfig.Converter, error) { +func (c *Config) ConvertNext() (version.Converter, error) { // v1 is the latest version, there is no need to convert. return c, nil } From 6fc54e16c3d7dd7df888b0c5417bf676e85d0773 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 1 Dec 2022 10:45:52 -0500 Subject: [PATCH 51/80] fix test --- ignite/config/chain/v0/config_convert_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ignite/config/chain/v0/config_convert_test.go b/ignite/config/chain/v0/config_convert_test.go index 890b819153..eb7c8d1c03 100644 --- a/ignite/config/chain/v0/config_convert_test.go +++ b/ignite/config/chain/v0/config_convert_test.go @@ -7,6 +7,7 @@ import ( v0testdata "github.com/ignite/cli/ignite/config/chain/v0/testdata" v1 "github.com/ignite/cli/ignite/config/chain/v1" + "github.com/ignite/cli/ignite/config/chain/version" ) func TestV0ToV1(t *testing.T) { @@ -20,7 +21,7 @@ func TestV0ToV1(t *testing.T) { // Assert require.NoError(t, err) require.NotNilf(t, cfgV1, "expected *v1.Config, got %T", c) - require.Equal(t, chainconfig.Version(1), cfgV1.GetVersion()) + require.Equal(t, version.Version(1), cfgV1.GetVersion()) require.Equal(t, cfgV0.Build, cfgV1.Build) require.Equal(t, cfgV0.Accounts, cfgV1.Accounts) require.Equal(t, cfgV0.Faucet, cfgV1.Faucet) From 1220b447ac3cc4f834e2a9a25bfd8ef1653bb212 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 1 Dec 2022 12:03:03 -0500 Subject: [PATCH 52/80] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 6c48aabe70..252dc23063 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ### Features +- [#3214](https://github.com/ignite/cli/pull/3214) Global plugins config. - [#3184](https://github.com/ignite/cli/pull/3184) Separate `plugins.yml` config file. - [#3038](https://github.com/ignite/cli/pull/3038) Addition of Plugin Hooks in Plugin System - [#3056](https://github.com/ignite/cli/pull/3056) Add `--genesis-config` flag option to `ignite network chain publish` From 742be4cd874be06ed6212d83fa68e11158ed879a Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 1 Dec 2022 12:09:00 -0500 Subject: [PATCH 53/80] refactor --- ignite/cmd/plugin.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index bed7e922e8..a80196d5a1 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -27,15 +27,10 @@ var plugins []*plugin.Plugin // LoadPlugins tries to load all the plugins found in configuration. // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { - var ( - localPlugins []*plugin.Plugin - globalPlugins []*plugin.Plugin - ) - localCfg, err := parseLocalConfig(rootCmd) // if binary is run where there is no cfg, don't load if err == nil { - localPlugins, err = plugin.Load(ctx, localCfg) + plugins, err = plugin.Load(ctx, localCfg) if err != nil { return err } @@ -44,15 +39,13 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { globalCfg, err := parseGlobalConfig(rootCmd) // if binary is run where there is no cfg, don't load if err == nil { - globalPlugins, err = plugin.Load(ctx, globalCfg) + globalPlugins, err := plugin.Load(ctx, globalCfg) if err != nil { return err } - + plugins = append(plugins, globalPlugins...) } - // nolint: appendAssign - plugins = append(localPlugins, globalPlugins...) if len(plugins) == 0 { return nil } From 1e5ec856c91bcd5e78fc6121b148b1cb81fbcc61 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 5 Dec 2022 15:58:49 -0500 Subject: [PATCH 54/80] simplify --- ignite/cmd/plugin.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index e4f1e50b55..0154afc8f4 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -37,7 +37,7 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { } } - globalCfg, err := parseGlobalConfig(rootCmd) + globalCfg, err := parseGlobalConfig() // if binary is run where there is no cfg, don't load if err == nil { globalPlugins, err := plugin.Load(ctx, globalCfg) @@ -68,20 +68,13 @@ func parseLocalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err er return pluginsconfig.ParseFile(pluginsPath) } -func parseGlobalConfig(rootCmd *cobra.Command) (cfg *pluginsconfig.Config, err error) { +func parseGlobalConfig() (cfg *pluginsconfig.Config, err error) { globalPath, err := plugin.PluginsPath() if err != nil { return cfg, err } - pluginsPath := getPlugins(rootCmd) - if pluginsPath == "" { - if pluginsPath, err = pluginsconfig.LocateDefault(globalPath); err != nil { - return cfg, err - } - } - - return pluginsconfig.ParseFile(pluginsPath) + return pluginsconfig.ParseFile(globalPath) } func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { From b5c967e710e82d4b1441496d6ad5198575624feb Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 18:30:10 -0500 Subject: [PATCH 55/80] RemoveDuplicates --- ignite/cmd/plugin.go | 24 +++++------ ignite/config/plugins/parse.go | 3 ++ ignite/services/plugin/plugin.go | 22 +++++++--- ignite/services/plugin/plugin_test.go | 62 +++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 18 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 9120f5e0b1..ebda417eee 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -31,24 +31,22 @@ var plugins []*plugin.Plugin // If no configuration found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) - // if binary is run where there is no cfg, don't load - if err == nil { - plugins, err = plugin.Load(ctx, localCfg) - if err != nil { - return err - } + if err != pluginsconfig.ErrNotFound { + return nil } globalCfg, err := parseGlobalPlugins() - // if no global cfg, don't load - if err == nil { - globalPlugins, err := plugin.Load(ctx, globalCfg) - if err != nil { - return err - } - plugins = append(plugins, globalPlugins...) + if err != pluginsconfig.ErrNotFound { + return nil + } + + pluginsConfigs := append(localCfg.Plugins, globalCfg.Plugins...) + if len(pluginsConfigs) == 0 { + return nil } + uniquePlugins := plugin.RemoveDuplicates(pluginsConfigs) + plugins, err = plugin.Load(ctx, uniquePlugins) if len(plugins) == 0 { return nil } diff --git a/ignite/config/plugins/parse.go b/ignite/config/plugins/parse.go index 7e7d470a25..9bf92525e8 100644 --- a/ignite/config/plugins/parse.go +++ b/ignite/config/plugins/parse.go @@ -1,6 +1,7 @@ package plugins import ( + "errors" "fmt" "io" "os" @@ -9,6 +10,8 @@ import ( "gopkg.in/yaml.v2" ) +var ErrNotFound = errors.New("plugins.yml file not found") + // ParseDir expects to find a plugin config file in dir. If dir is not a folder, // an error is returned. // The plugin config file format can be `plugins.yml` or `plugins.yaml`. If diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 730d9e6f1c..b38b9c2daa 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -67,19 +67,19 @@ type Plugin struct { // If an error occurs during a plugin load, it's not returned but rather stored // in the Plugin.Error field. This prevents the loading of other plugins to be // interrupted. -func Load(ctx context.Context, cfg *pluginsconfig.Config) ([]*Plugin, error) { +func Load(ctx context.Context, plugins []pluginsconfig.Plugin) ([]*Plugin, error) { pluginsDir, err := PluginsPath() if err != nil { return nil, errors.WithStack(err) } - var plugins []*Plugin - for _, cp := range cfg.Plugins { + var loaded []*Plugin + for _, cp := range plugins { p := newPlugin(pluginsDir, cp) p.load(ctx) - plugins = append(plugins, p) + loaded = append(loaded, p) } - return plugins, nil + return loaded, nil } func LoadSingle(ctx context.Context, pluginCfg *pluginsconfig.Plugin) (*Plugin, error) { @@ -153,6 +153,18 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin) *Plugin { return p } +// RemoveDuplicates takes a list of pluginsconfig.Plugins and returns a new list with only unique values +func RemoveDuplicates(plugins []pluginsconfig.Plugin) (unique []pluginsconfig.Plugin) { + keys := make(map[string]bool) + for _, plugin := range plugins { + if _, value := keys[plugin.Path]; !value { + keys[plugin.Path] = true + unique = append(unique, plugin) + } + } + return unique +} + func (p *Plugin) KillClient() { if p.client != nil { p.client.Kill() diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 420269b210..709c072372 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -394,6 +394,68 @@ func TestPluginClean(t *testing.T) { } } +func TestRemoveDuplicates(t *testing.T) { + tests := []struct { + name string + configs []pluginsconfig.Plugin + expected []pluginsconfig.Plugin + }{ + { + name: "do nothing for empty list", + configs: []pluginsconfig.Plugin(nil), + expected: []pluginsconfig.Plugin(nil), + }, + { + name: "remove duplicates", + configs: []pluginsconfig.Plugin{ + pluginsconfig.Plugin{ + Path: "foo/bar", + }, + pluginsconfig.Plugin{ + Path: "foo/bar", + }, + pluginsconfig.Plugin{ + Path: "bar/foo", + }, + }, + expected: []pluginsconfig.Plugin{ + pluginsconfig.Plugin{ + Path: "foo/bar", + }, + pluginsconfig.Plugin{ + Path: "bar/foo", + }, + }, + }, + { + name: "do nothing for no duplicates", + configs: []pluginsconfig.Plugin{ + pluginsconfig.Plugin{ + Path: "foo/bar", + }, + pluginsconfig.Plugin{ + Path: "bar/foo", + }, + }, + expected: []pluginsconfig.Plugin{ + pluginsconfig.Plugin{ + Path: "foo/bar", + }, + pluginsconfig.Plugin{ + Path: "bar/foo", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + unique := RemoveDuplicates(tt.configs) + require.EqualValues(t, tt.expected, unique) + + }) + } +} + func assertPlugin(t *testing.T, want, have Plugin) { if want.Error != nil { require.Error(t, have.Error) From 1ecfc288765f90c387e4f1c2f7cad2da0a133220 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 18:34:59 -0500 Subject: [PATCH 56/80] refactor LoadPlugins --- ignite/cmd/plugin.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index ebda417eee..9aa623b9ad 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -27,8 +27,8 @@ const ( // A global variable is used so the list is accessible to the plugin commands. var plugins []*plugin.Plugin -// LoadPlugins tries to load all the plugins found in configuration. -// If no configuration found, it returns w/o error. +// LoadPlugins tries to load all the plugins found in configurations. +// If no configurations found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) if err != pluginsconfig.ErrNotFound { @@ -40,19 +40,19 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { return nil } - pluginsConfigs := append(localCfg.Plugins, globalCfg.Plugins...) + // build list of all plugins + pluginsConfigs := globalCfg.Plugins + pluginsConfigs = append(pluginsConfigs, localCfg.Plugins...) if len(pluginsConfigs) == 0 { return nil } uniquePlugins := plugin.RemoveDuplicates(pluginsConfigs) plugins, err = plugin.Load(ctx, uniquePlugins) - if len(plugins) == 0 { + if err != nil || len(plugins) == 0 { return nil } - // TODO: sort duplicates - return loadPlugins(rootCmd, plugins) } From 859d6d358391ee8a59fac64d6a65d1e6473f4765 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 18:43:46 -0500 Subject: [PATCH 57/80] lint --- ignite/cmd/plugin.go | 4 ++-- ignite/services/plugin/plugin.go | 2 +- ignite/services/plugin/plugin_test.go | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 9aa623b9ad..fe3ebf0e51 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -31,12 +31,12 @@ var plugins []*plugin.Plugin // If no configurations found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) - if err != pluginsconfig.ErrNotFound { + if err != nil && !errors.Is(err, pluginsconfig.ErrNotFound) { return nil } globalCfg, err := parseGlobalPlugins() - if err != pluginsconfig.ErrNotFound { + if err != nil && !errors.Is(err, pluginsconfig.ErrNotFound) { return nil } diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index b38b9c2daa..055342347e 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -153,7 +153,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin) *Plugin { return p } -// RemoveDuplicates takes a list of pluginsconfig.Plugins and returns a new list with only unique values +// RemoveDuplicates takes a list of pluginsconfig.Plugins and returns a new list with only unique values. func RemoveDuplicates(plugins []pluginsconfig.Plugin) (unique []pluginsconfig.Plugin) { keys := make(map[string]bool) for _, plugin := range plugins { diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 709c072372..55878f95b6 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -408,21 +408,21 @@ func TestRemoveDuplicates(t *testing.T) { { name: "remove duplicates", configs: []pluginsconfig.Plugin{ - pluginsconfig.Plugin{ + { Path: "foo/bar", }, - pluginsconfig.Plugin{ + { Path: "foo/bar", }, - pluginsconfig.Plugin{ + { Path: "bar/foo", }, }, expected: []pluginsconfig.Plugin{ - pluginsconfig.Plugin{ + { Path: "foo/bar", }, - pluginsconfig.Plugin{ + { Path: "bar/foo", }, }, @@ -430,18 +430,18 @@ func TestRemoveDuplicates(t *testing.T) { { name: "do nothing for no duplicates", configs: []pluginsconfig.Plugin{ - pluginsconfig.Plugin{ + { Path: "foo/bar", }, - pluginsconfig.Plugin{ + { Path: "bar/foo", }, }, expected: []pluginsconfig.Plugin{ - pluginsconfig.Plugin{ + { Path: "foo/bar", }, - pluginsconfig.Plugin{ + { Path: "bar/foo", }, }, @@ -451,7 +451,6 @@ func TestRemoveDuplicates(t *testing.T) { t.Run(tt.name, func(t *testing.T) { unique := RemoveDuplicates(tt.configs) require.EqualValues(t, tt.expected, unique) - }) } } From 9c53c49ede66e392ff5a5e06f45a60610363fcac Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 19:03:48 -0500 Subject: [PATCH 58/80] add global flag --- ignite/cmd/cmd.go | 23 ++++++++++++++++++----- ignite/cmd/plugin.go | 10 ++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 5bf771e6b7..66cb140649 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -28,11 +28,12 @@ import ( ) const ( - flagPath = "path" - flagHome = "home" - flagYes = "yes" - flagClearCache = "clear-cache" - flagSkipProto = "skip-proto" + flagPath = "path" + flagHome = "home" + flagYes = "yes" + flagClearCache = "clear-cache" + flagSkipProto = "skip-proto" + flagPluginsGlobal = "global" checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -161,6 +162,18 @@ func flagGetClearCache(cmd *cobra.Command) bool { return clearCache } +func flagSetPluginsGlobal() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.BoolP(flagPluginsGlobal, "g", false, "use global plugins configuration"+ + " ($HOME/.ignite/plugins/plugins.yml)") + return fs +} + +func flagGetPluginsGlobal(cmd *cobra.Command) bool { + global, _ := cmd.Flags().GetBool(flagPluginsGlobal) + return global +} + func newChainWithHomeFlags(cmd *cobra.Command, chainOption ...chain.Option) (*chain.Chain, error) { // Check if custom home is provided if home := getHome(cmd); home != "" { diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index fe3ebf0e51..98debc543e 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -394,8 +394,8 @@ func NewPluginUpdate() *cobra.Command { func NewPluginAdd() *cobra.Command { cmdPluginAdd := &cobra.Command{ Use: "add [path] [key=value]...", - Short: "Adds a plugin declaration to a chain's plugin configuration", - Long: `Adds a plugin declaration to a chain's plugin configuration. + Short: "Adds a plugin declaration to a plugin configuration", + Long: `Adds a plugin declaration to a plugin configuration. Respects key value pairs declared after the plugin path to be added to the generated configuration definition. Example: @@ -453,6 +453,9 @@ Example: return nil }, } + + cmdPluginAdd.Flags().AddFlagSet(flagSetPluginsGlobal()) + return cmdPluginAdd } @@ -486,6 +489,9 @@ func NewPluginRemove() *cobra.Command { return nil }, } + + cmdPluginRemove.Flags().AddFlagSet(flagSetPluginsGlobal()) + return cmdPluginRemove } From 0862e8ff16a637bffda3979579152fd89eaa0a81 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 19:28:43 -0500 Subject: [PATCH 59/80] add info --- ignite/cmd/plugin.go | 40 ++++++++++++++++++++++++++++---- ignite/services/plugin/plugin.go | 7 ++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 98debc543e..e4f30736cb 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -405,7 +405,17 @@ Example: session := cliui.New(cliui.WithStdout(os.Stdout)) defer session.End() - conf, err := parseLocalPlugins(cmd) + var ( + conf *pluginsconfig.Config + err error + ) + + global := flagGetPluginsGlobal(cmd) + if global { + conf, err = parseGlobalPlugins() + } else { + conf, err = parseLocalPlugins(cmd) + } if err != nil { return err } @@ -468,7 +478,17 @@ func NewPluginRemove() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { s := cliui.New(cliui.WithStdout(os.Stdout)) - conf, err := parseLocalPlugins(cmd) + var ( + conf *pluginsconfig.Config + err error + ) + + global := flagGetPluginsGlobal(cmd) + if global { + conf, err = parseGlobalPlugins() + } else { + conf, err = parseLocalPlugins(cmd) + } if err != nil { return err } @@ -579,12 +599,22 @@ func printPlugins(session *cliui.Session) error { hookCount = len(manifest.Hooks) cmdCount = len(manifest.Commands) ) - return fmt.Sprintf("%s Loaded 🪝%d 💻%d", icons.OK, hookCount, cmdCount) + + return fmt.Sprintf("%s Loaded: 🪝%d 💻%d", icons.OK, hookCount, cmdCount) } + + installedStatus := func(p *plugin.Plugin) string { + installed := "local" + if p.IsGlobal() { + installed = "global" + } + return installed + } + for _, p := range plugins { - entries = append(entries, []string{p.Path, buildStatus(p)}) + entries = append(entries, []string{p.Path, buildStatus(p), installedStatus(p)}) } - if err := session.PrintTable([]string{"Path", "Status"}, entries...); err != nil { + if err := session.PrintTable([]string{"Path", "Status", "Config"}, entries...); err != nil { return fmt.Errorf("error while printing plugins: %w", err) } return nil diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 055342347e..abe02f67a1 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -51,6 +51,7 @@ type Plugin struct { reference string srcPath string binaryName string + global bool client *hplugin.Client } @@ -165,12 +166,18 @@ func RemoveDuplicates(plugins []pluginsconfig.Plugin) (unique []pluginsconfig.Pl return unique } +// KillClient kills the running plugin client. func (p *Plugin) KillClient() { if p.client != nil { p.client.Kill() } } +// IsGlobal returns whether the plugin is installed globally or locally for a chain. +func (p *Plugin) IsGlobal() bool { + return p.global +} + func (p *Plugin) isLocal() bool { return p.cloneURL == "" } From 284819c6e6ba31f4bd994666a39d66c4d8ec250f Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 20:13:46 -0500 Subject: [PATCH 60/80] add error prints --- ignite/cmd/plugin.go | 7 +++++-- ignite/config/plugins/parse.go | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index e4f30736cb..baaeb4a956 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -31,12 +31,14 @@ var plugins []*plugin.Plugin // If no configurations found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) - if err != nil && !errors.Is(err, pluginsconfig.ErrNotFound) { + if err != nil && !errors.Is(err, cosmosanalysis.ErrPathNotChain{}) { + fmt.Println("error parsing local chain plugins config: %w", err) return nil } globalCfg, err := parseGlobalPlugins() - if err != nil && !errors.Is(err, pluginsconfig.ErrNotFound) { + if err != nil { + fmt.Println("error parsing global plugins config: %w", err) return nil } @@ -505,6 +507,7 @@ func NewPluginRemove() *cobra.Command { } s.Printf("%s %s removed\n", icons.OK, args[0]) + s.Printf("\t%s updated\n", conf.Path()) return nil }, diff --git a/ignite/config/plugins/parse.go b/ignite/config/plugins/parse.go index cc929f76ca..589cc5c1d6 100644 --- a/ignite/config/plugins/parse.go +++ b/ignite/config/plugins/parse.go @@ -10,8 +10,6 @@ import ( "gopkg.in/yaml.v2" ) -var ErrNotFound = errors.New("plugins.yml file not found") - // ParseDir expects to find a plugin config file in dir. If dir is not a folder, // an error is returned. // The plugin config file format can be `plugins.yml` or `plugins.yaml`. If From fa84c3bf21a692d97571665b40b73ff92d9b6ffe Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 20:16:54 -0500 Subject: [PATCH 61/80] simplify return --- ignite/cmd/plugin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index baaeb4a956..e38240c756 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -81,8 +81,7 @@ func parseGlobalPlugins() (cfg *pluginsconfig.Config, err error) { return cfg, err } - cfg, err = pluginsconfig.ParseDir(globalDir) - return cfg, err + return pluginsconfig.ParseDir(globalDir) } func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { From bce47a7cb7a9ed106fab0426e1b3ed5a55f31dc5 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 20:44:14 -0500 Subject: [PATCH 62/80] fix test --- ignite/cmd/plugin.go | 15 +++++++++------ integration/account/cmd_account_test.go | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index e38240c756..368cfb620c 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -30,21 +30,24 @@ var plugins []*plugin.Plugin // LoadPlugins tries to load all the plugins found in configurations. // If no configurations found, it returns w/o error. func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { + pluginsConfigs := make([]pluginsconfig.Plugin, 0) + localCfg, err := parseLocalPlugins(rootCmd) - if err != nil && !errors.Is(err, cosmosanalysis.ErrPathNotChain{}) { - fmt.Println("error parsing local chain plugins config: %w", err) + if err != nil && !errors.As(err, &cosmosanalysis.ErrPathNotChain{}) { + fmt.Printf("error parsing local chain plugins config: %s", err.Error()) return nil + + } else if err == nil { + pluginsConfigs = append(pluginsConfigs, localCfg.Plugins...) } globalCfg, err := parseGlobalPlugins() if err != nil { - fmt.Println("error parsing global plugins config: %w", err) + fmt.Printf("error parsing global plugins config: %s", err.Error()) return nil } - // build list of all plugins - pluginsConfigs := globalCfg.Plugins - pluginsConfigs = append(pluginsConfigs, localCfg.Plugins...) + pluginsConfigs = append(pluginsConfigs, globalCfg.Plugins...) if len(pluginsConfigs) == 0 { return nil } diff --git a/integration/account/cmd_account_test.go b/integration/account/cmd_account_test.go index 9679220832..0ec564ef1b 100644 --- a/integration/account/cmd_account_test.go +++ b/integration/account/cmd_account_test.go @@ -49,7 +49,7 @@ func TestAccount(t *testing.T) { )), envtest.ExecStdout(listOutputAfterDeleteBuffer), )) - require.Equal(t, listOutputAfterDeleteBuffer.String(), "Name \tAddress Public Key \t\n\n") + require.Equal(t, "Name \tAddress Public Key \t\n\n", listOutputAfterDeleteBuffer.String()) env.Must(env.Exec("import account with mnemonic", step.NewSteps(step.New( From aa10107675e6d785a624e494a7c26b9f61eabcc6 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 22:25:39 -0500 Subject: [PATCH 63/80] fix global parse --- ignite/cmd/plugin.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 368cfb620c..8c1ce9d58e 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -42,12 +42,10 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { } globalCfg, err := parseGlobalPlugins() - if err != nil { - fmt.Printf("error parsing global plugins config: %s", err.Error()) - return nil + if err == nil { + pluginsConfigs = append(pluginsConfigs, globalCfg.Plugins...) } - pluginsConfigs = append(pluginsConfigs, globalCfg.Plugins...) if len(pluginsConfigs) == 0 { return nil } From 1149ae857b2e9d052f27009532e57700e4ebb034 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 23:29:37 -0500 Subject: [PATCH 64/80] add integration test --- integration/plugin/plugin_test.go | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 integration/plugin/plugin_test.go diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go new file mode 100644 index 0000000000..5724507958 --- /dev/null +++ b/integration/plugin/plugin_test.go @@ -0,0 +1,58 @@ +package plugin_test + +import ( + "testing" + + "github.com/ignite/cli/ignite/pkg/cmdrunner/step" + envtest "github.com/ignite/cli/integration" +) + +func TestAddPlugin(t *testing.T) { + var ( + env = envtest.New(t) + app = env.Scaffold("github.com/test/blog") + ) + + env.Must(env.Exec("add network plugin locally", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/cli-plugin-network@feb7a963661612ae1a6c1f9ccdbe3ea9f7cb8dd3"), + step.Workdir(app.SourcePath()), + )), + )) + + env.Must(env.Exec("remove network plugin locally", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/cli-plugin-network"), + step.Workdir(app.SourcePath()), + )), + )) + + env.Must(env.Exec("add network plugin globally", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/cli-plugin-network@feb7a963661612ae1a6c1f9ccdbe3ea9f7cb8dd3", "-g"), + step.Workdir(app.SourcePath()), + )), + )) + + env.Must(env.Exec("remove network plugin globally", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/cli-plugin-network", "-g"), + step.Workdir(app.SourcePath()), + )), + )) + + app.EnsureSteady() +} + +func TestPluginScaffold(t *testing.T) { + var ( + env = envtest.New(t) + ) + + env.Must(env.Exec("add a plugin", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "plugin", "scaffold", "test"), + step.Workdir(env.TmpDir()), + )), + )) +} From 054879c73aa7db476f8bfdd90691f7ecd75d26bc Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 12 Dec 2022 23:39:47 -0500 Subject: [PATCH 65/80] modify test --- integration/plugin/plugin_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index 5724507958..c21a09c812 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -13,30 +13,32 @@ func TestAddPlugin(t *testing.T) { app = env.Scaffold("github.com/test/blog") ) + // TODO use network plugin once finalized + env.Must(env.Exec("add network plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/cli-plugin-network@feb7a963661612ae1a6c1f9ccdbe3ea9f7cb8dd3"), + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/aljo242/test-plugin"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("remove network plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/cli-plugin-network"), + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/aljo242/test-plugin"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("add network plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/cli-plugin-network@feb7a963661612ae1a6c1f9ccdbe3ea9f7cb8dd3", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/aljo242/test-plugin", "-g"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("remove network plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/cli-plugin-network", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/aljo242/test-plugin", "-g"), step.Workdir(app.SourcePath()), )), )) From f8500bf181e3f19e52be4c3403bd2993b576269c Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 08:14:34 -0500 Subject: [PATCH 66/80] fix returns --- ignite/cmd/plugin.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 8c1ce9d58e..e06da65ecc 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -52,7 +52,9 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { uniquePlugins := plugin.RemoveDuplicates(pluginsConfigs) plugins, err = plugin.Load(ctx, uniquePlugins) - if err != nil || len(plugins) == 0 { + if err != nil { + return err + } else if len(plugins) == 0 { return nil } From bd4b6efe47b82ef814c0a50a742a80db25ccd723 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 09:38:56 -0500 Subject: [PATCH 67/80] use ignite example plugin --- integration/plugin/plugin_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index c21a09c812..d7ce85e190 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -13,32 +13,30 @@ func TestAddPlugin(t *testing.T) { app = env.Scaffold("github.com/test/blog") ) - // TODO use network plugin once finalized - - env.Must(env.Exec("add network plugin locally", + env.Must(env.Exec("add plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/aljo242/test-plugin"), + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/example-plugin"), step.Workdir(app.SourcePath()), )), )) - env.Must(env.Exec("remove network plugin locally", + env.Must(env.Exec("remove plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/aljo242/test-plugin"), + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/example-plugin"), step.Workdir(app.SourcePath()), )), )) - env.Must(env.Exec("add network plugin globally", + env.Must(env.Exec("add plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/aljo242/test-plugin", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/example-plugin", "-g"), step.Workdir(app.SourcePath()), )), )) - env.Must(env.Exec("remove network plugin globally", + env.Must(env.Exec("remove plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/aljo242/test-plugin", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/example-plugin", "-g"), step.Workdir(app.SourcePath()), )), )) @@ -46,6 +44,8 @@ func TestAddPlugin(t *testing.T) { app.EnsureSteady() } +// TODO install network plugin test + func TestPluginScaffold(t *testing.T) { var ( env = envtest.New(t) From 58c682938183f70dd9c0044309c3a4a44246ce17 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 09:55:55 -0500 Subject: [PATCH 68/80] refactor global flag --- ignite/cmd/plugin.go | 16 +++++++++++++--- ignite/config/plugins/config.go | 3 +++ ignite/services/plugin/plugin.go | 8 +++++--- integration/plugin/plugin_test.go | 4 +--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index e06da65ecc..b23a50e6f8 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -84,7 +84,15 @@ func parseGlobalPlugins() (cfg *pluginsconfig.Config, err error) { return cfg, err } - return pluginsconfig.ParseDir(globalDir) + cfg, err = pluginsconfig.ParseDir(globalDir) + if err != nil { + return &pluginsconfig.Config{}, nil + } + + for _, p := range cfg.Plugins { + p.Global = true + } + return } func loadPlugins(rootCmd *cobra.Command, plugins []*plugin.Plugin) error { @@ -430,9 +438,11 @@ Example: } } + fmt.Println(global) p := pluginsconfig.Plugin{ - Path: args[0], - With: make(map[string]string), + Path: args[0], + With: make(map[string]string), + Global: global, } var pluginArgs []string diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 8b3be1598a..0837a4e372 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -36,6 +36,9 @@ type Plugin struct { Path string `yaml:"path"` // With holds arguments passed to the plugin interface With map[string]string `yaml:"with,omitempty"` + // Global holds whether the plugin is installed globally + // (default: $HOME/.ignite/plugins/plugins.yml) or locally for a chain. + Global bool `yaml:"global,omitempty"` } // Path return the path of the config file. diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index abe02f67a1..a6275dfe7c 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -51,7 +51,6 @@ type Plugin struct { reference string srcPath string binaryName string - global bool client *hplugin.Client } @@ -110,7 +109,9 @@ func Update(plugins ...*Plugin) error { // newPlugin creates a Plugin from configuration. func newPlugin(pluginsDir string, cp pluginsconfig.Plugin) *Plugin { var ( - p = &Plugin{Plugin: cp} + p = &Plugin{ + Plugin: cp, + } pluginPath = cp.Path ) if pluginPath == "" { @@ -151,6 +152,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin) *Plugin { p.cloneDir = path.Join(pluginsDir, p.repoPath) p.srcPath = path.Join(pluginsDir, p.repoPath, path.Join(parts[3:]...)) p.binaryName = path.Base(pluginPath) + return p } @@ -175,7 +177,7 @@ func (p *Plugin) KillClient() { // IsGlobal returns whether the plugin is installed globally or locally for a chain. func (p *Plugin) IsGlobal() bool { - return p.global + return p.Plugin.Global } func (p *Plugin) isLocal() bool { diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index d7ce85e190..eca6d82611 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -47,9 +47,7 @@ func TestAddPlugin(t *testing.T) { // TODO install network plugin test func TestPluginScaffold(t *testing.T) { - var ( - env = envtest.New(t) - ) + env := envtest.New(t) env.Must(env.Exec("add a plugin", step.NewSteps(step.New( From a3d9d661f102a4a761b1a1ec8b533dc577eaaacd Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 13 Dec 2022 16:05:59 +0100 Subject: [PATCH 69/80] Fix plugin integration test Add more assertion and use an alternate `.ignite` folder to avoid conflicts with user home. Also fix `plugin add -g` when `.ignite/plugins` doesn't exist. --- ignite/config/config.go | 15 +------ ignite/pkg/env/env.go | 30 ++++++++++++- ignite/pkg/xfilepath/xfilepath.go | 54 +++++++++++++---------- ignite/pkg/xfilepath/xfilepath_test.go | 14 ++++++ ignite/services/plugin/plugin.go | 4 +- integration/env.go | 6 +++ integration/plugin/plugin_test.go | 61 +++++++++++++++++++++----- 7 files changed, 135 insertions(+), 49 deletions(-) diff --git a/ignite/config/config.go b/ignite/config/config.go index 2217fa486a..44a5c4ff2b 100644 --- a/ignite/config/config.go +++ b/ignite/config/config.go @@ -1,20 +1,9 @@ package config import ( - "os" - + "github.com/ignite/cli/ignite/pkg/env" "github.com/ignite/cli/ignite/pkg/xfilepath" ) // DirPath returns the path of configuration directory of Ignite. -var DirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite")) - -// CreateConfigDir creates config directory if it is not created yet. -func CreateConfigDir() error { - path, err := DirPath() - if err != nil { - return err - } - - return os.MkdirAll(path, 0o755) -} +var DirPath = xfilepath.Mkdir(env.ConfigDir()) diff --git a/ignite/pkg/env/env.go b/ignite/pkg/env/env.go index 09ee2de779..25c66fe152 100644 --- a/ignite/pkg/env/env.go +++ b/ignite/pkg/env/env.go @@ -1,11 +1,37 @@ package env -import "os" +import ( + "fmt" + "os" + "path" + + "github.com/ignite/cli/ignite/pkg/xfilepath" +) const ( - debug = "IGNT_DEBUG" + debug = "IGNT_DEBUG" + configDir = "IGNT_CONFIG_DIR" ) func DebugEnabled() bool { return os.Getenv(debug) == "1" } + +func ConfigDir() xfilepath.PathRetriever { + return func() (string, error) { + if dir := os.Getenv(configDir); dir != "" { + if !path.IsAbs(dir) { + panic(fmt.Sprintf("%s must be an absolute path", configDir)) + } + return dir, nil + } + return xfilepath.JoinFromHome(xfilepath.Path(".ignite"))() + } +} + +func SetConfigDir(dir string) { + err := os.Setenv(configDir, dir) + if err != nil { + panic(fmt.Sprintf("set config dir env: %v", err)) + } +} diff --git a/ignite/pkg/xfilepath/xfilepath.go b/ignite/pkg/xfilepath/xfilepath.go index 1707a7409a..ce6c09712d 100644 --- a/ignite/pkg/xfilepath/xfilepath.go +++ b/ignite/pkg/xfilepath/xfilepath.go @@ -26,19 +26,18 @@ func PathWithError(path string, err error) PathRetriever { // The returned path retriever eventually returns the error from the first provided path retrievers // that returns a non-nil error. func Join(paths ...PathRetriever) PathRetriever { - var components []string - var err error - for _, path := range paths { - var component string - component, err = path() - if err != nil { - break - } - components = append(components, component) - } - path := filepath.Join(components...) - return func() (string, error) { + var components []string + var err error + for _, path := range paths { + var component string + component, err = path() + if err != nil { + break + } + components = append(components, component) + } + path := filepath.Join(components...) return path, err } } @@ -52,18 +51,29 @@ func JoinFromHome(paths ...PathRetriever) PathRetriever { // List returns a paths retriever from a list of path retrievers. // The returned paths retriever eventually returns the error from the first provided path retrievers that returns a non-nil error. func List(paths ...PathRetriever) PathsRetriever { - var list []string - var err error - for _, path := range paths { - var resolved string - resolved, err = path() - if err != nil { - break + return func() ([]string, error) { + var list []string + var err error + for _, path := range paths { + var resolved string + resolved, err = path() + if err != nil { + break + } + list = append(list, resolved) } - list = append(list, resolved) - } - return func() ([]string, error) { return list, err } } + +// Mkdir ensure path exists before returning it. +func Mkdir(path PathRetriever) PathRetriever { + return func() (string, error) { + p, err := path() + if err != nil { + return "", err + } + return p, os.MkdirAll(p, 0o755) + } +} diff --git a/ignite/pkg/xfilepath/xfilepath_test.go b/ignite/pkg/xfilepath/xfilepath_test.go index 5e459daf81..9b5216666d 100644 --- a/ignite/pkg/xfilepath/xfilepath_test.go +++ b/ignite/pkg/xfilepath/xfilepath_test.go @@ -3,9 +3,11 @@ package xfilepath_test import ( "errors" "os" + "path" "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/pkg/xfilepath" @@ -88,3 +90,15 @@ func TestList(t *testing.T) { _, err = retriever() require.Error(t, err) } + +func TestMkdir(t *testing.T) { + require := require.New(t) + assert := assert.New(t) + newdir := path.Join(t.TempDir(), "hey") + + dir, err := xfilepath.Mkdir(xfilepath.Path(newdir))() + + require.NoError(err) + assert.Equal(newdir, dir) + assert.DirExists(dir) +} diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index a6275dfe7c..68280dc560 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -31,10 +31,10 @@ import ( ) // PluginsPath holds the plugin cache directory. -var PluginsPath = xfilepath.Join( +var PluginsPath = xfilepath.Mkdir(xfilepath.Join( config.DirPath, xfilepath.Path("plugins"), -) +)) // Plugin represents a ignite plugin. type Plugin struct { diff --git a/integration/env.go b/integration/env.go index 39cb47ab4b..f653bbdbd5 100644 --- a/integration/env.go +++ b/integration/env.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/ignite/pkg/cosmosfaucet" + "github.com/ignite/cli/ignite/pkg/env" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/gomodulepath" "github.com/ignite/cli/ignite/pkg/httpstatuschecker" @@ -53,6 +54,11 @@ func New(t *testing.T) Env { t: t, ctx: ctx, } + // To avoid conflicts with the default config folder located in $HOME, we + // set an other one thanks to env var. + cfgDir := path.Join(t.TempDir(), ".ignite") + env.SetConfigDir(cfgDir) + t.Cleanup(cancel) compileBinaryOnce.Do(func() { compileBinary(ctx) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index eca6d82611..ec1238ae10 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -3,49 +3,90 @@ package plugin_test import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" + "github.com/ignite/cli/ignite/services/plugin" envtest "github.com/ignite/cli/integration" ) -func TestAddPlugin(t *testing.T) { +func TestAddRemovePlugin(t *testing.T) { var ( - env = envtest.New(t) - app = env.Scaffold("github.com/test/blog") + require = require.New(t) + assert = assert.New(t) + env = envtest.New(t) + app = env.Scaffold("github.com/test/blog") + pluginRepo = "github.com/ignite/example-plugin" + + assertPlugins = func(expectedLocalPlugins, expectedGlobalPlugins []pluginsconfig.Plugin) { + localCfg, err := pluginsconfig.ParseDir(app.SourcePath()) + require.NoError(err) + assert.ElementsMatch(expectedLocalPlugins, localCfg.Plugins, "unexpected local plugins") + + globalCfgPath, err := plugin.PluginsPath() + require.NoError(err) + globalCfg, err := pluginsconfig.ParseDir(globalCfgPath) + require.NoError(err) + assert.ElementsMatch(expectedGlobalPlugins, globalCfg.Plugins, "unexpected global plugins") + } ) + // no plugins expected + assertPlugins(nil, nil) + env.Must(env.Exec("add plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/example-plugin"), + step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo), step.Workdir(app.SourcePath()), )), )) + // one local plugin expected + assertPlugins( + []pluginsconfig.Plugin{ + {Path: pluginRepo}, + }, + nil, + ) + env.Must(env.Exec("remove plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/example-plugin"), + step.Exec(envtest.IgniteApp, "plugin", "remove", pluginRepo), step.Workdir(app.SourcePath()), )), )) + // no plugins expected + assertPlugins(nil, nil) + env.Must(env.Exec("add plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", "github.com/ignite/example-plugin", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo, "-g"), step.Workdir(app.SourcePath()), )), )) + // one global plugins expected + assertPlugins( + nil, + []pluginsconfig.Plugin{ + {Path: pluginRepo}, + }, + ) + env.Must(env.Exec("remove plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", "github.com/ignite/example-plugin", "-g"), + step.Exec(envtest.IgniteApp, "plugin", "remove", pluginRepo, "-g"), step.Workdir(app.SourcePath()), )), )) - app.EnsureSteady() + // no plugins expected + assertPlugins(nil, nil) } -// TODO install network plugin test - func TestPluginScaffold(t *testing.T) { env := envtest.New(t) From eb63d3127ab894aa9a582e7d2491fb2f8ceffdc7 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 13 Dec 2022 16:12:12 +0100 Subject: [PATCH 70/80] add removed TODO by mistake --- integration/plugin/plugin_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index ec1238ae10..b8193a39cf 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -87,6 +87,8 @@ func TestAddRemovePlugin(t *testing.T) { assertPlugins(nil, nil) } +// TODO install network plugin test + func TestPluginScaffold(t *testing.T) { env := envtest.New(t) From 0bea0598b767d61ddb70626b4d60742df843771c Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 10:17:29 -0500 Subject: [PATCH 71/80] move flags --- ignite/cmd/cmd.go | 23 +++++------------------ ignite/cmd/plugin.go | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 66cb140649..5bf771e6b7 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -28,12 +28,11 @@ import ( ) const ( - flagPath = "path" - flagHome = "home" - flagYes = "yes" - flagClearCache = "clear-cache" - flagSkipProto = "skip-proto" - flagPluginsGlobal = "global" + flagPath = "path" + flagHome = "home" + flagYes = "yes" + flagClearCache = "clear-cache" + flagSkipProto = "skip-proto" checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -162,18 +161,6 @@ func flagGetClearCache(cmd *cobra.Command) bool { return clearCache } -func flagSetPluginsGlobal() *flag.FlagSet { - fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.BoolP(flagPluginsGlobal, "g", false, "use global plugins configuration"+ - " ($HOME/.ignite/plugins/plugins.yml)") - return fs -} - -func flagGetPluginsGlobal(cmd *cobra.Command) bool { - global, _ := cmd.Flags().GetBool(flagPluginsGlobal) - return global -} - func newChainWithHomeFlags(cmd *cobra.Command, chainOption ...chain.Option) (*chain.Chain, error) { // Check if custom home is provided if home := getHome(cmd); home != "" { diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index b23a50e6f8..2b80a284b7 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + flag "github.com/spf13/pflag" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" "github.com/ignite/cli/ignite/pkg/clictx" @@ -20,7 +21,8 @@ import ( ) const ( - igniteCmdPrefix = "ignite " + igniteCmdPrefix = "ignite " + flagPluginsGlobal = "global" ) // plugins hold the list of plugin declared in the config. @@ -685,3 +687,15 @@ func printPluginHooks(hooks []plugin.Hook, session *cliui.Session) error { } return nil } + +func flagSetPluginsGlobal() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.BoolP(flagPluginsGlobal, "g", false, "use global plugins configuration"+ + " ($HOME/.ignite/plugins/plugins.yml)") + return fs +} + +func flagGetPluginsGlobal(cmd *cobra.Command) bool { + global, _ := cmd.Flags().GetBool(flagPluginsGlobal) + return global +} From 36db41933fcfde6ecf637138756c308f26562e65 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 10:21:40 -0500 Subject: [PATCH 72/80] return err --- ignite/cmd/plugin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 2b80a284b7..da41772508 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -36,8 +36,7 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) if err != nil && !errors.As(err, &cosmosanalysis.ErrPathNotChain{}) { - fmt.Printf("error parsing local chain plugins config: %s", err.Error()) - return nil + return err } else if err == nil { pluginsConfigs = append(pluginsConfigs, localCfg.Plugins...) From 49dcbc661949c97670984792fa6d8a5090dc8bbb Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 13 Dec 2022 10:26:33 -0500 Subject: [PATCH 73/80] Update ignite/cmd/plugin.go Co-authored-by: Thomas Bruyelle --- ignite/cmd/plugin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index da41772508..56d4d870c0 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -439,7 +439,6 @@ Example: } } - fmt.Println(global) p := pluginsconfig.Plugin{ Path: args[0], With: make(map[string]string), From 14ee295ec9060694546dda31961a4e69dc60cd65 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 10:30:37 -0500 Subject: [PATCH 74/80] format --- ignite/cmd/plugin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 56d4d870c0..bd5a3581c5 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -37,7 +37,6 @@ func LoadPlugins(ctx context.Context, rootCmd *cobra.Command) error { localCfg, err := parseLocalPlugins(rootCmd) if err != nil && !errors.As(err, &cosmosanalysis.ErrPathNotChain{}) { return err - } else if err == nil { pluginsConfigs = append(pluginsConfigs, localCfg.Plugins...) } From 10d9145fc229ac0ce8737928bf60839f6c090d7b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 10:44:30 -0500 Subject: [PATCH 75/80] fix test --- integration/plugin/plugin_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index b8193a39cf..9c3f631867 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -72,7 +72,10 @@ func TestAddRemovePlugin(t *testing.T) { assertPlugins( nil, []pluginsconfig.Plugin{ - {Path: pluginRepo}, + { + Path: pluginRepo, + Global: true, + }, }, ) From d1694b7dea4f96caac30b096219b02da5fb39627 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 10:50:47 -0500 Subject: [PATCH 76/80] remove yaml tag --- ignite/config/plugins/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 0837a4e372..22afc75627 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -38,7 +38,7 @@ type Plugin struct { With map[string]string `yaml:"with,omitempty"` // Global holds whether the plugin is installed globally // (default: $HOME/.ignite/plugins/plugins.yml) or locally for a chain. - Global bool `yaml:"global,omitempty"` + Global bool `yaml:"-"` } // Path return the path of the config file. From ae336195be06335898b477d09f2273845fd893bb Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 13 Dec 2022 11:10:56 -0500 Subject: [PATCH 77/80] Update ignite/cmd/plugin.go Co-authored-by: Thomas Bruyelle --- ignite/cmd/plugin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index bd5a3581c5..471ff3aa79 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -89,8 +89,8 @@ func parseGlobalPlugins() (cfg *pluginsconfig.Config, err error) { return &pluginsconfig.Config{}, nil } - for _, p := range cfg.Plugins { - p.Global = true + for i := range cfg.Plugins { + cfg.Plugins[i].Global = true } return } From d0a1e0c4b1cf256a4b8b6690ade61060827eef31 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 13 Dec 2022 11:19:32 -0500 Subject: [PATCH 78/80] fix test --- integration/plugin/plugin_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index 9c3f631867..1eb0ccc649 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -46,7 +46,9 @@ func TestAddRemovePlugin(t *testing.T) { // one local plugin expected assertPlugins( []pluginsconfig.Plugin{ - {Path: pluginRepo}, + { + Path: pluginRepo, + }, }, nil, ) @@ -73,8 +75,7 @@ func TestAddRemovePlugin(t *testing.T) { nil, []pluginsconfig.Plugin{ { - Path: pluginRepo, - Global: true, + Path: pluginRepo, }, }, ) From 222a0616107c3e177be73bec91ec8209fcc4a72f Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 13 Dec 2022 17:54:09 +0100 Subject: [PATCH 79/80] test: add key/value pairs to plugin add --- integration/plugin/plugin_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index 1eb0ccc649..fa67287c5d 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -38,7 +38,7 @@ func TestAddRemovePlugin(t *testing.T) { env.Must(env.Exec("add plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo), + step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo, "k1=v1", "k2=v2"), step.Workdir(app.SourcePath()), )), )) @@ -48,6 +48,10 @@ func TestAddRemovePlugin(t *testing.T) { []pluginsconfig.Plugin{ { Path: pluginRepo, + With: map[string]string{ + "k1": "v1", + "k2": "v2", + }, }, }, nil, From 604dd60714b104087d1717a4dca8923b041528f9 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 14 Dec 2022 08:57:24 -0500 Subject: [PATCH 80/80] add detailed plugin --- ignite/cmd/plugin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 471ff3aa79..91e2a10c39 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -85,6 +85,8 @@ func parseGlobalPlugins() (cfg *pluginsconfig.Config, err error) { } cfg, err = pluginsconfig.ParseDir(globalDir) + // if there is error parsing, return empty config and continue execution to load + // local plugins if they exist. if err != nil { return &pluginsconfig.Config{}, nil }