npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hashspan/faults

v0.2.0

Published

A JSON-RPC fault proxy for tests: puts an HTTP proxy between an EVM client and a local node and makes chosen methods hang, fail, reset or answer wrong.

Readme

@hashspan/faults

A JSON-RPC fault proxy for tests. It sits between an EVM client and a local node, such as Anvil, and makes chosen JSON-RPC methods hang, fail with an HTTP status or a JSON-RPC error, drop or reset the connection, cut an answer off mid-body, or answer with a wrong result. The client talks to a real HTTP server, so its own transport, retries and backoff run as they do in production, which a mocked transport does not show.

It works with any client that speaks JSON-RPC over HTTP: viem, ethers, web3.js, a bundler or a facilitator. It is the proxy behind the fault tests of hashspan, but does not depend on it.

Install

npm install --save-dev @hashspan/faults

Node.js only: it is an HTTP server built on node:http. Requires Node.js 22.3 or later. No dependencies.

Usage

import { startFaultProxy } from '@hashspan/faults';

// In front of a local node, such as Anvil on http://127.0.0.1:8545.
const proxy = await startFaultProxy(nodeUrl);

// The second eth_blockNumber gets a rate limit; the others reach the node.
proxy.set({ eth_blockNumber: { fault: { kind: 'http', status: 429 }, after: 1, times: 1 } });
for (let id = 1; id <= 3; id++) {
  const response = await fetch(proxy.url, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ jsonrpc: '2.0', id, method: 'eth_blockNumber', params: [] }),
  });
  console.log(response.status, await response.text()); // 200 {"jsonrpc":"2.0","id":1,"result":"0x..."}, 429 ...
}
console.log(proxy.requests()); // { eth_blockNumber: 3 }

await proxy.stop();

With viem, pass the proxy's URL to the transport, http(proxy.url): with retryCount: 0 each fault reaches your code as it is, and with viem's retries on you test them.

startFaultProxy(upstream, options?) resolves to a proxy on a free port of 127.0.0.1:

| Member | What it does | |---|---| | url | the proxy's URL, for the client's HTTP transport | | set(rules) | replaces every rule, by JSON-RPC method, and restarts the counts | | requests() | the requests of every method since the last set(), as { [method]: count } | | requests(method) | the requests of one method since the last set(), faulted ones included | | stop() | closes the proxy and every connection it holds, hanging ones included |

Faults

| Fault | What the client gets | Reaches the node | |---|---|---| | { kind: 'hang' } | no answer; its own timeout ends the request | no | | { kind: 'http', status } | that HTTP status without a JSON-RPC body, such as 429 | no | | { kind: 'rpc-error', code, message? } | a JSON-RPC error with the request's id, such as -32005 | no | | { kind: 'reset' } | a connection reset (TCP RST) before any byte of the answer | no | | { kind: 'drop' } | the connection closed (TCP FIN) before any byte | no | | { kind: 'truncate' } | the headers, with a content-length larger than what follows, and part of the body, then a connection reset (TCP RST) | no | | { kind: 'result', result } | the node's result replaced by result(nodeResult, call) | once | | { kind: 'previous' } | the result of this method's previous request, as a load balancer that mixes up answers | once |

call counts the method's requests since the last set(), from 1, so result can return a receipt that stays null, a malformed block or a chain id that changes between calls. Under result and previous, a node answer that is not JSON is answered with 502; the proxy keeps serving.

Rules

A rule is a fault, or { fault, after?, times? }: after requests of the method are passed on untouched before the fault applies (default 0), and it applies to times requests (default: all after that). A method can have a list of rules; the first that applies to a request is used. Every rule counts from the method's first request since the last set():

// Request 1 hangs, request 2 fails, request 3 and later reach the node.
proxy.set({
  eth_getTransactionReceipt: [
    { fault: { kind: 'hang' }, times: 1 },
    { fault: { kind: 'rpc-error', code: -32603 }, after: 1, times: 1 },
  ],
});

// No faults.
proxy.set({});

Only single JSON-RPC requests are matched. Batches (JSON arrays) and bodies that are not JSON are passed on untouched and are not counted.

Safety

The proxy is meant for a node on your own machine:

  • It listens on 127.0.0.1 only, on a free port.
  • It refuses an upstream that is not loopback: an IPv4 address of 127.0.0.0/8, [::1] or localhost, judged from the URL as written, without resolving names. Any other host, a compose service name such as anvil included, needs startFaultProxy(upstream, { allowRemoteUpstream: true }). Only http: and https: upstreams are accepted.
  • It sends at most one upstream request per request it receives: no retries, no fan-out and no load features.
  • It never follows a redirect: a 3xx answer of the upstream goes back to the client as it is.

startFaultProxy() rejects when the upstream is refused or the port cannot be bound. A request the proxy cannot pass on, such as one to an upstream that is down, is answered with 502.

Compatibility

This package is 0.x while its fault model settles; a new kind of fault comes in a minor release. The design, with the faults planned next, is in ADR 0032.

License

Apache-2.0