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

Commit 84aa574

Browse files
authored
Merge pull request #11 from orbitdb/refactor-update-deps
refactor: update deps, add tests, make more lightweight
2 parents 1b0c67c + 9324b42 commit 84aa574

18 files changed

+7261
-31150
lines changed

.circleci/config.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
version: 2.1
2-
orbs:
3-
node: circleci/[email protected]
41
jobs:
5-
build-and-test:
2+
test:
63
executor:
74
name: node/default
5+
tag: 'lts'
86
steps:
97
- checkout
10-
- node/with-cache:
11-
steps:
12-
- run: npm install
13-
- run: npm test
8+
- node/install-packages
9+
- run:
10+
command: npm run test
11+
orbs:
12+
node: 'circleci/[email protected]'
13+
version: 2.1
1414
workflows:
15-
build-and-test:
16-
jobs:
17-
- build-and-test
15+
test_my_app:
16+
jobs:
17+
- test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.nyc_output

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,76 @@
1-
# OrbitDB Test Utils
1+
# OrbitDB Test Utils _(orbit-db-test-utils)_
2+
> Shared test utilities for OrbitDB-related projects
23
34
[![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)
45

5-
- Readme TBD
6+
This repository contains utilities to spin up IPFS nodes and swarms, as well
7+
as different `abstract-leveldown` implementations to use with `orbit-db-keystore`
8+
and `orbit-db-cache`.
9+
10+
For examples on how this would be used, see the `test` folder in this repo, or
11+
read on!
12+
13+
## Install
14+
15+
```bash
16+
$ npm install orbit-db-test-utils -D
17+
```
18+
19+
## Usage
20+
21+
### Spawn a single IPFS instance
22+
23+
```JavaScript
24+
const {
25+
connectPeers,
26+
startIpfs,
27+
stopIpfs,
28+
testApis,
29+
getIpfsPeerId,
30+
waitForPeers
31+
} = require('../')
32+
33+
;(async () => {
34+
// Create JS and Go nodes
35+
const ipfsd1 = await startIpfs('js-ipfs')
36+
const ipfsd2 = await startIpfs('go-ipfs')
37+
38+
// Get the peer IDs
39+
const id1 = await getIpfsPeerId(ipfsd1.api)
40+
const id2 = await getIpfsPeerId(ipfsd2.api)
41+
42+
// Helper function to connect the nodes
43+
await connectPeers(ipfsd1.api, ipfsd2.api)
44+
45+
// Test that the nodes are pubsubbing with each other
46+
const topic = 'test-topic'
47+
await ipfsd1.api.pubsub.subscribe(topic, () => {})
48+
await ipfsd2.api.pubsub.subscribe(topic, () => {})
49+
await waitForPeers(ipfsd1.api, [id2], topic)
50+
51+
// stop the nodes
52+
await stopIpfs(ipfsd1)
53+
await stopIpfs(ipfsd2)
54+
})()
55+
```
56+
57+
**Note:** You may run into issues with `stopIpfs` hanging the script due to a `js-ipfs` bug
58+
59+
### Spawn a swarm of connected IPFS instances
60+
61+
```JavaScript
62+
const { swarm } = require('orbit-db-test-utils')
63+
64+
// Enter an array of the node types you want, either 'js' or 'go'
65+
const nodeTypes = ['js', 'go', 'js']
66+
67+
swarm(nodeTypes).then(nodes => /* ... do stuff ... */)
68+
```
69+
70+
## Contributing
71+
72+
Issues and PRs are welcome.
73+
74+
## License
75+
76+
[MIT](./LICENSE) © OrbitDB Community

config/browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = {
5353
webRTCStar: {
5454
Enabled: true
5555
}
56-
},
56+
}
5757
}
5858
},
5959
daemon2: {
@@ -66,7 +66,7 @@ module.exports = {
6666
config: {
6767
Addresses: {
6868
API: '/ip4/127.0.0.1/tcp/0',
69-
"Swarm": ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'],
69+
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'],
7070
Gateway: '/ip4/0.0.0.0/tcp/0'
7171
},
7272
Bootstrap: [],
@@ -78,7 +78,7 @@ module.exports = {
7878
webRTCStar: {
7979
Enabled: true
8080
}
81-
},
81+
}
8282
}
8383
}
8484
}

config/factory.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
defaults: {
3+
type: 'proc',
4+
test: true,
5+
disposable: true,
6+
ipfsModule: require('ipfs'),
7+
init: false,
8+
start: false,
9+
ipfsOptions: {
10+
config: {
11+
Addresses: {
12+
API: '/ip4/127.0.0.1/tcp/0',
13+
Swarm: ['/ip4/0.0.0.0/tcp/0'],
14+
Gateway: '/ip4/0.0.0.0/tcp/0'
15+
},
16+
Bootstrap: []
17+
}
18+
}
19+
},
20+
overrides: {
21+
go: {
22+
test: false,
23+
ipfsHttpModule: require('ipfs-http-client'),
24+
ipfsBin: require('go-ipfs-dep').path()
25+
}
26+
}
27+
}

implementations/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const mongoUnit = require('mongo-unit')
1+
// const mongoUnit = require('mongo-unit')
22
const spawn = require('child_process').spawn
33
const exec = require('child_process').exec
44

index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
exports.MemStore = require('./mem-store')
2+
exports.swarm = require('./swarm')
13
exports.config = require('./config')
2-
exports.testAPIs = require('./test-apis')
4+
exports.connectPeers = require('./connect-peers')
5+
exports.getIpfsPeerId = require('./get-ipfs-peer-id')
36
exports.startIpfs = require('./start-ipfs')
47
exports.stopIpfs = require('./stop-ipfs')
8+
exports.testApis = require('./test-apis.js')
59
exports.waitForPeers = require('./wait-for-peers')
6-
exports.connectPeers = require('./connect-peers')
7-
exports.getIpfsPeerId = require('./get-ipfs-peer-id')
8-
exports.MemStore = require('./mem-store')
910

11+
// Different abstract-leveldown implementations
1012
const implementations = require('./implementations')
11-
12-
const properLevelModule = implementations.filter(i => i.key.indexOf('level') > -1).map(i => i.module)[0]
13+
const properLevelModule = implementations
14+
.filter(i => i.key.indexOf('level') > -1)
15+
.map(i => i.module)[0]
1316
const defaultStorage = require('orbit-db-storage-adapter')(properLevelModule)
14-
15-
exports.implementations = implementations
1617
exports.defaultStorage = defaultStorage
18+
exports.implementations = implementations

mem-store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class MemStore {
3939
}
4040

4141
const data = this._store.get(cid)
42+
43+
// TODO: Change this to refs
4244
const links = ['next', 'heads']
4345
links.forEach((prop) => {
4446
if (data[prop]) {

0 commit comments

Comments
 (0)