Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: transform url arg into a flag #138

Merged
merged 17 commits into from
Oct 21, 2023
Merged

chore: transform url arg into a flag #138

merged 17 commits into from
Oct 21, 2023

Conversation

leovct
Copy link
Member

@leovct leovct commented Oct 18, 2023

Description

🚨 Breaking change 🚨

It's just a suggestion, no problem if we don't merge it :)

This pull request enhances the loadtest, loadtest uniswapv3, monitor and rpcfuzz commands by transforming the url argument into a more flexible and user-friendly flag called rpc-url. With this update, users can now set the URL as a flag, offering greater control and simplicity in command usage, following the standards employed by other tools such as cast.

By default, the rpc-url flag is set to http://localhost:8545.

$ polycli loadtest --help | grep rpc-url
  -r, --rpc-url string                        The RPC endpoint url (default "http://localhost:8545")

It's now possible to run polycli loadtest. If you were specifying the url as an argument previously, you can switch from polycli loadtest <url> to polycli loadtest --rpc-url <url> or polycli loadtest -r <url>.

Other

  • Move most of the logic related to cobra.Command to a separate file cmd.go or app.go for each cmd.
  • Move logic related to flags in checkFlags and logic responsible for running the cmd in a specific func.
  • Add a method to validate urls in util, to be reused in other commands also.

For example, here's how the monitor cmd looks now.

// cmd/monitor/cmd.go

// MonitorCmd represents the monitor command
var MonitorCmd = &cobra.Command{
	Use:   "monitor",
	Short: "Monitor blocks using a JSON-RPC endpoint.",
	Long:  usage,
	Args:  cobra.NoArgs,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return checkFlags()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		return monitor(cmd.Context())
	},
}

Jira / Linear Tickets

Testing

x

@leovct leovct requested a review from a team October 19, 2023 11:20
@leovct leovct marked this pull request as ready for review October 19, 2023 11:20
@leovct
Copy link
Member Author

leovct commented Oct 19, 2023

If we end up merging this PR, we should make sure we update the polycli loadtest uniswapv3 cmd (see #137)

@leovct leovct changed the title chore(loadtest): remove url arg chore: transform url arg into a flag Oct 19, 2023
@leovct
Copy link
Member Author

leovct commented Oct 20, 2023

If we end up merging this PR, we should make sure we update the polycli loadtest uniswapv3 cmd (see #137)

Implemented in the PR ✅

Comment on lines -82 to -99
func validateUrl(input string) (*url.URL, error) {
url, err := url.Parse(input)
if err != nil {
log.Error().Err(err).Msg("Unable to parse url input error")
return nil, err
}

if url.Scheme == "" {
return nil, errors.New("the scheme has not been specified")
}
switch url.Scheme {
case "http", "https", "ws", "wss":
return url, nil
default:
return nil, fmt.Errorf("the scheme %s is not supported", url.Scheme)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice simplification here

@@ -14,7 +14,7 @@
Run a generic load test against an Eth/EVM style JSON-RPC endpoint.

```bash
polycli loadtest url [flags]
polycli loadtest [flags]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: potentially add comment here that rpc-url default is localhost

@@ -98,6 +98,7 @@ The command also inherits flags from parent commands.
--private-key string The hex encoded private key that we'll use to send transactions (default "42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa")
--rate-limit float An overall limit to the number of requests per second. Give a number less than zero to remove this limit all together (default 4)
-n, --requests int Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results. (default 1)
-r, --rpc-url string The RPC endpoint url (default "http://localhost:8545")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, this is perfect

@@ -37,10 +37,10 @@ geth-loadtest: build fund ## Run loadtest against an EVM/Geth chain.
sleep 5
$(BUILD_DIR)/$(BIN_NAME) loadtest \
--verbosity 700 \
--rpc-url http://127.0.0.1:$(PORT) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: potentially make host configurable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we could, this is just a handy command to trigger load test in ci :)

Copy link
Contributor

@rebelArtists rebelArtists left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, couple nits but not a blocker

@leovct leovct merged commit 6d912a6 into main Oct 21, 2023
5 checks passed
@leovct leovct deleted the chore/remove-url-arg branch October 21, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants