Skip to content
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
24 changes: 12 additions & 12 deletions integration/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ func (e env) EnsureAppIsSteady(appPath string) {

// IsAppServed checks that app is served properly and servers are started to listening
// before ctx canceled.
func (e env) IsAppServed(ctx context.Context, servers starportconf.Servers) error {
func (e env) IsAppServed(ctx context.Context, host starportconf.Host) error {
checkAlive := func() error {
ok, err := httpstatuschecker.Check(ctx, xurl.HTTP(servers.APIAddr)+"/node_info")
ok, err := httpstatuschecker.Check(ctx, xurl.HTTP(host.API)+"/node_info")
if err == nil && !ok {
err = errors.New("app is not online")
}
Expand All @@ -242,7 +242,7 @@ func (e env) TmpDir() (path string) {

// RandomizeServerPorts randomizes server ports for the app at path, updates
// its config.yml and returns new values.
func (e env) RandomizeServerPorts(path string, configFile string) starportconf.Servers {
func (e env) RandomizeServerPorts(path string, configFile string) starportconf.Host {
if configFile == "" {
configFile = "config.yml"
}
Expand All @@ -255,14 +255,14 @@ func (e env) RandomizeServerPorts(path string, configFile string) starportconf.S
return fmt.Sprintf("localhost:%d", port)
}

servers := starportconf.Servers{
RPCAddr: genAddr(ports[0]),
P2PAddr: genAddr(ports[1]),
ProfAddr: genAddr(ports[2]),
GRPCAddr: genAddr(ports[3]),
APIAddr: genAddr(ports[4]),
FrontendAddr: genAddr(ports[5]),
DevUIAddr: genAddr(ports[6]),
servers := starportconf.Host{
RPC: genAddr(ports[0]),
P2P: genAddr(ports[1]),
Prof: genAddr(ports[2]),
GRPC: genAddr(ports[3]),
API: genAddr(ports[4]),
Frontend: genAddr(ports[5]),
DevUI: genAddr(ports[6]),
}

// update config.yml with the generated servers list.
Expand All @@ -273,7 +273,7 @@ func (e env) RandomizeServerPorts(path string, configFile string) starportconf.S
var conf starportconf.Config
require.NoError(e.t, yaml.NewDecoder(configyml).Decode(&conf))

conf.Servers = servers
conf.Host = servers
require.NoError(e.t, configyml.Truncate(0))
_, err = configyml.Seek(0, 0)
require.NoError(e.t, err)
Expand Down
8 changes: 4 additions & 4 deletions integration/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
env = newEnv(t)
appname = randstr.Runes(10)
path = env.Scaffold(appname, Stargate)
servers = env.RandomizeServerPorts(path, "")
host = env.RandomizeServerPorts(path, "")
ctx, cancel = context.WithCancel(env.Ctx())
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
),
step.PreExec(func() error {
output.Reset()
return env.IsAppServed(ctx, servers)
return env.IsAppServed(ctx, host)
}),
step.PostExec(func(execErr error) error {
if execErr != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
"10token",
"--keyring-backend", "test",
"--chain-id", appname,
"--node", xurl.TCP(servers.RPCAddr),
"--node", xurl.TCP(host.RPC),
"--yes",
),
step.PreExec(func() error {
Expand All @@ -115,7 +115,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
return err
}

addr := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", xurl.HTTP(servers.APIAddr), tx.Hash)
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")
Expand Down
59 changes: 37 additions & 22 deletions starport/chainconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ var (

// DefaultConf holds default configuration.
DefaultConf = Config{
Servers: Servers{
RPCAddr: "0.0.0.0:26657",
P2PAddr: "0.0.0.0:26656",
ProfAddr: "0.0.0.0:6060",
GRPCAddr: "0.0.0.0:9090",
APIAddr: "0.0.0.0:1317",
FrontendAddr: "0.0.0.0:8080",
DevUIAddr: "0.0.0.0:12345",
Host: Host{
RPC: ":26657",
P2P: ":26656",
Prof: ":6060",
GRPC: ":9090",
API: ":1317",
Frontend: ":8080",
DevUI: ":12345",
},
Build: Build{
Proto: Proto{
Expand All @@ -39,7 +39,7 @@ var (
},
},
Faucet: Faucet{
Port: 4500,
Host: ":4500",
},
}
)
Expand All @@ -53,7 +53,7 @@ type Config struct {
Build Build `yaml:"build"`
Init Init `yaml:"init"`
Genesis map[string]interface{} `yaml:"genesis"`
Servers Servers `yaml:"servers"`
Host Host `yaml:"host"`
}

// AccountByName finds account by name.
Expand Down Expand Up @@ -101,9 +101,6 @@ type Proto struct {

// Faucet configuration.
type Faucet struct {
// Port number for faucet server to listen at.
Port int `yaml:"port"`

// Name is faucet account's name.
Name *string `yaml:"name"`

Expand All @@ -113,6 +110,12 @@ type Faucet struct {
// CoinsMax holds of chain denoms and their max amounts that can be transferred
// to single user.
CoinsMax []string `yaml:"coins_max"`

// Host is the host of the faucet server
Host string `yaml:"host"`

// Port number for faucet server to listen at.
Port int `yaml:"port"`
}

// Init overwrites sdk configurations with given values.
Expand All @@ -133,15 +136,15 @@ type Init struct {
KeyringBackend string `yaml:"keyring-backend"`
}

// Servers keeps configuration related to started servers.
type Servers struct {
RPCAddr string `yaml:"rpc-address"`
P2PAddr string `yaml:"p2p-address"`
ProfAddr string `yaml:"prof-address"`
GRPCAddr string `yaml:"grpc-address"`
APIAddr string `yaml:"api-address"`
FrontendAddr string `yaml:"frontend-address"`
DevUIAddr string `yaml:"dev-ui-address"`
// Host keeps configuration related to started servers.
type Host struct {
RPC string `yaml:"rpc"`
P2P string `yaml:"p2p"`
Prof string `yaml:"prof"`
GRPC string `yaml:"grpc"`
API string `yaml:"api"`
Frontend string `yaml:"frontend"`
DevUI string `yaml:"dev-ui"`
}

// Parse parses config.yml into UserConfig.
Expand Down Expand Up @@ -198,3 +201,15 @@ func LocateDefault(root string) (path string, err error) {
}
return "", ErrCouldntLocateConfig
}

// FaucetHost returns the faucet host to use
func FaucetHost(conf Config) string {
// We keep supporting Port option for backward compatibility
// TODO: drop this option in the future
host := conf.Faucet.Host
if conf.Faucet.Port != 0 {
host = fmt.Sprintf(":%d", conf.Faucet.Port)
}

return host
}
52 changes: 52 additions & 0 deletions starport/chainconf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,55 @@ accounts:
_, err := Parse(strings.NewReader(confyml))
require.Equal(t, &ValidationError{"validator is required"}, err)
}

func TestFaucetHost(t *testing.T) {
confyml := `
accounts:
- name: me
coins: ["1000token", "100000000stake"]
- name: you
coins: ["5000token"]
validator:
name: user1
staked: "100000000stake"
faucet:
host: "0.0.0.0:4600"
`
conf, err := Parse(strings.NewReader(confyml))
require.NoError(t, err)
require.Equal(t, "0.0.0.0:4600", FaucetHost(conf))

confyml = `
accounts:
- name: me
coins: ["1000token", "100000000stake"]
- name: you
coins: ["5000token"]
validator:
name: user1
staked: "100000000stake"
faucet:
port: 4700
`
conf, err = Parse(strings.NewReader(confyml))
require.NoError(t, err)
require.Equal(t, ":4700", FaucetHost(conf))

// Port must be higher priority
confyml = `
accounts:
- name: me
coins: ["1000token", "100000000stake"]
- name: you
coins: ["5000token"]
validator:
name: user1
staked: "100000000stake"
faucet:
host: "0.0.0.0:4600"
port: 4700
`
conf, err = Parse(strings.NewReader(confyml))
require.NoError(t, err)
require.Equal(t, ":4700", FaucetHost(conf))
}
4 changes: 2 additions & 2 deletions starport/services/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (c *Chain) RPCPublicAddress() (string, error) {
if err != nil {
return "", err
}
rpcAddress = conf.Servers.RPCAddr
rpcAddress = conf.Host.RPC
}
return rpcAddress, nil
}
Expand Down Expand Up @@ -423,7 +423,7 @@ func (c *Chain) Commands(ctx context.Context) (chaincmdrunner.Runner, error) {
chaincmd.WithChainID(id),
chaincmd.WithHome(home),
chaincmd.WithVersion(c.Version),
chaincmd.WithNodeAddress(xurl.TCP(config.Servers.RPCAddr)),
chaincmd.WithNodeAddress(xurl.TCP(config.Host.RPC)),
}

if c.plugin.Version() == cosmosver.Launchpad {
Expand Down
2 changes: 1 addition & 1 deletion starport/services/chain/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Chain) Faucet(ctx context.Context) (cosmosfaucet.Faucet, error) {
}

// construct faucet options.
apiAddress := conf.Servers.APIAddr
apiAddress := conf.Host.API
if envAPIAddress != "" {
apiAddress = envAPIAddress
}
Expand Down
8 changes: 4 additions & 4 deletions starport/services/chain/plugin-launchpad.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (p *launchpadPlugin) configtoml(homePath string, conf starportconf.Config)
return err
}
config.Set("rpc.cors_allowed_origins", []string{"*"})
config.Set("rpc.laddr", xurl.TCP(conf.Servers.RPCAddr))
config.Set("p2p.laddr", xurl.TCP(conf.Servers.P2PAddr))
config.Set("rpc.pprof_laddr", conf.Servers.ProfAddr)
config.Set("rpc.laddr", xurl.TCP(conf.Host.RPC))
config.Set("p2p.laddr", xurl.TCP(conf.Host.P2P))
config.Set("rpc.pprof_laddr", conf.Host.Prof)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
Expand All @@ -111,7 +111,7 @@ func (p *launchpadPlugin) Start(ctx context.Context, runner chaincmdrunner.Runne
})

g.Go(func() error {
err := runner.LaunchpadStartRestServer(ctx, xurl.TCP(conf.Servers.APIAddr), xurl.TCP(conf.Servers.RPCAddr))
err := runner.LaunchpadStartRestServer(ctx, xurl.TCP(conf.Host.API), xurl.TCP(conf.Host.RPC))
return errors.Wrapf(err, "cannot run %[1]vcli rest-server", p.app.Name)
})

Expand Down
12 changes: 6 additions & 6 deletions starport/services/chain/plugin-stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (p *stargatePlugin) apptoml(homePath string, conf starportconf.Config) erro
config.Set("api.enable", true)
config.Set("api.enabled-unsafe-cors", true)
config.Set("rpc.cors_allowed_origins", []string{"*"})
config.Set("api.address", xurl.TCP(conf.Servers.APIAddr))
config.Set("grpc.address", conf.Servers.GRPCAddr)
config.Set("api.address", xurl.TCP(conf.Host.API))
config.Set("grpc.address", conf.Host.GRPC)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
Expand All @@ -89,9 +89,9 @@ func (p *stargatePlugin) configtoml(homePath string, conf starportconf.Config) e
config.Set("rpc.cors_allowed_origins", []string{"*"})
config.Set("consensus.timeout_commit", "1s")
config.Set("consensus.timeout_propose", "1s")
config.Set("rpc.laddr", xurl.TCP(conf.Servers.RPCAddr))
config.Set("p2p.laddr", xurl.TCP(conf.Servers.P2PAddr))
config.Set("rpc.pprof_laddr", conf.Servers.ProfAddr)
config.Set("rpc.laddr", xurl.TCP(conf.Host.RPC))
config.Set("p2p.laddr", xurl.TCP(conf.Host.P2P))
config.Set("rpc.pprof_laddr", conf.Host.Prof)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
Expand All @@ -106,7 +106,7 @@ func (p *stargatePlugin) Start(ctx context.Context, runner chaincmdrunner.Runner
"--pruning",
"nothing",
"--grpc.address",
conf.Servers.GRPCAddr,
conf.Host.GRPC,
)
return &CannotStartAppError{p.app.Name, err}
}
Expand Down
Loading