Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
release-0.9.0: upgrade to js-ipfs 0.43.0 and go-ipfs 0.5.0, swarm api
Browse files Browse the repository at this point in the history
  • Loading branch information
aphelionz committed May 11, 2020
1 parent 1b0c67c commit 0034ad9
Show file tree
Hide file tree
Showing 18 changed files with 7,266 additions and 31,153 deletions.
22 changes: 11 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
version: 2.1
orbs:
node: circleci/[email protected]
jobs:
build-and-test:
test:
executor:
name: node/default
tag: 'lts'
steps:
- checkout
- node/with-cache:
steps:
- run: npm install
- run: npm test
- node/install-packages
- run:
command: npm run test
orbs:
node: 'circleci/[email protected]'
version: 2.1
workflows:
build-and-test:
jobs:
- build-and-test
test_my_app:
jobs:
- test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nyc_output
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
# OrbitDB Test Utils
# OrbitDB Test Utils _(orbit-db-test-utils)_
> Shared test utilities for OrbitDB-related projects
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![Matrix](https://img.shields.io/badge/matrix-%23orbitdb%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#orbitdb:permaweb.io) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/cscuf5T)

- Readme TBD
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

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

## Usage

### Spawn a single IPFS instance

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

;(async () => {
// Create JS and Go nodes
ipfsd1 = await startIpfs('js-ipfs')
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)
})()
```

### Spawn a swarm of connected IPFS instances

```JavaScript
const { swarm } = require('orbit-db-test-utils')

// Enter an array of the node types you want, either 'js' or 'go'
const nodeTypes = ['js', 'go', 'js']

swarm(nodeTypes).then(nodes => /* ... do stuff ... */)
```


**Note:** The previously used `startIpfs` and `stopIpfs` functionality is **deprecated**
and should be avoided and refactored away.

## Contributing

Issues and PRs are welcome.

## License

[MIT](./LICENSE.md) © OrbitDB Community
>>>>>>> cf5458c... refactor: update deps and utilize new ipfsd-ctl
6 changes: 3 additions & 3 deletions config/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
webRTCStar: {
Enabled: true
}
},
}
}
},
daemon2: {
Expand All @@ -66,7 +66,7 @@ module.exports = {
config: {
Addresses: {
API: '/ip4/127.0.0.1/tcp/0',
"Swarm": ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'],
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'],
Gateway: '/ip4/0.0.0.0/tcp/0'
},
Bootstrap: [],
Expand All @@ -78,7 +78,7 @@ module.exports = {
webRTCStar: {
Enabled: true
}
},
}
}
}
}
27 changes: 27 additions & 0 deletions config/factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
defaults: {
type: 'proc',
test: true,
disposable: true,
ipfsModule: require('ipfs'),
init: false,
start: false,
ipfsOptions: {
config: {
Addresses: {
API: '/ip4/127.0.0.1/tcp/0',
Swarm: ['/ip4/0.0.0.0/tcp/0'],
Gateway: '/ip4/0.0.0.0/tcp/0'
},
Bootstrap: []
}
}
},
overrides: {
go: {
test: false,
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require('go-ipfs-dep').path()
}
}
}
2 changes: 1 addition & 1 deletion implementations/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoUnit = require('mongo-unit')
// const mongoUnit = require('mongo-unit')
const spawn = require('child_process').spawn
const exec = require('child_process').exec

Expand Down
27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
exports.config = require('./config')
exports.testAPIs = require('./test-apis')
exports.startIpfs = require('./start-ipfs')
exports.stopIpfs = require('./stop-ipfs')
exports.waitForPeers = require('./wait-for-peers')
exports.connectPeers = require('./connect-peers')
exports.getIpfsPeerId = require('./get-ipfs-peer-id')
exports.MemStore = require('./mem-store')
exports.swarm = require('./swarm')

// Different abstract-leveldown implementations
const implementations = require('./implementations')

const properLevelModule = implementations.filter(i => i.key.indexOf('level') > -1).map(i => i.module)[0]
const properLevelModule = implementations
.filter(i => i.key.indexOf('level') > -1)
.map(i => i.module)[0]
const defaultStorage = require('orbit-db-storage-adapter')(properLevelModule)

exports.implementations = implementations
exports.defaultStorage = defaultStorage
exports.implementations = implementations

// Deprecated APIs
// startIpfs and stopIpfs will throw console.warn-ings
exports.config = require('./config')
exports.connectPeers = require('./connect-peers')
exports.getIpfsPeerId = require('./get-ipfs-peer-id')
exports.startIpfs = require('./start-ipfs')
exports.stopIpfs = require('./stop-ipfs')
exports.testApis = require('./test-apis.js')
exports.waitForPeers = require('./wait-for-peers')
2 changes: 2 additions & 0 deletions mem-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class MemStore {
}

const data = this._store.get(cid)

// TODO: Change this to refs
const links = ['next', 'heads']
links.forEach((prop) => {
if (data[prop]) {
Expand Down
Loading

0 comments on commit 0034ad9

Please sign in to comment.