Skip to content
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run:
tests: false
skip-dirs:
- starport/ui
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/imdario/mergo v0.3.11
github.com/improbable-eng/grpc-web v0.13.0
github.com/jpillora/chisel v1.7.3
github.com/magefile/mage v1.11.0 // indirect
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-zglob v0.0.3
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76
Expand All @@ -39,6 +40,7 @@ require (
github.com/rdegges/go-ipify v0.0.0-20150526035502-2d94a6a86c40
github.com/rogpeppe/go-internal v1.7.0 // indirect
github.com/rs/cors v1.7.0
github.com/sirupsen/logrus v1.8.0 // indirect
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
Expand All @@ -47,6 +49,7 @@ require (
golang.org/x/mod v0.4.1
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210218085108-9555bcde0c6a // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
google.golang.org/grpc v1.35.0
)
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0U
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY=
Expand Down Expand Up @@ -738,6 +742,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -1018,6 +1024,8 @@ golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210218085108-9555bcde0c6a h1:+Kiu2GijIw0WaCBk1i7AcqqRx8Xg3HIYaheQazXOu8w=
golang.org/x/sys v0.0.0-20210218085108-9555bcde0c6a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
Expand Down
64 changes: 50 additions & 14 deletions integration/cmd_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package integration_test

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -14,7 +17,7 @@ func TestServeLaunchpadAppWithWasm(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("blog", Launchpad)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

env.Must(env.Exec("add Wasm module",
Expand All @@ -32,7 +35,7 @@ func TestServeLaunchpadAppWithWasm(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Wasm", apath, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Wasm", apath, "", "", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
Expand All @@ -41,7 +44,7 @@ func TestServeLaunchpadAppWithCustomHomes(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("blog2", Launchpad)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

var (
Expand All @@ -52,7 +55,7 @@ func TestServeLaunchpadAppWithCustomHomes(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Wasm", apath, "./home", "./clihome", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Wasm", apath, "./home", "./clihome", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
Expand All @@ -61,11 +64,11 @@ func TestServeLaunchpadAppWithConfigHomes(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("blog3", Launchpad)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

// Set config homes
env.SetRandomHomeConfig(apath)
env.SetRandomHomeConfig(apath, "")

var (
ctx, cancel = context.WithTimeout(env.Ctx(), serveTimeout)
Expand All @@ -75,7 +78,7 @@ func TestServeLaunchpadAppWithConfigHomes(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Wasm", apath, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Wasm", apath, "", "", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
Expand All @@ -84,7 +87,7 @@ func TestServeStargateWithWasm(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("sgblog", Stargate)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

env.Must(env.Exec("add Wasm module",
Expand All @@ -102,7 +105,7 @@ func TestServeStargateWithWasm(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Stargate version", apath, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Stargate version", apath, "", "", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
Expand All @@ -111,7 +114,7 @@ func TestServeStargateWithCustomHome(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("sgblog2", Stargate)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

var (
Expand All @@ -122,7 +125,7 @@ func TestServeStargateWithCustomHome(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Stargate version", apath, "./home", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Stargate version", apath, "./home", "", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
Expand All @@ -131,11 +134,11 @@ func TestServeStargateWithConfigHome(t *testing.T) {
var (
env = newEnv(t)
apath = env.Scaffold("sgblog3", Stargate)
servers = env.RandomizeServerPorts(apath)
servers = env.RandomizeServerPorts(apath, "")
)

// Set config homes
env.SetRandomHomeConfig(apath)
env.SetRandomHomeConfig(apath, "")

var (
ctx, cancel = context.WithTimeout(env.Ctx(), serveTimeout)
Expand All @@ -145,7 +148,40 @@ func TestServeStargateWithConfigHome(t *testing.T) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Stargate version", apath, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve with Stargate version", apath, "", "", "", ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}

func TestServeStargateWithCustomConfigFile(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "starporttest")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

var (
env = newEnv(t)
apath = env.Scaffold("sgblog4", Stargate)
)
// Move config
newConfig := "new_config.yml"
newConfigPath := filepath.Join(tmpDir, newConfig)
err = os.Rename(filepath.Join(apath, "config.yml"), newConfigPath)
require.NoError(t, err)

servers := env.RandomizeServerPorts(tmpDir, newConfig)

// Set config homes
env.SetRandomHomeConfig(tmpDir, newConfig)

var (
ctx, cancel = context.WithTimeout(env.Ctx(), serveTimeout)
isBackendAliveErr error
)
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve with Stargate version", apath, "", "", newConfigPath, ExecCtx(ctx)))

require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
4 changes: 2 additions & 2 deletions integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func testOverwriteSDKConfigsAndChainID(t *testing.T, sdkVersion string) {
env = newEnv(t)
appname = randstr.Runes(10)
path = env.Scaffold(appname, sdkVersion)
servers = env.RandomizeServerPorts(path)
servers = env.RandomizeServerPorts(path, "")
ctx, cancel = context.WithCancel(env.Ctx())
isBackendAliveErr error
)
Expand All @@ -51,7 +51,7 @@ func testOverwriteSDKConfigsAndChainID(t *testing.T, sdkVersion string) {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers)
}()
env.Must(env.Serve("should serve", path, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve", path, "", "", "", ExecCtx(ctx)))
require.NoError(t, isBackendAliveErr, "app cannot get online in time")

configs := []struct {
Expand Down
21 changes: 16 additions & 5 deletions integration/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (e env) Scaffold(appName, sdkVersion string) (appPath string) {
// Serve serves an application lives under path with options where msg describes the
// expection from the serving action.
// unless calling with Must(), Serve() will not exit test runtime on failure.
func (e env) Serve(msg, path, home, clihome string, options ...execOption) (ok bool) {
func (e env) Serve(msg, path, home, clihome, configPath string, options ...execOption) (ok bool) {
serveCommand := []string{
"serve",
"-v",
Expand All @@ -194,6 +194,9 @@ func (e env) Serve(msg, path, home, clihome string, options ...execOption) (ok b
if clihome != "" {
serveCommand = append(serveCommand, "--cli-home", clihome)
}
if configPath != "" {
serveCommand = append(serveCommand, "--config", configPath)
}

return e.Exec(msg,
step.NewSteps(step.New(
Expand Down Expand Up @@ -238,7 +241,11 @@ 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) starportconf.Servers {
func (e env) RandomizeServerPorts(path string, configFile string) starportconf.Servers {
if configFile == "" {
configFile = "config.yml"
}

// generate random server ports and servers list.
ports, err := availableport.Find(7)
require.NoError(e.t, err)
Expand All @@ -258,7 +265,7 @@ func (e env) RandomizeServerPorts(path string) starportconf.Servers {
}

// update config.yml with the generated servers list.
configyml, err := os.OpenFile(filepath.Join(path, "config.yml"), os.O_RDWR|os.O_CREATE, 0755)
configyml, err := os.OpenFile(filepath.Join(path, configFile), os.O_RDWR|os.O_CREATE, 0755)
require.NoError(e.t, err)
defer configyml.Close()

Expand All @@ -275,9 +282,13 @@ func (e env) RandomizeServerPorts(path string) starportconf.Servers {
}

// SetRandomHomeConfig sets in the blockchain config files generated temporary directories for home directories
func (e env) SetRandomHomeConfig(path string) {
func (e env) SetRandomHomeConfig(path string, configFile string) {
if configFile == "" {
configFile = "config.yml"
}

// update config.yml with the generated temporary directories
configyml, err := os.OpenFile(filepath.Join(path, "config.yml"), os.O_RDWR|os.O_CREATE, 0755)
configyml, err := os.OpenFile(filepath.Join(path, configFile), os.O_RDWR|os.O_CREATE, 0755)
require.NoError(e.t, err)
defer configyml.Close()

Expand Down
4 changes: 2 additions & 2 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)
servers = env.RandomizeServerPorts(path, "")
ctx, cancel = context.WithCancel(env.Ctx())
)

Expand Down Expand Up @@ -148,7 +148,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
isTxBodyRetrieved = env.Exec("retrieve account addresses", steps, ExecRetry())
}()

env.Must(env.Serve("should serve", path, "", "", ExecCtx(ctx)))
env.Must(env.Serve("should serve", path, "", "", "", ExecCtx(ctx)))

if !isTxBodyRetrieved {
t.FailNow()
Expand Down
8 changes: 5 additions & 3 deletions starport/chainconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ func (e *ValidationError) Error() string {
return fmt.Sprintf("config is not valid: %s", e.Message)
}

// Locate locates the path for the config file otherwise returns ErrCouldntLocateConfig.
func Locate(root string) (path string, err error) {
// LocateDefault locates the default path for the config file, if no file found returns ErrCouldntLocateConfig.
func LocateDefault(root string) (path string, err error) {
for _, name := range FileNames {
path = filepath.Join(root, name)
if _, err := os.Stat(path); !os.IsNotExist(err) {
if _, err := os.Stat(path); err == nil {
return path, nil
} else if !os.IsNotExist(err) {
return "", err
}
}
return "", ErrCouldntLocateConfig
Expand Down
16 changes: 14 additions & 2 deletions starport/interface/cli/starport/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

const flagForceReset = "force-reset"
const flagResetOnce = "reset-once"
const flagConfig = "config"

var appPath string

Expand All @@ -23,17 +24,28 @@ func NewServe() *cobra.Command {
c.Flags().StringVarP(&appPath, "path", "p", "", "Path of the app")
c.Flags().BoolP("verbose", "v", false, "Verbose output")
c.Flags().BoolP(flagForceReset, "f", false, "Force reset of the app state on start and every source change")
c.Flags().BoolP(flagResetOnce, "r", false, "Reset of the app state on first start")
c.Flags().BoolP(flagResetOnce, "r", false, "Reset of -the app state on first start")
c.Flags().StringP(flagConfig, "c", "", "Starport config file (default: ./config.yml)")

return c
}

func serveHandler(cmd *cobra.Command, args []string) error {
// create the chain
chainOption := []chain.Option{
chain.LogLevel(logLevel(cmd)),
chain.KeyringBackend(chaincmd.KeyringBackendTest),
}

// check if custom config is defined
config, err := cmd.Flags().GetString(flagConfig)
if err != nil {
return err
}
if config != "" {
chainOption = append(chainOption, chain.ConfigFile(config))
}

// create the chain
c, err := newChainWithHomeFlags(cmd, appPath, chainOption...)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion starport/pkg/dirchange/dirchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func checksumFromPaths(workdir string, paths []string) ([]byte, error) {

// read files
for _, path := range paths {
if workdir != "" {
if !filepath.IsAbs(path) {
path = filepath.Join(workdir, path)
}

Expand Down
5 changes: 4 additions & 1 deletion starport/pkg/fswatcher/fswatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func (w *watcher) listen() {

func (w *watcher) addPaths(paths ...string) {
for _, path := range paths {
w.wt.AddRecursive(filepath.Join(w.workdir, path))
if !filepath.IsAbs(path) {
path = filepath.Join(w.workdir, path)
}
w.wt.AddRecursive(path)
}
}

Expand Down
Loading