mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user