ethereum_test.js


Overview

The `ethereum_test.js` file is a performance/load testing script designed specifically for Ethereum blockchain API endpoints. It uses the [k6](https://k6.io/) load testing framework to simulate high throughput GET requests against the Ethereum account API provided by ShapeShift’s Ethereum service.

Its main purpose is to validate the API's ability to handle sustained, concurrent traffic by:

This script plays a critical role in continuous performance validation and ensuring the Ethereum API's robustness under load.


Detailed Explanation

Imported Modules

Constants

addresses

An array of 150+ Ethereum address strings (checksummed) used to distribute GET requests among different accounts. This variety mimics realistic traffic patterns by querying diverse accounts rather than repeatedly hitting the same endpoint.


Exported Variables and Functions

options

export const options = {
  scenarios: {
    rps: {
      executor: 'constant-arrival-rate',
      duration: "5m",
      rate: 1000,
      preAllocatedVUs: 2500,
      maxVUs: 10000,
    },
  },
  thresholds: {
    'http_req_duration{scenario:rps}': ['p(95) < 800'],
    'http_req_failed{scenario:rps}': ['rate<0.01'],
    'http_req_duration{status:200}': ['max>=0'],
    'http_req_duration{status:429}': ['max>=0'],
  },
  summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(90)', 'p(95)', 'p(99)', 'count'],
}

Default Exported Function

export default function () {
  http.get(`https://api.ethereum.shapeshift.com/api/v1/account/${addresses[exec.scenario.iterationInTest % addresses.length]}`)
}

handleSummary Function

export function handleSummary(data) {
  return {
    "/out/ethereum/results/result.json": JSON.stringify(data),
  }
}

Important Implementation Details


Interaction with Other System Components


Usage Example

To run this load test locally (assuming k6 is installed):

k6 run ethereum_test.js

This will execute the constant arrival rate scenario sending 1000 requests per second for 5 minutes against the Ethereum account API, cycling through the predefined addresses.

After completion, a summary JSON report will be saved to `/out/ethereum/results/result.json`.


Mermaid Diagram: Flowchart of Main Functions and Their Relationships

flowchart TD
    A[Start of Test] --> B[Initialize Scenario Options]
    B --> C[For each iteration in scenario]
    C --> D[Calculate address index: iterationInTest % addresses.length]
    D --> E[Perform HTTP GET request to Ethereum account endpoint]
    E --> F[Collect metrics: duration, status, errors]
    F --> G{Thresholds met?}
    G -->|Yes| C
    G -->|No| H[Log threshold violation]
    C --> I{Test duration reached?}
    I -->|No| C
    I -->|Yes| J[Invoke handleSummary]
    J --> K[Write result JSON to /out/ethereum/results/result.json]
    K --> L[End of Test]

Summary

The `ethereum_test.js` is a focused k6 load testing script that simulates sustained high request rates against the ShapeShift Ethereum API. By cycling through a comprehensive list of Ethereum addresses, it realistically mimics user traffic patterns. Its configuration enforces strict latency and failure thresholds to ensure API reliability and performance. The script integrates smoothly with local development environments and CI workflows through detailed result reporting, making it a vital tool for continuous performance validation of the Ethereum API service.