8000 feat(templates/cmd): upgrade spm to add 'config' cmd by ilgooz · Pull Request #1417 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(templates/cmd): upgrade spm to add 'config' cmd #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## v0.17.1
## Unreleased

### Features

- `client.toml` is initialized and used by node's CLI, can be configured through `config.yml` with the `init.client` property

## `v0.17.1`

### Fixes:

Expand All @@ -9,7 +15,7 @@
- Fixed an error in chain scaffolding due to "unknown revision"
- Fixed an error in `starport chain serve` by limiting the scope where proto files are searched for

## v0.17
## `v0.17`

### Features:

Expand Down
182 changes: 94 additions & 88 deletions integration/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,100 +47,106 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
// 1- list accounts
// 2- send tokens from one to other.
// 3- verify tx by using gRPC Gateway API.
steps := step.NewSteps(step.New(
step.Exec(
appname+"d",
"keys",
"list",
"--keyring-backend", "test",
"--output", "json",
steps := step.NewSteps(
step.New(
step.Exec(
appname+"d",
"config",
"output", "json",
),
step.PreExec(func() error {
return env.IsAppServed(ctx, host)
}),
),
step.PreExec(func() error {
output.Reset()
return env.IsAppServed(ctx, host)
}),
step.PostExec(func(execErr error) error {
if execErr != nil {
return execErr
}

addresses := []string{}

// collect addresses of alice and bob.
accounts := []struct {
Name string `json:"name"`
Address string `json:"address"`
}{}
if err := json.NewDecoder(output).Decode(&accounts); err != nil {
return err
}
for _, account := range accounts {
if account.Name == "alice" || account.Name == "bob" {
addresses = append(addresses, account.Address)
step.New(
step.Exec(
appname+"d",
"keys",
"list",
"--keyring-backend", "test",
),
step.PostExec(func(execErr error) error {
if execErr != nil {
return execErr
}
}
if len(addresses) != 2 {
return errors.New("expected alice and bob accounts to be created")
}

// send some tokens from alice to bob and confirm the corresponding tx via gRPC gateway
// endpoint by asserting denom and amount.
return cmdrunner.New().Run(ctx, step.New(
step.Exec(
appname+"d",
"tx",
"bank",
"send",
addresses[0],
addresses[1],
"10token",
"--keyring-backend", "test",
"--chain-id", appname,
"--node", xurl.TCP(host.RPC),
"--yes",
),
step.PreExec(func() error {
output.Reset()
return nil
}),
step.PostExec(func(execErr error) error {
if execErr != nil {
return execErr
}

tx := struct {
Hash string `json:"txHash"`
}{}
if err := json.NewDecoder(output).Decode(&tx); err != nil {
return err
}

addr := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", xurl.HTTP(host.API), tx.Hash)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, addr, nil)
if err != nil {
return errors.Wrap(err, "call to get tx via gRPC gateway")
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
addresses := []string{}

// Send error if the request failed
if resp.StatusCode != http.StatusOK {
return errors.New(resp.Status)
// collect addresses of alice and bob.
accounts := []struct {
Name string `json:"name"`
Address string `json:"address"`
}{}
if err := json.NewDecoder(output).Decode(&accounts); err != nil {
return err
}
for _, account := range accounts {
if account.Name == "alice" || account.Name == "bob" {
addresses = append(addresses, account.Address)
}
}
if len(addresses) != 2 {
return errors.New("expected alice and bob accounts to be created")
}

if err := json.NewDecoder(resp.Body).Decode(&txBody); err != nil {
return err
}
return nil
}),
step.Stdout(output),
))
}),
step.Stdout(output),
))
// send some tokens from alice to bob and confirm the corresponding tx via gRPC gateway
// endpoint by asserting denom and amount.
return cmdrunner.New().Run(ctx, step.New(
step.Exec(
appname+"d",
"tx",
"bank",
"send",
addresses[0],
addresses[1],
"10token",
"--keyring-backend", "test",
"--chain-id", appname,
"--node", xurl.TCP(host.RPC),
"--yes",
),
step.PreExec(func() error {
output.Reset()
return nil
}),
step.PostExec(func(execErr error) error {
if execErr != nil {
return execErr
}

tx := struct {
Hash string `json:"txHash"`
}{}
if err := json.NewDecoder(output).Decode(&tx); err != nil {
return err
}

addr := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", xurl.HTTP(host.API), tx.Hash)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, addr, nil)
if err != nil {
return errors.Wrap(err, "call to get tx via gRPC gateway")
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

// Send error if the request failed
if resp.StatusCode != http.StatusOK {
return errors.New(resp.Status)
}

if err := json.NewDecoder(resp.Body).Decode(&txBody); err != nil {
return err
}
return nil
}),
step.Stdout(output),
))
}),
step.Stdout(output),
))

go func() {
defer cancel()
Expand Down
3 changes: 3 additions & 0 deletions starport/chainconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ type Init struct {
// App overwrites appd's config/app.toml configs.
App map[string]interface{} `yaml:"app"`

// Client overwrites appd's config/client.toml configs.
Client map[string]interface{} `yaml:"client"`

// Config overwrites appd's config/config.toml configs.
Config map[string]interface{} `yaml:"config"`

Expand Down
4 changes: 2 additions & 2 deletions starport/services/chain/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const checksumTxt = "checksum.txt"

// Build builds and installs app binaries.
func (c *Chain) Build(ctx context.Context) (binaryName string, err error) {
if err := c.setup(ctx); err != nil {
if err := c.setup(); err != nil {
return "", err
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *Chain) BuildRelease(ctx context.Context, prefix string, targets ...stri
}

// prepare for build.
if err := c.setup(ctx); err != nil {
if err := c.setup(); err != nil {
return "", err
}

Expand Down
16 changes: 12 additions & 4 deletions starport/services/chain/chain.go
F438
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chain

import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -306,7 +305,7 @@ func (c *Chain) GenesisPath() (string, error) {
if err != nil {
return "", err
}
return fmt.Sprintf("%s/config/genesis.json", home), nil
return filepath.Join(home, "config/genesis.json"), nil
}

// AppTOMLPath returns app.toml path of the app.
Expand All @@ -315,7 +314,7 @@ func (c *Chain) AppTOMLPath() (string, error) {
if err != nil {
return "", err
}
return fmt.Sprintf("%s/config/app.toml", home), nil
return filepath.Join(home, "config/app.toml"), nil
}

// ConfigTOMLPath returns config.toml path of the app.
Expand All @@ -324,7 +323,16 @@ func (c *Chain) ConfigTOMLPath() (string, error) {
if err != nil {
return "", err
}
return fmt.Sprintf("%s/config/config.toml", home), nil
return filepath.Join(home, "config/config.toml"), nil
}

// ClientTOMLPath returns client.toml path of the app.
func (c *Chain) ClientTOMLPath() (string, error) {
home, err := c.Home()
if err != nil {
return "", err
}
return filepath.Join(home, "config/client.toml"), nil
}

// Commands returns the runner execute commands on the chain's binary
Expand Down
32 changes: 10 additions & 22 deletions starport/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func (c *Chain) InitChain(ctx context.Context) error {
// overwrite configuration changes from Starport's config.yml to
// over app's sdk configs.

if err := c.plugin.Configure(home, conf); err != nil {
return err
}

// make sure that chain id given during chain.New() has the most priority.
if conf.Genesis != nil {
conf.Genesis["chain_id"] = chainID
Expand All @@ -82,6 +86,10 @@ func (c *Chain) InitChain(ctx context.Context) error {
if err != nil {
return err
}
clientTOMLPath, err := c.ClientTOMLPath()
if err != nil {
return err
}
configTOMLPath, err := c.ConfigTOMLPath()
if err != nil {
return err
Expand All @@ -94,6 +102,7 @@ func (c *Chain) InitChain(ctx context.Context) error {
}{
{confile.DefaultJSONEncodingCreator, genesisPath, conf.Genesis},
{confile.DefaultTOMLEncodingCreator, appTOMLPath, conf.Init.App},
{confile.DefaultTOMLEncodingCreator, clientTOMLPath, conf.Init.Client},
{confile.DefaultTOMLEncodingCreator, configTOMLPath, conf.Init.Config},
}

Expand All @@ -111,8 +120,7 @@ func (c *Chain) InitChain(ctx context.Context) error {
}
}

// run post init handler
return c.plugin.PostInit(home, conf)
return nil
}

// InitAccounts initializes the chain accounts and creates validator gentxs
Expand Down Expand Up @@ -159,11 +167,6 @@ func (c *Chain) InitAccounts(ctx context.Context, conf conf.Config) error {
}
}

// perform configuration in the chain config
if err := c.configure(ctx); err != nil {
return err
}

// create the gentx from the validator from the config
if _, err := c.plugin.Gentx(ctx, commands, Validator{
Name: conf.Validator.Name,
Expand Down Expand Up @@ -200,21 +203,6 @@ func (c *Chain) IsInitialized() (bool, error) {
return true, nil
}

func (c *Chain) configure(ctx context.Context) error {
// configure blockchain.
chainID, err := c.ID()
if err != nil {
return err
}

commands, err := c.Commands(ctx)
if err != nil {
return err
}

return c.plugin.Configure(ctx, commands, chainID)
}

type Validator struct {
Name string
Moniker string
Expand Down
Loading
0