Skip to content

Commit

Permalink
Fix Powchain Error In Startup (#7621)
Browse files Browse the repository at this point in the history
* fix error

* add test case
  • Loading branch information
nisdas committed Oct 23, 2020
1 parent 6a2bb65 commit e776eb5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions shared/cmd/helpers.go
Expand Up @@ -75,11 +75,17 @@ func EnterPassword(confirmPassword bool, pr PasswordReader) (string, error) {

// ExpandWeb3EndpointIfFile expands the path for --http-web3provider if specified as a file.
func ExpandWeb3EndpointIfFile(ctx *cli.Context, flag *cli.StringFlag) error {
// Return early if no flag value is set.
if !ctx.IsSet(flag.Name) {
return nil
}
web3endpoint := ctx.String(flag.Name)
if !strings.HasPrefix(web3endpoint, "http://") &&
!strings.HasPrefix(web3endpoint, "https://") &&
!strings.HasPrefix(web3endpoint, "ws://") &&
!strings.HasPrefix(web3endpoint, "wss://") {
switch {
case strings.HasPrefix(web3endpoint, "http://"):
case strings.HasPrefix(web3endpoint, "https://"):
case strings.HasPrefix(web3endpoint, "ws://"):
case strings.HasPrefix(web3endpoint, "wss://"):
default:
web3endpoint, err := fileutil.ExpandPath(ctx.String(flag.Name))
if err != nil {
return errors.Wrapf(err, "could not expand path for %s", web3endpoint)
Expand Down
6 changes: 5 additions & 1 deletion shared/cmd/helpers_test.go
Expand Up @@ -84,9 +84,13 @@ func TestExpandWeb3EndpointIfFile(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
HTTPWeb3ProviderFlag := &cli.StringFlag{Name: "http-web3provider", Value: ""}
set.String(HTTPWeb3ProviderFlag.Name, "http://localhost:8545", "")
set.String(HTTPWeb3ProviderFlag.Name, "", "")
context := cli.NewContext(&app, set, nil)

// with nothing set
require.NoError(t, ExpandWeb3EndpointIfFile(context, HTTPWeb3ProviderFlag))
require.Equal(t, "", context.String(HTTPWeb3ProviderFlag.Name))

// with url scheme
require.NoError(t, context.Set(HTTPWeb3ProviderFlag.Name, "http://localhost:8545"))
require.NoError(t, ExpandWeb3EndpointIfFile(context, HTTPWeb3ProviderFlag))
Expand Down

0 comments on commit e776eb5

Please sign in to comment.