mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-05-19 13:26:37 +00:00
Merge pull request #335 from orbitdb/feat/tests-with-ipfsd-ctl
Use ipfsd-ctl to create test IPFS instances
This commit is contained in:
commit
99c69b6b74
232
package-lock.json
generated
232
package-lock.json
generated
@ -295,6 +295,12 @@
|
||||
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==",
|
||||
"dev": true
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
|
||||
"dev": true
|
||||
},
|
||||
"atob": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.0.3.tgz",
|
||||
@ -1823,6 +1829,32 @@
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||
"dev": true
|
||||
},
|
||||
"comandante": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/comandante/-/comandante-0.0.1.tgz",
|
||||
"integrity": "sha1-gFHaYILocgiq3VK9gXJ1t8gDUAk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"duplexer": "0.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"duplexer": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.0.4.tgz",
|
||||
"integrity": "sha1-r8t/H4uNdPggcmFx1dZKyeSo/yA=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz",
|
||||
"integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"delayed-stream": "1.0.0"
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.15.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
|
||||
@ -1956,6 +1988,12 @@
|
||||
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=",
|
||||
"dev": true
|
||||
},
|
||||
"cookiejar": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.1.tgz",
|
||||
"integrity": "sha1-Qa1XsbVVlR7BcUEqgZQrHoIA00o=",
|
||||
"dev": true
|
||||
},
|
||||
"copy-concurrently": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
||||
@ -2257,6 +2295,12 @@
|
||||
"isobject": "3.0.1"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||
"dev": true
|
||||
},
|
||||
"delegates": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
|
||||
@ -2393,6 +2437,12 @@
|
||||
"create-hmac": "1.1.6"
|
||||
}
|
||||
},
|
||||
"duplexer": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
|
||||
"integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
|
||||
"dev": true
|
||||
},
|
||||
"duplexer3": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
|
||||
@ -2962,6 +3012,12 @@
|
||||
"resolved": "https://registry.npmjs.org/expand-template/-/expand-template-1.1.0.tgz",
|
||||
"integrity": "sha512-kkjwkMqj0h4w/sb32ERCDxCQkREMCAgS39DscDnSwDsbxnwwM1BTZySdC3Bn1lhY7vL08n9GoO/fVTynjDgRyQ=="
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
||||
"integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=",
|
||||
"dev": true
|
||||
},
|
||||
"extend-shallow": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz",
|
||||
@ -3164,6 +3220,23 @@
|
||||
"integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=",
|
||||
"dev": true
|
||||
},
|
||||
"form-data": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz",
|
||||
"integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asynckit": "0.4.0",
|
||||
"combined-stream": "1.0.6",
|
||||
"mime-types": "2.1.18"
|
||||
}
|
||||
},
|
||||
"formidable": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz",
|
||||
"integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==",
|
||||
"dev": true
|
||||
},
|
||||
"fragment-cache": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz",
|
||||
@ -5382,6 +5455,12 @@
|
||||
"integrity": "sha1-EPIJmg18BaQPK+r1wdOc8vfavzY=",
|
||||
"dev": true
|
||||
},
|
||||
"hat": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/hat/-/hat-0.0.3.tgz",
|
||||
"integrity": "sha1-uwFKnmSzeIrtgAWRdBPU/z1QLYo=",
|
||||
"dev": true
|
||||
},
|
||||
"he": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
|
||||
@ -5548,6 +5627,12 @@
|
||||
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=",
|
||||
"dev": true
|
||||
},
|
||||
"individual": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/individual/-/individual-2.0.0.tgz",
|
||||
"integrity": "sha1-gzsJfa0jKU52EXqY+zjg2a1hu5c=",
|
||||
"dev": true
|
||||
},
|
||||
"inert": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/inert/-/inert-4.2.1.tgz",
|
||||
@ -6041,6 +6126,37 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"ipfsd-ctl": {
|
||||
"version": "0.30.4",
|
||||
"resolved": "https://registry.npmjs.org/ipfsd-ctl/-/ipfsd-ctl-0.30.4.tgz",
|
||||
"integrity": "sha512-GZ8uzZ7AZ/DhgVQZ8f1j1sTuzOPMBAszDPd3p4ucxRd9kdlatxlFTaRyLlQB9/A+gx90SUQF8nKTqr5ZDWJ0yg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"async": "2.6.0",
|
||||
"boom": "7.2.0",
|
||||
"debug": "3.1.0",
|
||||
"detect-node": "2.0.3",
|
||||
"hapi": "16.6.3",
|
||||
"hat": "0.0.3",
|
||||
"ipfs-api": "18.2.1",
|
||||
"ipfs-repo": "0.18.7",
|
||||
"joi": "13.1.2",
|
||||
"lodash.clone": "4.5.0",
|
||||
"lodash.defaults": "4.2.0",
|
||||
"lodash.defaultsdeep": "4.6.0",
|
||||
"multiaddr": "3.1.0",
|
||||
"once": "1.4.0",
|
||||
"readable-stream": "2.3.5",
|
||||
"rimraf": "2.6.2",
|
||||
"safe-json-parse": "4.0.0",
|
||||
"safe-json-stringify": "1.1.0",
|
||||
"shutdown": "0.3.0",
|
||||
"stream-http": "2.8.1",
|
||||
"subcomandante": "1.0.5",
|
||||
"superagent": "3.8.2",
|
||||
"truthy": "0.0.1"
|
||||
}
|
||||
},
|
||||
"ipld": {
|
||||
"version": "0.15.0",
|
||||
"resolved": "https://registry.npmjs.org/ipld/-/ipld-0.15.0.tgz",
|
||||
@ -6441,6 +6557,12 @@
|
||||
"integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=",
|
||||
"dev": true
|
||||
},
|
||||
"is-running": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/is-running/-/is-running-1.0.5.tgz",
|
||||
"integrity": "sha1-4IikdniNqbE7kTxsgT1WQK1j0ig=",
|
||||
"dev": true
|
||||
},
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
@ -7244,6 +7366,12 @@
|
||||
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.clone": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz",
|
||||
"integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
@ -7255,6 +7383,18 @@
|
||||
"integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.defaults": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
||||
"integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.defaultsdeep": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.0.tgz",
|
||||
"integrity": "sha1-vsECT4WxvZbL6kBbI8FK1kQ6b4E=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.filter": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.filter/-/lodash.filter-4.6.0.tgz",
|
||||
@ -7607,6 +7747,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"methods": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
||||
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=",
|
||||
"dev": true
|
||||
},
|
||||
"micromatch": {
|
||||
"version": "3.1.10",
|
||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz",
|
||||
@ -7646,6 +7792,12 @@
|
||||
"brorand": "1.1.0"
|
||||
}
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
||||
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
||||
"dev": true
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.33.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
|
||||
@ -9489,11 +9641,35 @@
|
||||
"aproba": "1.2.0"
|
||||
}
|
||||
},
|
||||
"rust-result": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/rust-result/-/rust-result-1.0.0.tgz",
|
||||
"integrity": "sha1-NMdbLm3Dn+WHXlveyFteD5FTb3I=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"individual": "2.0.0"
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
||||
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
|
||||
},
|
||||
"safe-json-parse": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-json-parse/-/safe-json-parse-4.0.0.tgz",
|
||||
"integrity": "sha1-fA9XjPzNEtM6ccDgVBPi7KFx6qw=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"rust-result": "1.0.0"
|
||||
}
|
||||
},
|
||||
"safe-json-stringify": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-json-stringify/-/safe-json-stringify-1.1.0.tgz",
|
||||
"integrity": "sha512-EzBtUaFH9bHYPc69wqjp0efJI/DPNHdFbGE3uIMn4sVbO0zx8vZ8cG4WKxQfOpUOKsQyGBiT2mTqnCw+6nLswA==",
|
||||
"dev": true
|
||||
},
|
||||
"safe-regex": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
|
||||
@ -9668,6 +9844,27 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"shutdown": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/shutdown/-/shutdown-0.3.0.tgz",
|
||||
"integrity": "sha1-AmlEfnzQ+AW6TpxNj5N9LbPvtZQ=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"async": "2.6.0",
|
||||
"debug": "2.6.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
@ -10322,6 +10519,17 @@
|
||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
|
||||
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo="
|
||||
},
|
||||
"subcomandante": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/subcomandante/-/subcomandante-1.0.5.tgz",
|
||||
"integrity": "sha1-JoL4/FMbik+u3xWnV4lkp9YmCVk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"comandante": "0.0.1",
|
||||
"duplexer": "0.1.1",
|
||||
"is-running": "1.0.5"
|
||||
}
|
||||
},
|
||||
"subtext": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/subtext/-/subtext-5.0.0.tgz",
|
||||
@ -10352,6 +10560,24 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"superagent": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.2.tgz",
|
||||
"integrity": "sha512-gVH4QfYHcY3P0f/BZzavLreHW3T1v7hG9B+hpMQotGQqurOvhv87GcMCd6LWySmBuf+BDR44TQd0aISjVHLeNQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"component-emitter": "1.2.1",
|
||||
"cookiejar": "2.1.1",
|
||||
"debug": "3.1.0",
|
||||
"extend": "3.0.1",
|
||||
"form-data": "2.3.2",
|
||||
"formidable": "1.2.1",
|
||||
"methods": "1.1.2",
|
||||
"mime": "1.6.0",
|
||||
"qs": "6.5.1",
|
||||
"readable-stream": "2.3.5"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
|
||||
@ -10587,6 +10813,12 @@
|
||||
"utf8-byte-length": "1.0.4"
|
||||
}
|
||||
},
|
||||
"truthy": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/truthy/-/truthy-0.0.1.tgz",
|
||||
"integrity": "sha1-eJ8zBZ3B8C/dkM8FY6yxpnZvx7w=",
|
||||
"dev": true
|
||||
},
|
||||
"tty-browserify": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz",
|
||||
|
@ -32,8 +32,9 @@
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"datastore-level": "~0.7.0",
|
||||
"ipfs": "~0.28.0",
|
||||
"ipfs-repo": "~0.18.0",
|
||||
"ipfs": "~0.28.2",
|
||||
"ipfs-repo": "~0.18.7",
|
||||
"ipfsd-ctl": "~0.30.3",
|
||||
"mocha": "^4.0.1",
|
||||
"p-each-series": "^1.0.0",
|
||||
"p-map-series": "^1.0.0",
|
||||
|
@ -374,12 +374,8 @@ class OrbitDB {
|
||||
databaseTypes[type] = store
|
||||
}
|
||||
|
||||
static create () {
|
||||
return new Error('Not implemented yet!')
|
||||
}
|
||||
|
||||
static open () {
|
||||
return new Error('Not implemented yet!')
|
||||
static getDatabaseTypes () {
|
||||
return databaseTypes
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,35 +1,44 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const mapSeries = require('p-each-series')
|
||||
const path = require('path')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const waitForPeers = require('./utils/wait-for-peers')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
connectPeers,
|
||||
waitForPeers,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/counters/peer1'
|
||||
const dbPath2 = './orbitdb/tests/counters/peer2'
|
||||
const ipfsPath1 = './orbitdb/tests/counters/peer1/ipfs'
|
||||
const ipfsPath2 = './orbitdb/tests/counters/peer2/ipfs'
|
||||
|
||||
describe('CounterStore', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Counters (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let orbitdb1, orbitdb2
|
||||
let ipfs1, ipfs2
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
|
||||
before(async () => {
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
config.daemon1.repo = ipfsPath1
|
||||
config.daemon2.repo = ipfsPath2
|
||||
ipfs1 = await startIpfs(config.daemon1)
|
||||
ipfs2 = await startIpfs(config.daemon2)
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
// Connect the peers manually to speed up test times
|
||||
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
@ -39,11 +48,11 @@ describe('CounterStore', function() {
|
||||
if (orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfs1)
|
||||
await ipfs1.stop()
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
|
||||
if (ipfs2)
|
||||
await ipfs2.stop()
|
||||
if (ipfsd2)
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
@ -62,6 +71,18 @@ describe('CounterStore', function() {
|
||||
describe('counters', function() {
|
||||
let address
|
||||
|
||||
it('creates and opens a database', async () => {
|
||||
const db = await orbitdb1.counter('counter database')
|
||||
assert.notEqual(db, null)
|
||||
assert.equal(db.type, 'counter')
|
||||
assert.equal(db.dbname, 'counter database')
|
||||
})
|
||||
|
||||
it('value is undefined when it\'s a fresh database', async () => {
|
||||
const db = await orbitdb1.feed('counter database')
|
||||
assert.equal(db.value, undefined)
|
||||
})
|
||||
|
||||
it('increases a counter value', async () => {
|
||||
const counter = await orbitdb1.counter('counter test', { path: dbPath1 })
|
||||
address = counter.address.toString()
|
||||
@ -109,7 +130,8 @@ describe('CounterStore', function() {
|
||||
assert.equal(counter1.value, 30)
|
||||
assert.equal(counter2.value, 30)
|
||||
resolve()
|
||||
}, 5000)
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,31 +1,39 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const mapSeries = require('p-map-series')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const rmrf = require('rimraf')
|
||||
const mapSeries = require('p-map-series')
|
||||
const levelup = require('levelup')
|
||||
const leveldown = require('leveldown')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const OrbitDBAddress = require('../src/orbit-db-address')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/create-open'
|
||||
const ipfsPath = './orbitdb/tests/create-open/ipfs'
|
||||
|
||||
describe('orbit-db - Create & Open', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Create & Open (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb, db, address
|
||||
let ipfsd, ipfs, orbitdb, db, address
|
||||
let localDataPath
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb = new OrbitDB(ipfs, dbPath)
|
||||
})
|
||||
|
||||
@ -33,8 +41,8 @@ describe('orbit-db - Create & Open', function() {
|
||||
if(orbitdb)
|
||||
await orbitdb.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('Create', function() {
|
||||
@ -62,8 +70,8 @@ describe('orbit-db - Create & Open', function() {
|
||||
it('throws an error if database already exists', async () => {
|
||||
let err
|
||||
try {
|
||||
db = await orbitdb.create('first', 'feed')
|
||||
db = await orbitdb.create('first', 'feed')
|
||||
db = await orbitdb.create('first', 'feed', { replicate: false })
|
||||
db = await orbitdb.create('first', 'feed', { replicate: false })
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
@ -74,7 +82,7 @@ describe('orbit-db - Create & Open', function() {
|
||||
it('throws an error if database type doesn\'t match', async () => {
|
||||
let err, log, kv
|
||||
try {
|
||||
log = await orbitdb.kvstore('keyvalue')
|
||||
log = await orbitdb.kvstore('keyvalue', { replicate: false })
|
||||
kv = await orbitdb.eventlog(log.address.toString())
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
@ -85,7 +93,7 @@ describe('orbit-db - Create & Open', function() {
|
||||
|
||||
describe('Success', function() {
|
||||
before(async () => {
|
||||
db = await orbitdb.create('second', 'feed')
|
||||
db = await orbitdb.create('second', 'feed', { replicate: false })
|
||||
localDataPath = path.join(dbPath, db.address.root, db.address.path)
|
||||
await db.close()
|
||||
})
|
||||
@ -256,3 +264,5 @@ describe('orbit-db - Create & Open', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -1,16 +1,21 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const config = require('./utils/config')
|
||||
const rmrf = require('rimraf')
|
||||
const DocumentStore = require('orbit-db-docstore')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const rmrf = require('rimraf')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/create-open'
|
||||
const ipfsPath = './orbitdb/tests/create-open/ipfs'
|
||||
|
||||
|
||||
class CustomStore extends DocumentStore {
|
||||
constructor (ipfs, id, dbname, options) {
|
||||
super(ipfs, id, dbname, options)
|
||||
@ -22,22 +27,27 @@ class CustomStore extends DocumentStore {
|
||||
}
|
||||
}
|
||||
|
||||
describe('orbit-db - Create custom type', function () {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Create Custom Database Type (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb
|
||||
let ipfsd, ipfs, orbitdb
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb = new OrbitDB(ipfs, dbPath)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (orbitdb) await orbitdb.stop()
|
||||
if (ipfs) await ipfs.stop()
|
||||
if (ipfsd) await stopIpfs(ipfsd)
|
||||
// Remove the added custom database type from OrbitDB
|
||||
// between js-ipfs and js-ipfs-api tests
|
||||
delete OrbitDB.getDatabaseTypes()[CustomStore.type]
|
||||
})
|
||||
|
||||
describe('addDatabaseType', function () {
|
||||
@ -57,3 +67,4 @@ describe('orbit-db - Create custom type', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -3,9 +3,14 @@
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const customTestKeystore = require('./utils/custom-test-keystore')
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
CustomTestKeystore,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/customKeystore'
|
||||
const ipfsPath = './orbitdb/tests/customKeystore/ipfs'
|
||||
@ -53,18 +58,20 @@ const databases = [
|
||||
},
|
||||
]
|
||||
|
||||
describe('orbit-db - Using custom keystore', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Use a Custom Keystore (${API})`, function() {
|
||||
this.timeout(20000)
|
||||
|
||||
let ipfs, orbitdb1
|
||||
let ipfsd, ipfs, orbitdb1
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1', {
|
||||
keystore: customTestKeystore
|
||||
keystore: CustomTestKeystore
|
||||
})
|
||||
})
|
||||
|
||||
@ -72,8 +79,8 @@ describe('orbit-db - Using custom keystore', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('allows orbit to use a custom keystore with different store types', function() {
|
||||
@ -109,3 +116,4 @@ describe('orbit-db - Using custom keystore', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -3,21 +3,29 @@
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/docstore'
|
||||
const ipfsPath = './orbitdb/tests/docstore/ipfs'
|
||||
|
||||
describe('orbit-db - Document Store', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Document Store (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb1, db
|
||||
let ipfsd, ipfs, orbitdb1, db
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
})
|
||||
|
||||
@ -25,13 +33,15 @@ describe('orbit-db - Document Store', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
it('creates and opens a database', async () => {
|
||||
db = await orbitdb1.docstore('first doc database')
|
||||
db = await orbitdb1.docstore('first doc database')
|
||||
assert.notEqual(db, null)
|
||||
assert.equal(db.type, 'docstore')
|
||||
assert.equal(db.dbname, 'first doc database')
|
||||
})
|
||||
|
||||
describe('Default index \'_id\'', function() {
|
||||
@ -160,3 +170,4 @@ describe('orbit-db - Document Store', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -5,23 +5,31 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/drop'
|
||||
const ipfsPath = './orbitdb/tests/drop/ipfs'
|
||||
|
||||
describe('orbit-db - Drop Database', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Drop Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb, db, address
|
||||
let ipfsd, ipfs, orbitdb, db, address
|
||||
let localDataPath
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb = new OrbitDB(ipfs, dbPath)
|
||||
})
|
||||
|
||||
@ -29,8 +37,8 @@ describe('orbit-db - Drop Database', function() {
|
||||
if(orbitdb)
|
||||
await orbitdb.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
|
||||
rmrf.sync(dbPath)
|
||||
})
|
||||
@ -48,3 +56,4 @@ describe('orbit-db - Drop Database', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,27 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const mapSeries = require('p-map-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const last = arr => arr[arr.length - 1]
|
||||
|
||||
const dbPath = './orbitdb/tests/eventlog'
|
||||
const ipfsPath = './orbitdb/tests/eventlog/ipfs'
|
||||
|
||||
describe('orbit-db - Eventlog', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Log Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb1, db
|
||||
let ipfsd, ipfs, orbitdb1, db
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
})
|
||||
|
||||
@ -29,14 +37,20 @@ describe('orbit-db - Eventlog', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('Eventlog', function () {
|
||||
it('creates and opens a database', async () => {
|
||||
db = await orbitdb1.eventlog('first database')
|
||||
db = await orbitdb1.eventlog('first database')
|
||||
db = await orbitdb1.eventlog('log database')
|
||||
assert.notEqual(db, null)
|
||||
assert.equal(db.type, 'eventlog')
|
||||
assert.equal(db.dbname, 'log database')
|
||||
})
|
||||
|
||||
it('returns 0 items when it\'s a fresh database', async () => {
|
||||
db = await orbitdb1.eventlog('log database')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.equal(items.length, 0)
|
||||
})
|
||||
@ -51,6 +65,8 @@ describe('orbit-db - Eventlog', function() {
|
||||
})
|
||||
|
||||
it('returns the added entry\'s hash, 2 entries', async () => {
|
||||
db = await orbitdb1.eventlog('first database')
|
||||
await db.load()
|
||||
const prevHash = db.iterator().collect()[0].hash
|
||||
const hash = await db.add('hello2')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
@ -346,3 +362,4 @@ describe('orbit-db - Eventlog', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,27 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const mapSeries = require('p-map-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const last = arr => arr[arr.length - 1]
|
||||
|
||||
const dbPath = './orbitdb/tests/feed'
|
||||
const ipfsPath = './orbitdb/tests/feed/ipfs'
|
||||
|
||||
describe('orbit-db - Feed', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Feed Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb1, db, address
|
||||
let ipfsd, ipfs, orbitdb1, db, address
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
})
|
||||
|
||||
@ -29,14 +37,20 @@ describe('orbit-db - Feed', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('Feed', function() {
|
||||
it('creates and opens a database', async () => {
|
||||
db = await orbitdb1.feed('first database')
|
||||
db = await orbitdb1.feed('first database')
|
||||
db = await orbitdb1.feed('feed database')
|
||||
assert.notEqual(db, null)
|
||||
assert.equal(db.type, 'feed')
|
||||
assert.equal(db.dbname, 'feed database')
|
||||
})
|
||||
|
||||
it('returns 0 items when it\'s a fresh database', async () => {
|
||||
db = await orbitdb1.feed('feed database')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.equal(items.length, 0)
|
||||
})
|
||||
@ -388,3 +402,4 @@ describe('orbit-db - Feed', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -3,22 +3,30 @@
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/kvstore'
|
||||
const ipfsPath = './orbitdb/tests/kvstore/ipfs'
|
||||
|
||||
describe('orbit-db - Key-Value Store', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Key-Value Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs, orbitdb1, db
|
||||
let ipfsd, ipfs, orbitdb1, db
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
})
|
||||
|
||||
@ -26,8 +34,8 @@ describe('orbit-db - Key-Value Store', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -40,7 +48,9 @@ describe('orbit-db - Key-Value Store', function() {
|
||||
|
||||
it('creates and opens a database', async () => {
|
||||
db = await orbitdb1.keyvalue('first kv database')
|
||||
db = await orbitdb1.keyvalue('first kv database')
|
||||
assert.notEqual(db, null)
|
||||
assert.equal(db.type, 'keyvalue')
|
||||
assert.equal(db.dbname, 'first kv database')
|
||||
})
|
||||
|
||||
it('put', async () => {
|
||||
@ -117,3 +127,4 @@ describe('orbit-db - Key-Value Store', function() {
|
||||
assert.deepEqual(v1, val)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -6,6 +6,9 @@ const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const stopIpfs = require('./utils/stop-ipfs')
|
||||
const testAPIs = require('./utils/test-apis')
|
||||
const connectPeers = require('./utils/connect-peers')
|
||||
const waitForPeers = require('./utils/wait-for-peers')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/multiple-databases/1'
|
||||
@ -49,10 +52,12 @@ const databaseInterfaces = [
|
||||
},
|
||||
]
|
||||
|
||||
describe('orbit-db - Multiple Databases', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Multiple Databases (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2, db3, db4
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2, db1, db2, db3, db4
|
||||
|
||||
let localDatabases = []
|
||||
let remoteDatabases = []
|
||||
@ -65,11 +70,12 @@ describe('orbit-db - Multiple Databases', function() {
|
||||
rmrf.sync(config.daemon2.repo)
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfs1 = await startIpfs(config.daemon1)
|
||||
ipfs2 = await startIpfs(config.daemon2)
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
// Connect the peers manually to speed up test times
|
||||
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
orbitdb1 = new OrbitDB(ipfs1, dbPath1)
|
||||
orbitdb2 = new OrbitDB(ipfs2, dbPath2)
|
||||
})
|
||||
@ -81,11 +87,11 @@ describe('orbit-db - Multiple Databases', function() {
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfs1)
|
||||
await ipfs1.stop()
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
|
||||
if (ipfs2)
|
||||
await ipfs2.stop()
|
||||
if (ipfsd2)
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -185,3 +191,4 @@ describe('orbit-db - Multiple Databases', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -4,24 +4,32 @@ const assert = require('assert')
|
||||
const mapSeries = require('p-map-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/persistency'
|
||||
const ipfsPath = './orbitdb/tests/persistency/ipfs'
|
||||
|
||||
describe('orbit-db - Persistency', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Persistency (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const entryCount = 100
|
||||
|
||||
let ipfs, orbitdb1, db, address
|
||||
let ipfsd, ipfs, orbitdb1, db, address
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
})
|
||||
|
||||
@ -29,8 +37,8 @@ describe('orbit-db - Persistency', function() {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('load', function() {
|
||||
@ -259,3 +267,4 @@ describe('orbit-db - Persistency', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -4,19 +4,28 @@ const assert = require('assert')
|
||||
const mapSeries = require('p-each-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const waitForPeers = require('./utils/wait-for-peers')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
connectPeers,
|
||||
waitForPeers,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/replicate-and-load/1'
|
||||
const dbPath2 = './orbitdb/tests/replicate-and-load/2'
|
||||
const ipfsPath1 = './orbitdb/tests/replicate-and-load/1/ipfs'
|
||||
const ipfsPath2 = './orbitdb/tests/replicate-and-load/2/ipfs'
|
||||
|
||||
describe('orbit-db - Replicate and Load', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Replicate and Load (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2, db1, db2
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath1
|
||||
@ -25,13 +34,14 @@ describe('orbit-db - Replicate and Load', function() {
|
||||
rmrf.sync(config.daemon2.repo)
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfs1 = await startIpfs(config.daemon1)
|
||||
ipfs2 = await startIpfs(config.daemon2)
|
||||
// Connect the peers manually to speed up test times
|
||||
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
orbitdb1 = new OrbitDB(ipfs1, dbPath1)
|
||||
orbitdb2 = new OrbitDB(ipfs2, dbPath2)
|
||||
// Connect the peers manually to speed up test times
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
@ -41,11 +51,11 @@ describe('orbit-db - Replicate and Load', function() {
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfs1)
|
||||
await ipfs1.stop()
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
|
||||
if (ipfs2)
|
||||
await ipfs2.stop()
|
||||
if (ipfsd2)
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
describe('two peers', function() {
|
||||
@ -153,3 +163,4 @@ describe('orbit-db - Replicate and Load', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -4,19 +4,28 @@ const assert = require('assert')
|
||||
const mapSeries = require('p-each-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const waitForPeers = require('./utils/wait-for-peers')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
connectPeers,
|
||||
waitForPeers,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/replicate-automatically/1'
|
||||
const dbPath2 = './orbitdb/tests/replicate-automatically/2'
|
||||
const ipfsPath1 = './orbitdb/tests/replicate-automatically/1/ipfs'
|
||||
const ipfsPath2 = './orbitdb/tests/replicate-automatically/2/ipfs'
|
||||
|
||||
describe('orbit-db - Automatic Replication', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Automatic Replication (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2, db3, db4
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2, db1, db2, db3, db4
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath1
|
||||
@ -25,13 +34,14 @@ describe('orbit-db - Automatic Replication', function() {
|
||||
rmrf.sync(config.daemon2.repo)
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfs1 = await startIpfs(config.daemon1)
|
||||
ipfs2 = await startIpfs(config.daemon2)
|
||||
// Connect the peers manually to speed up test times
|
||||
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
orbitdb1 = new OrbitDB(ipfs1, dbPath1)
|
||||
orbitdb2 = new OrbitDB(ipfs2, dbPath2)
|
||||
// Connect the peers manually to speed up test times
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
@ -41,11 +51,11 @@ describe('orbit-db - Automatic Replication', function() {
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfs1)
|
||||
await ipfs1.stop()
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
|
||||
if (ipfs2)
|
||||
await ipfs2.stop()
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -132,7 +142,6 @@ describe('orbit-db - Automatic Replication', function() {
|
||||
db2.events.on('replicate.progress', (address, hash, entry) => {
|
||||
try {
|
||||
// Check that the head we received from the first peer is the latest
|
||||
// console.log(JSON.stringify(entry))
|
||||
assert.equal(entry.payload.op, 'ADD')
|
||||
assert.equal(entry.payload.key, null)
|
||||
assert.notEqual(entry.payload.value.indexOf('hello'), -1)
|
||||
@ -158,3 +167,4 @@ describe('orbit-db - Automatic Replication', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -4,37 +4,46 @@ const assert = require('assert')
|
||||
const mapSeries = require('p-each-series')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
const waitForPeers = require('./utils/wait-for-peers')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
connectPeers,
|
||||
waitForPeers,
|
||||
MemStore,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/replication/1'
|
||||
const dbPath2 = './orbitdb/tests/replication/2'
|
||||
const ipfsPath1 = './orbitdb/tests/replication/ipfs/1'
|
||||
const ipfsPath2 = './orbitdb/tests/replication/ipfs/2'
|
||||
const ipfsPath1 = './orbitdb/tests/replication/1/ipfs'
|
||||
const ipfsPath2 = './orbitdb/tests/replication/2/ipfs'
|
||||
|
||||
const MemStore = require('./utils/mem-store')
|
||||
|
||||
describe('orbit-db - Replication', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Replication (${API})`, function() {
|
||||
this.timeout(config.timeout * 2)
|
||||
|
||||
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2, db1, db2
|
||||
let id1, id2
|
||||
|
||||
describe('two peers', function() {
|
||||
let timer
|
||||
let options
|
||||
|
||||
beforeEach(async () => {
|
||||
clearInterval(timer)
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath1
|
||||
config.daemon2.repo = ipfsPath2
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(config.daemon2.repo)
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfs1 = await startIpfs(config.daemon1)
|
||||
ipfs2 = await startIpfs(config.daemon2)
|
||||
ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
ipfs2 = ipfsd2.api
|
||||
// Use memory store for quicker tests
|
||||
const memstore = new MemStore()
|
||||
ipfs1.object.put = memstore.put.bind(memstore)
|
||||
@ -42,8 +51,20 @@ describe('orbit-db - Replication', function() {
|
||||
ipfs2.object.put = memstore.put.bind(memstore)
|
||||
ipfs2.object.get = memstore.get.bind(memstore)
|
||||
// Connect the peers manually to speed up test times
|
||||
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (ipfsd1)
|
||||
await stopIpfs(ipfsd1)
|
||||
|
||||
if (ipfsd2)
|
||||
await stopIpfs(ipfsd2)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
clearInterval(timer)
|
||||
|
||||
orbitdb1 = new OrbitDB(ipfs1, dbPath1)
|
||||
orbitdb2 = new OrbitDB(ipfs2, dbPath2)
|
||||
|
||||
@ -57,15 +78,6 @@ describe('orbit-db - Replication', function() {
|
||||
|
||||
options = Object.assign({}, options, { path: dbPath1 })
|
||||
db1 = await orbitdb1.eventlog('replication-tests', options)
|
||||
// Set 'sync' flag on. It'll prevent creating a new local database and rather
|
||||
// fetch the database from the network
|
||||
// options = Object.assign({}, options, { path: dbPath2, sync: true })
|
||||
// db2 = await orbitdb2.eventlog(db1.address.toString(), options)
|
||||
|
||||
// assert.equal(db1.address.toString(), db2.address.toString())
|
||||
|
||||
// await waitForPeers(ipfs1, [orbitdb2.id], db1.address.toString())
|
||||
// await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@ -83,21 +95,11 @@ describe('orbit-db - Replication', function() {
|
||||
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(async () => {
|
||||
if (ipfs1)
|
||||
await ipfs1.stop()
|
||||
|
||||
if (ipfs2)
|
||||
await ipfs2.stop()
|
||||
|
||||
resolve()
|
||||
}, 2000)
|
||||
})
|
||||
})
|
||||
|
||||
it('replicates database of 1 entry', async () => {
|
||||
// Set 'sync' flag on. It'll prevent creating a new local database and rather
|
||||
// fetch the database from the network
|
||||
options = Object.assign({}, options, { path: dbPath2, sync: true })
|
||||
db2 = await orbitdb2.eventlog(db1.address.toString(), options)
|
||||
await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
|
||||
@ -124,9 +126,13 @@ describe('orbit-db - Replication', function() {
|
||||
for (let i = 0; i < entryCount; i ++)
|
||||
entryArr.push(i)
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
await mapSeries(entryArr, (i) => db1.add('hello' + i))
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
timer = setInterval(() => {
|
||||
const items = db2.iterator({ limit: -1 }).collect()
|
||||
if (items.length === entryCount) {
|
||||
@ -240,10 +246,6 @@ describe('orbit-db - Replication', function() {
|
||||
let events = []
|
||||
let expectedEventCount = 512
|
||||
|
||||
// Close second instance
|
||||
await db2.close()
|
||||
await db2.drop()
|
||||
|
||||
// Trigger replication
|
||||
let adds = []
|
||||
for (let i = 0; i < expectedEventCount; i ++) {
|
||||
@ -328,23 +330,25 @@ describe('orbit-db - Replication', function() {
|
||||
})
|
||||
// Resolve with a little timeout to make sure we
|
||||
// don't receive more than one event
|
||||
setTimeout(() => {
|
||||
setTimeout( async () => {
|
||||
// console.log(eventCount['replicate.progress'], expectedEventCount)
|
||||
|
||||
if (eventCount['replicate.progress'] === expectedEventCount)
|
||||
if (eventCount['replicate.progress'] === expectedEventCount) {
|
||||
finished = true
|
||||
}
|
||||
}, 500)
|
||||
})
|
||||
|
||||
try {
|
||||
const st = new Date().getTime()
|
||||
timer = setInterval(async () => {
|
||||
if (finished) {
|
||||
clearInterval(timer)
|
||||
|
||||
// await db2.close()
|
||||
|
||||
const et = new Date().getTime()
|
||||
console.log("Duration:", et - st, "ms")
|
||||
|
||||
try {
|
||||
assert.equal(eventCount['replicate'], expectedEventCount)
|
||||
assert.equal(eventCount['replicate.progress'], expectedEventCount)
|
||||
|
||||
@ -365,11 +369,11 @@ describe('orbit-db - Replication', function() {
|
||||
assert.equal(replicatedEvents[replicatedEvents.length - 1].replicationInfo.progress, expectedEventCount)
|
||||
|
||||
resolve()
|
||||
}
|
||||
}, 100)
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
}
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
|
||||
@ -402,6 +406,11 @@ describe('orbit-db - Replication', function() {
|
||||
orbitdb2.key.getPublic('hex')
|
||||
],
|
||||
}
|
||||
|
||||
// if (db2) {
|
||||
// await db2.drop()
|
||||
// }
|
||||
|
||||
db2 = await orbitdb2.eventlog(db1.address.toString(), options)
|
||||
await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
|
||||
|
||||
@ -474,6 +483,7 @@ describe('orbit-db - Replication', function() {
|
||||
const et = new Date().getTime()
|
||||
console.log("Duration:", et - st, "ms")
|
||||
|
||||
// console.log(eventCount['replicate'])
|
||||
assert.equal(eventCount['replicate'], expectedEventCount)
|
||||
assert.equal(eventCount['replicate.progress'], expectedEventCount)
|
||||
assert.equal(eventCount['replicated'], expectedEventCount)
|
||||
@ -515,3 +525,4 @@ describe('orbit-db - Replication', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
10
test/utils/connect-peers.js
Normal file
10
test/utils/connect-peers.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const connectIpfsNodes = async (ipfs1, ipfs2) => {
|
||||
const id1 = await ipfs1.id()
|
||||
const id2 = await ipfs2.id()
|
||||
await ipfs1.swarm.connect(id2.addresses[0])
|
||||
await ipfs2.swarm.connect(id1.addresses[0])
|
||||
}
|
||||
|
||||
module.exports = connectIpfsNodes
|
8
test/utils/index.js
Normal file
8
test/utils/index.js
Normal file
@ -0,0 +1,8 @@
|
||||
exports.config = require('./config.js')
|
||||
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.MemStore = require('./mem-store')
|
||||
exports.CustomTestKeystore = require('./custom-test-keystore')
|
@ -1,17 +1,42 @@
|
||||
'use strict'
|
||||
|
||||
const IPFS = require('ipfs')
|
||||
const IPFSFactory = require('ipfsd-ctl')
|
||||
const testAPIs = require('./test-apis')
|
||||
|
||||
/**
|
||||
* Start an IPFS instance
|
||||
* @param {Object} config [IPFS configuration to use]
|
||||
* @return {[Promise<IPFS>]} [IPFS instance]
|
||||
*/
|
||||
const startIpfs = (config = {}) => {
|
||||
const startIpfs = (type, config = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ipfs = new IPFS(config)
|
||||
ipfs.on('error', reject)
|
||||
ipfs.on('ready', () => resolve(ipfs))
|
||||
if (!testAPIs[type]) {
|
||||
reject(new Error(`Wanted API type ${JSON.stringify(type)} is unknown. Available types: ${Object.keys(testAPIs).join(', ')}`))
|
||||
}
|
||||
|
||||
// If we're starting a process, pass command line arguments to it
|
||||
if (!config.args) {
|
||||
config.args = ['--enable-pubsub-experiment']
|
||||
}
|
||||
|
||||
// Spawn an IPFS daemon (type defined in)
|
||||
IPFSFactory
|
||||
.create(testAPIs[type])
|
||||
.spawn(config, async (err, ipfsd) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
|
||||
// Monkey patch _peerInfo to the ipfs api/instance
|
||||
// to make js-ipfs-api compatible with js-ipfs
|
||||
// TODO: Get IPFS id via coherent API call (without it being asynchronous)
|
||||
if (!ipfsd.api._peerInfo) {
|
||||
let { id } = await ipfsd.api.id()
|
||||
ipfsd.api._peerInfo = { id: { _idB58String: id } }
|
||||
}
|
||||
|
||||
resolve(ipfsd)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
17
test/utils/stop-ipfs.js
Normal file
17
test/utils/stop-ipfs.js
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Stop an IPFS or ipfsd-ctl instance
|
||||
* @param {Object} config [IPFS ipfsd-ctl to stop]
|
||||
* @return {None}
|
||||
*/
|
||||
const stopIpfs = (ipfs) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
ipfs.stop((err) => {
|
||||
if (err) { reject(err) }
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = stopIpfs
|
26
test/utils/test-apis.js
Normal file
26
test/utils/test-apis.js
Normal file
@ -0,0 +1,26 @@
|
||||
const IPFS = require('ipfs')
|
||||
|
||||
// Available daemon types are defined in:
|
||||
// https://github.com/ipfs/js-ipfsd-ctl#ipfsfactory---const-f--ipfsfactorycreateoptions
|
||||
let jsIpfs = {
|
||||
'js-ipfs': {
|
||||
type: 'proc',
|
||||
exec: IPFS,
|
||||
}
|
||||
}
|
||||
|
||||
const goIpfs = {
|
||||
'go-ipfs': {
|
||||
type: 'go',
|
||||
}
|
||||
}
|
||||
|
||||
// IPFS daemons to run the tests with
|
||||
let testAPIs = Object.assign({}, jsIpfs)
|
||||
|
||||
// By default, we only run tests against js-ipfs.
|
||||
// Setting env variable 'TEST=all' will make tests run with go-ipfs also.
|
||||
if (process.env.TEST === 'all')
|
||||
testAPIs = Object.assign({}, testAPIs, goIpfs)
|
||||
|
||||
module.exports = testAPIs
|
@ -3,11 +3,17 @@
|
||||
const assert = require('assert')
|
||||
const rmrf = require('rimraf')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const config = require('./utils/config')
|
||||
const startIpfs = require('./utils/start-ipfs')
|
||||
|
||||
const dbPath = './orbitdb/tests/sync'
|
||||
const ipfsPath = './orbitdb/tests/feed/ipfs'
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath = './orbitdb/tests/write-permissions'
|
||||
const ipfsPath = './orbitdb/tests/write-permissions/ipfs'
|
||||
|
||||
const databases = [
|
||||
{
|
||||
@ -52,16 +58,18 @@ const databases = [
|
||||
},
|
||||
]
|
||||
|
||||
describe('orbit-db - Write Permissions', function() {
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Write Permissions (${API})`, function() {
|
||||
this.timeout(20000)
|
||||
|
||||
let ipfs, orbitdb1, orbitdb2
|
||||
let ipfsd, ipfs, orbitdb1, orbitdb2
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath)
|
||||
ipfs = await startIpfs(config.daemon1)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
|
||||
orbitdb2 = new OrbitDB(ipfs, dbPath + '/2')
|
||||
})
|
||||
@ -73,8 +81,8 @@ describe('orbit-db - Write Permissions', function() {
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfs)
|
||||
await ipfs.stop()
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('allows multiple peers to write to the databases', function() {
|
||||
@ -239,3 +247,4 @@ describe('orbit-db - Write Permissions', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user