bitcoin_test.js

Overview

`bitcoin_test.js` is a performance/load testing script designed to benchmark the Bitcoin blockchain API endpoints exposed by the ShapeShift Unchained platform. Utilizing the [k6](https://k6.io/) load testing tool, it simulates high-throughput traffic against two critical REST API endpoints:

The script defines two concurrent test scenarios (`account` and `utxos`) that generate a constant arrival rate of HTTP GET requests for a duration of 5 minutes each. It uses a large predefined list of Bitcoin xpubs to cycle through requests, mimicking diverse user queries. Performance thresholds for request latency and failure rates are enforced to ensure API responsiveness and reliability under load.

This script is a vital part of the developer tooling and performance testing suite, enabling developers and QA teams to validate the scalability and robustness of the Bitcoin API layer before production deployment.


Detailed Components

Constants

xpubs


Exported Variables

options

export const options = {
  scenarios: {
    account: {
      executor: 'constant-arrival-rate',
      duration: "5m",
      rate: 1000,
      preAllocatedVUs: 1000,
      maxVUs: 2500,
      exec: 'account'
    },
    utxos: {
      executor: 'constant-arrival-rate',
      duration: "5m",
      rate: 1000,
      preAllocatedVUs: 1000,
      maxVUs: 2500,
      exec: 'utxos'
    },
  },
  thresholds: {
    'http_req_duration{scenario:account}': ['p(95) < 800'],
    'http_req_duration{scenario:utxos}': ['p(95) < 800'],
    'http_req_failed{scenario:account}': ['rate<0.01'],
    'http_req_failed{scenario:utxos}': ['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'],
}

Exported Functions

account()

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

utxos()

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

handleSummary(data)

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

Important Implementation Details


Interaction with Other System Components


Visual Diagram: Flowchart of Load Test Execution

flowchart TD
  Start[Test Start] --> Configure[Load options & scenarios]
  Configure --> Init[Initialize VUs and iteration counter]
  Init --> Loop{Iteration < Total Requests & Duration < 5m?}
  Loop -->|Yes| SelectXpub[Select xpub via iterationInTest % length]
  SelectXpub --> ChooseScenario{Which scenario?}
  ChooseScenario -->|account| GETAccount[Send GET to /account/{xpub}]
  ChooseScenario -->|utxos| GETUtxos[Send GET to /account/{xpub}/utxos]
  GETAccount --> CollectMetrics[Collect response & metrics]
  GETUtxos --> CollectMetrics
  CollectMetrics --> Loop
  Loop -->|No| Summarize[Generate summary statistics]
  Summarize --> WriteOutput[Write JSON summary to file]
  WriteOutput --> End[Test End]

Summary

`bitcoin_test.js` is a specialized k6 load test script that simulates sustained high-throughput HTTP GET traffic against Bitcoin account and UTXO API endpoints using a large dataset of xpubs. It employs constant arrival rate executors, enforces strict latency and failure thresholds, and outputs detailed JSON summaries for performance analysis. This script integrates tightly with local and staging environments orchestrated by Docker Compose and is part of the comprehensive developer tooling suite to ensure the ShapeShift Unchained Bitcoin API delivers reliable and scalable service under realistic loads.