Skip to content

Use requests builder #2

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

AlexeyKrasnoperov
Copy link
Member

@AlexeyKrasnoperov AlexeyKrasnoperov commented Jul 18, 2025

filecoin-requests-builder is used to generate method definitions, k6 just goes through them.

Single method and all benchmarks supported.

First of all, a user is required to generate requests definitions, they will be stored to the methods/requests.json file, which then could be manually adjusted if needed and used to reproduce the same scenario on another server

Summary by CodeRabbit

  • New Features

    • Added a script to generate up-to-date JSON-RPC method definitions for benchmarking.
    • Introduced a new test script for benchmarking a single RPC method using dynamic parameters.
  • Bug Fixes

    • Standardized environment variable names for specifying the RPC URL across scripts and documentation.
  • Documentation

    • Enhanced README with instructions for generating method definitions and clarified benchmarking steps.
  • Chores

    • Improved .gitignore for Yarn and build artifacts.
    • Updated dependencies and npm scripts for improved workflow.
  • Refactor

    • Simplified test scripts to load method parameters from a JSON file.
    • Updated utility function to accept method names and parameters directly.
  • Revert

    • Removed obsolete test scripts and static method definitions.

@CLAassistant
Copy link

CLAassistant commented Jul 18, 2025

CLA assistant check
All committers have signed the CLA.

@AlexeyKrasnoperov AlexeyKrasnoperov marked this pull request as ready for review July 18, 2025 15:32
@AlexeyKrasnoperov AlexeyKrasnoperov requested a review from a team as a code owner July 18, 2025 15:32
@AlexeyKrasnoperov AlexeyKrasnoperov requested review from elmattic, sudo-shashank, LesnyRumcajs, a team and hanabi1224 and removed request for a team, elmattic and sudo-shashank July 18, 2025 15:32
@LesnyRumcajs
Copy link
Member

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 22, 2025

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

This set of changes refactors how JSON-RPC method definitions are managed and used for benchmarking. Static JavaScript method definitions were removed and replaced by a generated JSON file created via a new build script. Test scripts were updated to load method data dynamically from this JSON. Documentation, environment variables, and configuration files were updated accordingly, including renaming environment variables and adding instructions for generating method definitions.

Changes

File(s) Change Summary
.gitignore Refined Yarn ignore rules; added methods/requests.json to ignore list.
Makefile Renamed environment variable from K6_TEST_URL to K6_RPC_URL in all targets.
README.md Added "Methods Definitions" section; updated environment variables and benchmarking instructions; improved clarity.
package.json Added build-requests script, "type": "module" field, and new devDependency @chainsafe/filecoin-requests-builder.
scripts/build_requests.js New script to generate methods/requests.json by fetching live RPC context and building requests.
methods/index.js Removed static JavaScript RPC method definitions and exports.
tests/all.js Updated to load methods and parameters from requests.json; renamed environment variable; added error handling.
tests/single_method.js New test script to benchmark a single method using parameters from requests.json.
tests/gas_price.js, tests/top5.js Removed old test scripts that relied on static method definitions.
utils/rpc.js Refactored sendRpcRequest to accept method name and parameters explicitly instead of a method object.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant build_requests.js
    participant filecoin-requests-builder
    participant methods/requests.json

    User->>build_requests.js: Run build-requests script
    build_requests.js->>filecoin-requests-builder: fetchRpcContext(RPC_URL)
    filecoin-requests-builder-->>build_requests.js: RPC context
    build_requests.js->>filecoin-requests-builder: buildRequests(context)
    filecoin-requests-builder-->>build_requests.js: Requests object
    build_requests.js->>methods/requests.json: Write requests as JSON
Loading
sequenceDiagram
    participant K6 Test Script
    participant methods/requests.json
    participant RPC Endpoint

    K6 Test Script->>methods/requests.json: Load method definitions
    loop For each method
        K6 Test Script->>RPC Endpoint: Send request (method, params)
        RPC Endpoint-->>K6 Test Script: Response
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~45 minutes

Poem

A rabbit hopped through JSON trees,
Replacing static lists with keys.
With scripts that build and tests that run,
The codebase shines—its work well done!
Now methods flex with every call,
And bunnies cheer for changes small.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 714e1c2 and d3abae4.

📒 Files selected for processing (2)
  • tests/all.js (1 hunks)
  • tests/single_method.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/all.js
  • tests/single_method.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch use-requests-builder

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
tests/all.js (2)

7-7: Remove unnecessary await for synchronous JSON parsing.

The open() function is synchronous in k6, so await is unnecessary here.

-const requests = await JSON.parse(open('../methods/requests.json'));
+const requests = JSON.parse(open('../methods/requests.json'));

11-12: Add error handling for malformed JSON or missing file.

Consider adding error handling for cases where the JSON file is missing or malformed.

-  for (const [method, { params }] of Object.entries(requests)) {
-    const response = sendRpcRequest(url, method, params);
+  try {
+    for (const [method, { params }] of Object.entries(requests)) {
+      const response = sendRpcRequest(url, method, params);
+      assertSuccess(response);
+    }
+  } catch (error) {
+    console.error('Error processing requests:', error.message);
+    throw error;
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed231b and e55ff7d.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • .gitignore (1 hunks)
  • Makefile (1 hunks)
  • README.md (2 hunks)
  • methods/index.js (0 hunks)
  • package.json (1 hunks)
  • scripts/build_requests.js (1 hunks)
  • tests/all.js (1 hunks)
  • tests/gas_price.js (0 hunks)
  • tests/single_method.js (1 hunks)
  • tests/top5.js (0 hunks)
  • utils/rpc.js (2 hunks)
🧬 Code Graph Analysis (4)
tests/all.js (4)
scripts/build_requests.js (2)
  • url (4-4)
  • requests (7-7)
tests/single_method.js (4)
  • url (4-4)
  • requests (8-8)
  • method (5-5)
  • response (16-16)
utils/benchmark_params.js (2)
  • regularBenchmarkParams (2-8)
  • regularBenchmarkParams (2-8)
utils/rpc.js (2)
  • response (16-19)
  • sendRpcRequest (4-26)
scripts/build_requests.js (2)
tests/single_method.js (2)
  • url (4-4)
  • requests (8-8)
tests/all.js (2)
  • url (4-4)
  • requests (7-7)
tests/single_method.js (3)
scripts/build_requests.js (2)
  • url (4-4)
  • requests (7-7)
tests/all.js (5)
  • url (4-4)
  • options (6-6)
  • options (6-6)
  • requests (7-7)
  • response (12-12)
utils/rpc.js (3)
  • response (16-19)
  • sendRpcRequest (4-26)
  • assertSuccess (28-36)
utils/rpc.js (3)
scripts/build_requests.js (1)
  • url (4-4)
tests/single_method.js (3)
  • url (4-4)
  • method (5-5)
  • response (16-16)
tests/all.js (2)
  • url (4-4)
  • response (12-12)
🪛 LanguageTool
README.md

[style] ~17-~17: Consider using a less common alternative to make your writing sound more unique and professional.
Context: ...em in the methods/requests.json file. Feel free to adjust parameters manually. ## Local b...

(FEEL_FREE_TO_STYLE_ME)

💤 Files with no reviewable changes (3)
  • tests/top5.js
  • tests/gas_price.js
  • methods/index.js
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/all.js (4)
scripts/build_requests.js (2)
  • url (4-4)
  • requests (7-7)
tests/single_method.js (4)
  • url (4-4)
  • requests (8-8)
  • method (5-5)
  • response (16-16)
utils/benchmark_params.js (2)
  • regularBenchmarkParams (2-8)
  • regularBenchmarkParams (2-8)
utils/rpc.js (2)
  • response (16-19)
  • sendRpcRequest (4-26)
scripts/build_requests.js (2)
tests/single_method.js (2)
  • url (4-4)
  • requests (8-8)
tests/all.js (2)
  • url (4-4)
  • requests (7-7)
tests/single_method.js (3)
scripts/build_requests.js (2)
  • url (4-4)
  • requests (7-7)
tests/all.js (5)
  • url (4-4)
  • options (6-6)
  • options (6-6)
  • requests (7-7)
  • response (12-12)
utils/rpc.js (3)
  • response (16-19)
  • sendRpcRequest (4-26)
  • assertSuccess (28-36)
utils/rpc.js (3)
scripts/build_requests.js (1)
  • url (4-4)
tests/single_method.js (3)
  • url (4-4)
  • method (5-5)
  • response (16-16)
tests/all.js (2)
  • url (4-4)
  • response (12-12)
🪛 LanguageTool
README.md

[style] ~17-~17: Consider using a less common alternative to make your writing sound more unique and professional.
Context: ...em in the methods/requests.json file. Feel free to adjust parameters manually. ## Local b...

(FEEL_FREE_TO_STYLE_ME)

🔇 Additional comments (13)
.gitignore (1)

1-11: LGTM! Proper exclusion patterns for Yarn and generated files.

The refined Yarn exclusions follow best practices by preserving necessary Yarn subdirectories while excluding cache and PnP files. Adding methods/requests.json to gitignore is correct since this file is generated by the build script.

package.json (2)

11-11: LGTM! ES module configuration enables import syntax.

Adding "type": "module" correctly enables ES module syntax used in the new build script.


8-8: LGTM! New build script aligns with the refactoring.

The build-requests script properly integrates the new dynamic request generation workflow.

Makefile (1)

2-2: LGTM! Consistent environment variable naming.

Renaming K6_TEST_URL to K6_RPC_URL across all targets improves clarity and aligns with the standardization across the codebase.

Also applies to: 5-5, 8-8, 11-11

tests/all.js (1)

4-4: LGTM! Consistent environment variable usage.

The environment variable change to K6_RPC_URL aligns with the standardization across the codebase.

utils/rpc.js (3)

4-8: LGTM! Clean refactor of function signature.

The change from accepting a method object to separate method and params arguments is a good improvement that:

  • Makes the function signature more intuitive and explicit
  • Aligns well with the new dynamic JSON-based approach for loading method definitions
  • Eliminates the need for method objects with name and params properties

18-18: Tagging correctly updated for new signature.

The HTTP request tagging now uses the method string directly, which is consistent with the updated function signature.


22-22: Debug logging properly updated.

The debug logging now uses the method string directly, maintaining the same debugging functionality with the new signature.

README.md (2)

9-19: Excellent documentation of the new workflow.

The new "Methods Definitions" section clearly explains:

  • How to generate method definitions using the requests builder
  • The purpose and location of the generated methods/requests.json file
  • That users can manually adjust parameters for customization

This provides users with the essential information needed to work with the new dynamic approach.


24-34: Well-executed environment variable standardization.

The updates consistently replace K6_TEST_URL with the more descriptive K6_RPC_URL throughout all examples, and properly document the new K6_METHOD variable for single-method benchmarking. This improves clarity and supports the new flexible testing approach.

Also applies to: 41-41, 50-54

tests/single_method.js (3)

1-2: Proper imports for the test functionality.

The imports correctly bring in the RPC utilities and benchmark parameters needed for the single-method testing.


4-8: Well-structured configuration with appropriate defaults.

The configuration properly:

  • Uses the standardized K6_RPC_URL environment variable
  • Defaults to eth_gasPrice which is ideal for single-method testing
  • Loads the generated methods/requests.json file using the correct async pattern
  • Exports the benchmark options for k6

11-18: Robust implementation of single-method benchmarking.

The test function includes:

  • Proper validation that the requested method exists in the loaded definitions
  • Clear error messaging for unsupported methods
  • Correct usage of the updated sendRpcRequest function with separate method and params arguments
  • Appropriate success assertion

This provides a flexible foundation for benchmarking any supported RPC method.

AlexeyKrasnoperov and others added 3 commits July 24, 2025 15:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

3 participants