orbit-db-test-utils

3.0.0 • Public • Published

OrbitDB Test Utils (orbit-db-test-utils)

Shared test utilities for OrbitDB-related projects

Gitter Matrix CircleCI

This repository contains utilities to spin up IPFS nodes and swarms, as well as different abstract-leveldown implementations to use with orbit-db-keystore and orbit-db-cache.

For examples on how this would be used, see the test folder in this repo, or read on!

Install

$ npm install -D orbit-db-test-utils

Usage

Spawn a single IPFS instance

const {
  connectPeers,
  startIpfs,
  stopIpfs,
  getIpfsPeerId,
  waitForPeers
} = require('../')

;(async () => {
  // Create JS and Go nodes
  const ipfsd1 = await startIpfs('js-ipfs')
  const ipfsd2 = await startIpfs('go-ipfs')

  // Get the peer IDs
  const id1 = await getIpfsPeerId(ipfsd1.api)
  const id2 = await getIpfsPeerId(ipfsd2.api)

  // Helper function to connect the nodes
  await connectPeers(ipfsd1.api, ipfsd2.api)

  // Test that the nodes are pubsubbing with each other
  const topic = 'test-topic'
  await ipfsd1.api.pubsub.subscribe(topic, () => {})
  await ipfsd2.api.pubsub.subscribe(topic, () => {})
  await waitForPeers(ipfsd1.api, [id2], topic)

  // stop the nodes
  await stopIpfs(ipfsd1)
  await stopIpfs(ipfsd2)
})()

Note: You may run into issues with stopIpfs hanging the script due to a js-ipfs bug

Contributing

Issues and PRs are welcome.

License

MIT © OrbitDB Community

Readme

Keywords

none

Package Sidebar

Install

npm i orbit-db-test-utils

Weekly Downloads

11

Version

3.0.0

License

MIT

Unpacked Size

4.86 MB

Total Files

16

Last publish

Collaborators

  • hajamark