vaporyjs-stub-rpc-server
TypeScript icon, indicating that this package has built-in type declarations

2.1.6 • Public • Published

npm version

Purpose

Allow for easy stubbing of an Vapory node when testing Vapory dApp clients. It allows you to stub out a response to any request with whatever result you like so it is easy to write tests for your dApps without having to run a full Vapory node or do actual mining. It is intended to be run inside your tests and a new server should be created/destroyed with each test case, though you could re-use across test cases if you are okay with using the same responses in each test.

This library is not intended to simulate the inner workings of a real Vapory node, only allow you to define canned responses to requests made of an Vapory node. It supports requests over HTTP, WS or IPC. It dose have some basic simulation build in (can be overriden or removed) for things like vap_sendTransaction, vap_getBlock, net_version (and others) and it has a .mine() function to allow you to simulate mining a block that includes pending transactions. PRs welcome for additional baked-in behaviors, though the goal is to keep them relatively simply with a focus on validating request payloads and returning responses that are shaped correctly.

Usage

describe("my vapory integration test", () => {
	var server;
	beforeEach(function () {
		server = require('vaporyjs-stub-rpc-server').createStubServer('HTTP', 'http://localhost:1337');
	});
	afterEach(function () {
		server.destroy();
	});

	it("uses a stub server", () => {
		server.addExpectation((requestJso) => requestJso.method === "net_version");
		server.addResponder((requestJso) => (requestJso.method === "net_version") ? "apple" : undefined);
		myPreferredVaporyJsLibrary.netVersion().then((version) => {
			assert.strictEqual(version, "apple");
			server.assertExpectations();
		});
	});
});

To see the public surface area of this project in TypeScript definition format plus JSDocs (which a TypeScript aware editor will understand) check out source/index.d.ts. You can also see the tests for more full featured examples (in particular, see adds sent transaction to block when mined for an interesting one that does mining).

Dependencies (2)

Dev Dependencies (3)

Package Sidebar

Install

npm i vaporyjs-stub-rpc-server

Weekly Downloads

0

Version

2.1.6

License

CC0-1.0

Unpacked Size

29.8 kB

Total Files

11

Last publish

Collaborators

  • marlonhanks