Fix Powchain Error In Startup (#7621)

* fix error

* add test case
This commit is contained in:
Nishant Das
2020-10-23 11:57:19 +08:00
committed by GitHub
parent 6a2bb65fe2
commit e776eb5409
2 changed files with 15 additions and 5 deletions

View File

@@ -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)

View File

@@ -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))