Merge pull request #335 from orbitdb/feat/tests-with-ipfsd-ctl

Use ipfsd-ctl to create test IPFS instances
This commit is contained in:
Haad 2018-03-27 14:37:11 +02:00 committed by GitHub
commit 99c69b6b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 2910 additions and 2424 deletions

232
package-lock.json generated
View File

@ -295,6 +295,12 @@
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==", "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==",
"dev": true "dev": true
}, },
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
"dev": true
},
"atob": { "atob": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.0.3.tgz", "resolved": "https://registry.npmjs.org/atob/-/atob-2.0.3.tgz",
@ -1823,6 +1829,32 @@
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true "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": { "commander": {
"version": "2.15.1", "version": "2.15.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
@ -1956,6 +1988,12 @@
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=", "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=",
"dev": true "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": { "copy-concurrently": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
@ -2257,6 +2295,12 @@
"isobject": "3.0.1" "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": { "delegates": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
@ -2393,6 +2437,12 @@
"create-hmac": "1.1.6" "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": { "duplexer3": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", "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", "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-1.1.0.tgz",
"integrity": "sha512-kkjwkMqj0h4w/sb32ERCDxCQkREMCAgS39DscDnSwDsbxnwwM1BTZySdC3Bn1lhY7vL08n9GoO/fVTynjDgRyQ==" "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": { "extend-shallow": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz",
@ -3164,6 +3220,23 @@
"integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=",
"dev": true "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": { "fragment-cache": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz",
@ -5382,6 +5455,12 @@
"integrity": "sha1-EPIJmg18BaQPK+r1wdOc8vfavzY=", "integrity": "sha1-EPIJmg18BaQPK+r1wdOc8vfavzY=",
"dev": true "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": { "he": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
@ -5548,6 +5627,12 @@
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=", "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=",
"dev": true "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": { "inert": {
"version": "4.2.1", "version": "4.2.1",
"resolved": "https://registry.npmjs.org/inert/-/inert-4.2.1.tgz", "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": { "ipld": {
"version": "0.15.0", "version": "0.15.0",
"resolved": "https://registry.npmjs.org/ipld/-/ipld-0.15.0.tgz", "resolved": "https://registry.npmjs.org/ipld/-/ipld-0.15.0.tgz",
@ -6441,6 +6557,12 @@
"integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=", "integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=",
"dev": true "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": { "is-stream": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
@ -7244,6 +7366,12 @@
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==", "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
"dev": true "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": { "lodash.clonedeep": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
@ -7255,6 +7383,18 @@
"integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=",
"dev": true "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": { "lodash.filter": {
"version": "4.6.0", "version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.filter/-/lodash.filter-4.6.0.tgz", "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": { "micromatch": {
"version": "3.1.10", "version": "3.1.10",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz",
@ -7646,6 +7792,12 @@
"brorand": "1.1.0" "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": { "mime-db": {
"version": "1.33.0", "version": "1.33.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
@ -9489,11 +9641,35 @@
"aproba": "1.2.0" "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": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" "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": { "safe-regex": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "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": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "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", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" "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": { "subtext": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/subtext/-/subtext-5.0.0.tgz", "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": { "supports-color": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
@ -10587,6 +10813,12 @@
"utf8-byte-length": "1.0.4" "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": { "tty-browserify": {
"version": "0.0.0", "version": "0.0.0",
"resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz",

View File

@ -32,8 +32,9 @@
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1", "babel-preset-es2015": "^6.24.1",
"datastore-level": "~0.7.0", "datastore-level": "~0.7.0",
"ipfs": "~0.28.0", "ipfs": "~0.28.2",
"ipfs-repo": "~0.18.0", "ipfs-repo": "~0.18.7",
"ipfsd-ctl": "~0.30.3",
"mocha": "^4.0.1", "mocha": "^4.0.1",
"p-each-series": "^1.0.0", "p-each-series": "^1.0.0",
"p-map-series": "^1.0.0", "p-map-series": "^1.0.0",

View File

@ -374,12 +374,8 @@ class OrbitDB {
databaseTypes[type] = store databaseTypes[type] = store
} }
static create () { static getDatabaseTypes () {
return new Error('Not implemented yet!') return databaseTypes
}
static open () {
return new Error('Not implemented yet!')
} }
} }

View File

@ -1,35 +1,44 @@
'use strict' 'use strict'
const path = require('path')
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf')
const mapSeries = require('p-each-series') const mapSeries = require('p-each-series')
const path = require('path')
const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs') // Include test utilities
const waitForPeers = require('./utils/wait-for-peers') const {
config,
startIpfs,
stopIpfs,
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
const dbPath1 = './orbitdb/tests/counters/peer1' const dbPath1 = './orbitdb/tests/counters/peer1'
const dbPath2 = './orbitdb/tests/counters/peer2' const dbPath2 = './orbitdb/tests/counters/peer2'
const ipfsPath1 = './orbitdb/tests/counters/peer1/ipfs' const ipfsPath1 = './orbitdb/tests/counters/peer1/ipfs'
const ipfsPath2 = './orbitdb/tests/counters/peer2/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) this.timeout(config.timeout)
let orbitdb1, orbitdb2 let orbitdb1, orbitdb2
let ipfs1, ipfs2 let ipfsd1, ipfsd2, ipfs1, ipfs2
before(async () => { before(async () => {
rmrf.sync(dbPath1) rmrf.sync(dbPath1)
rmrf.sync(dbPath2) rmrf.sync(dbPath2)
config.daemon1.repo = ipfsPath1 config.daemon1.repo = ipfsPath1
config.daemon2.repo = ipfsPath2 config.daemon2.repo = ipfsPath2
ipfs1 = await startIpfs(config.daemon1) ipfsd1 = await startIpfs(API, config.daemon1)
ipfs2 = await startIpfs(config.daemon2) ipfsd2 = await startIpfs(API, config.daemon2)
ipfs1 = ipfsd1.api
ipfs2 = ipfsd2.api
// Connect the peers manually to speed up test times // Connect the peers manually to speed up test times
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) await connectPeers(ipfs1, ipfs2)
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
}) })
after(async () => { after(async () => {
@ -39,11 +48,11 @@ describe('CounterStore', function() {
if (orbitdb2) if (orbitdb2)
await orbitdb2.stop() await orbitdb2.stop()
if (ipfs1) if (ipfsd1)
await ipfs1.stop() await stopIpfs(ipfsd1)
if (ipfs2) if (ipfsd2)
await ipfs2.stop() await stopIpfs(ipfsd2)
}) })
beforeEach(() => { beforeEach(() => {
@ -62,6 +71,18 @@ describe('CounterStore', function() {
describe('counters', function() { describe('counters', function() {
let address 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 () => { it('increases a counter value', async () => {
const counter = await orbitdb1.counter('counter test', { path: dbPath1 }) const counter = await orbitdb1.counter('counter test', { path: dbPath1 })
address = counter.address.toString() address = counter.address.toString()
@ -109,7 +130,8 @@ describe('CounterStore', function() {
assert.equal(counter1.value, 30) assert.equal(counter1.value, 30)
assert.equal(counter2.value, 30) assert.equal(counter2.value, 30)
resolve() resolve()
}, 5000) }, 1000)
})
}) })
}) })
}) })

View File

@ -1,31 +1,39 @@
'use strict' 'use strict'
const assert = require('assert') const assert = require('assert')
const mapSeries = require('p-map-series')
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const mapSeries = require('p-map-series')
const levelup = require('levelup') const levelup = require('levelup')
const leveldown = require('leveldown') const leveldown = require('leveldown')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const OrbitDBAddress = require('../src/orbit-db-address') 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 dbPath = './orbitdb/tests/create-open'
const ipfsPath = './orbitdb/tests/create-open/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb, db, address let ipfsd, ipfs, orbitdb, db, address
let localDataPath let localDataPath
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb = new OrbitDB(ipfs, dbPath) orbitdb = new OrbitDB(ipfs, dbPath)
}) })
@ -33,8 +41,8 @@ describe('orbit-db - Create & Open', function() {
if(orbitdb) if(orbitdb)
await orbitdb.stop() await orbitdb.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('Create', function() { describe('Create', function() {
@ -62,8 +70,8 @@ describe('orbit-db - Create & Open', function() {
it('throws an error if database already exists', async () => { it('throws an error if database already exists', async () => {
let err let err
try { try {
db = await orbitdb.create('first', 'feed') db = await orbitdb.create('first', 'feed', { replicate: false })
db = await orbitdb.create('first', 'feed') db = await orbitdb.create('first', 'feed', { replicate: false })
} catch (e) { } catch (e) {
err = e.toString() err = e.toString()
} }
@ -74,7 +82,7 @@ describe('orbit-db - Create & Open', function() {
it('throws an error if database type doesn\'t match', async () => { it('throws an error if database type doesn\'t match', async () => {
let err, log, kv let err, log, kv
try { try {
log = await orbitdb.kvstore('keyvalue') log = await orbitdb.kvstore('keyvalue', { replicate: false })
kv = await orbitdb.eventlog(log.address.toString()) kv = await orbitdb.eventlog(log.address.toString())
} catch (e) { } catch (e) {
err = e.toString() err = e.toString()
@ -85,7 +93,7 @@ describe('orbit-db - Create & Open', function() {
describe('Success', function() { describe('Success', function() {
before(async () => { 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) localDataPath = path.join(dbPath, db.address.root, db.address.path)
await db.close() await db.close()
}) })
@ -255,4 +263,6 @@ describe('orbit-db - Create & Open', function() {
assert.equal(res[1].payload.value, 'hello2') assert.equal(res[1].payload.value, 'hello2')
}) })
}) })
})
}) })

View File

@ -1,16 +1,21 @@
'use strict' 'use strict'
const assert = require('assert') const assert = require('assert')
const config = require('./utils/config') const rmrf = require('rimraf')
const DocumentStore = require('orbit-db-docstore') const DocumentStore = require('orbit-db-docstore')
const OrbitDB = require('../src/OrbitDB') 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 dbPath = './orbitdb/tests/create-open'
const ipfsPath = './orbitdb/tests/create-open/ipfs' const ipfsPath = './orbitdb/tests/create-open/ipfs'
class CustomStore extends DocumentStore { class CustomStore extends DocumentStore {
constructor (ipfs, id, dbname, options) { constructor (ipfs, id, dbname, options) {
super(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) this.timeout(config.timeout)
let ipfs, orbitdb let ipfsd, ipfs, orbitdb
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb = new OrbitDB(ipfs, dbPath) orbitdb = new OrbitDB(ipfs, dbPath)
}) })
after(async () => { after(async () => {
if (orbitdb) await orbitdb.stop() 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 () { describe('addDatabaseType', function () {
@ -56,4 +66,5 @@ describe('orbit-db - Create custom type', function () {
} }
}) })
}) })
})
}) })

View File

@ -3,9 +3,14 @@
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config') // Include test utilities
const startIpfs = require('./utils/start-ipfs') const {
const customTestKeystore = require('./utils/custom-test-keystore') config,
startIpfs,
stopIpfs,
testAPIs,
CustomTestKeystore,
} = require('./utils')
const dbPath = './orbitdb/tests/customKeystore' const dbPath = './orbitdb/tests/customKeystore'
const ipfsPath = './orbitdb/tests/customKeystore/ipfs' 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) this.timeout(20000)
let ipfs, orbitdb1 let ipfsd, ipfs, orbitdb1
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1', { orbitdb1 = new OrbitDB(ipfs, dbPath + '/1', {
keystore: customTestKeystore keystore: CustomTestKeystore
}) })
}) })
@ -72,8 +79,8 @@ describe('orbit-db - Using custom keystore', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('allows orbit to use a custom keystore with different store types', function() { describe('allows orbit to use a custom keystore with different store types', function() {
@ -108,4 +115,5 @@ describe('orbit-db - Using custom keystore', function() {
}) })
}) })
}) })
})
}) })

View File

@ -3,21 +3,29 @@
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 dbPath = './orbitdb/tests/docstore'
const ipfsPath = './orbitdb/tests/docstore/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb1, db let ipfsd, ipfs, orbitdb1, db
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) 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') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
}) })
@ -25,13 +33,15 @@ describe('orbit-db - Document Store', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.docstore('first doc database') 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() { describe('Default index \'_id\'', function() {
@ -159,4 +169,5 @@ describe('orbit-db - Document Store', function() {
assert.deepEqual(value2, [doc2]) assert.deepEqual(value2, [doc2])
}) })
}) })
})
}) })

View File

@ -5,23 +5,31 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 dbPath = './orbitdb/tests/drop'
const ipfsPath = './orbitdb/tests/drop/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb, db, address let ipfsd, ipfs, orbitdb, db, address
let localDataPath let localDataPath
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb = new OrbitDB(ipfs, dbPath) orbitdb = new OrbitDB(ipfs, dbPath)
}) })
@ -29,8 +37,8 @@ describe('orbit-db - Drop Database', function() {
if(orbitdb) if(orbitdb)
await orbitdb.stop() await orbitdb.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
rmrf.sync(dbPath) rmrf.sync(dbPath)
}) })
@ -47,4 +55,5 @@ describe('orbit-db - Drop Database', function() {
assert.equal(fs.existsSync(localDataPath), false) assert.equal(fs.existsSync(localDataPath), false)
}) })
}) })
})
}) })

View File

@ -1,27 +1,35 @@
'use strict' 'use strict'
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf')
const mapSeries = require('p-map-series') const mapSeries = require('p-map-series')
const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 last = arr => arr[arr.length - 1]
const dbPath = './orbitdb/tests/eventlog' const dbPath = './orbitdb/tests/eventlog'
const ipfsPath = './orbitdb/tests/eventlog/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb1, db let ipfsd, ipfs, orbitdb1, db
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
}) })
@ -29,14 +37,20 @@ describe('orbit-db - Eventlog', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('Eventlog', function () { describe('Eventlog', function () {
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.eventlog('first database') db = await orbitdb1.eventlog('log database')
db = await orbitdb1.eventlog('first 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() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 0) assert.equal(items.length, 0)
}) })
@ -51,6 +65,8 @@ describe('orbit-db - Eventlog', function() {
}) })
it('returns the added entry\'s hash, 2 entries', async () => { 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 prevHash = db.iterator().collect()[0].hash
const hash = await db.add('hello2') const hash = await db.add('hello2')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
@ -345,4 +361,5 @@ describe('orbit-db - Eventlog', function() {
}) })
}) })
}) })
})
}) })

View File

@ -1,27 +1,35 @@
'use strict' 'use strict'
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf')
const mapSeries = require('p-map-series') const mapSeries = require('p-map-series')
const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 last = arr => arr[arr.length - 1]
const dbPath = './orbitdb/tests/feed' const dbPath = './orbitdb/tests/feed'
const ipfsPath = './orbitdb/tests/feed/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb1, db, address let ipfsd, ipfs, orbitdb1, db, address
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
}) })
@ -29,14 +37,20 @@ describe('orbit-db - Feed', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('Feed', function() { describe('Feed', function() {
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.feed('first database') db = await orbitdb1.feed('feed database')
db = await orbitdb1.feed('first 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() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 0) assert.equal(items.length, 0)
}) })
@ -387,4 +401,5 @@ describe('orbit-db - Feed', function() {
}) })
}) })
}) })
})
}) })

View File

@ -3,22 +3,30 @@
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 dbPath = './orbitdb/tests/kvstore'
const ipfsPath = './orbitdb/tests/kvstore/ipfs' 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) this.timeout(config.timeout)
let ipfs, orbitdb1, db let ipfsd, ipfs, orbitdb1, db
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
}) })
@ -26,8 +34,8 @@ describe('orbit-db - Key-Value Store', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
beforeEach(async () => { beforeEach(async () => {
@ -40,7 +48,9 @@ describe('orbit-db - Key-Value Store', function() {
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.keyvalue('first kv database') 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 () => { it('put', async () => {
@ -116,4 +126,5 @@ describe('orbit-db - Key-Value Store', function() {
const v1 = db.get('key1') const v1 = db.get('key1')
assert.deepEqual(v1, val) assert.deepEqual(v1, val)
}) })
})
}) })

View File

@ -6,6 +6,9 @@ const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config') const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs') 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 waitForPeers = require('./utils/wait-for-peers')
const dbPath1 = './orbitdb/tests/multiple-databases/1' 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) 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 localDatabases = []
let remoteDatabases = [] let remoteDatabases = []
@ -65,11 +70,12 @@ describe('orbit-db - Multiple Databases', function() {
rmrf.sync(config.daemon2.repo) rmrf.sync(config.daemon2.repo)
rmrf.sync(dbPath1) rmrf.sync(dbPath1)
rmrf.sync(dbPath2) rmrf.sync(dbPath2)
ipfs1 = await startIpfs(config.daemon1) ipfsd1 = await startIpfs(API, config.daemon1)
ipfs2 = await startIpfs(config.daemon2) ipfsd2 = await startIpfs(API, config.daemon2)
ipfs1 = ipfsd1.api
ipfs2 = ipfsd2.api
// Connect the peers manually to speed up test times // Connect the peers manually to speed up test times
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) await connectPeers(ipfs1, ipfs2)
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
orbitdb1 = new OrbitDB(ipfs1, dbPath1) orbitdb1 = new OrbitDB(ipfs1, dbPath1)
orbitdb2 = new OrbitDB(ipfs2, dbPath2) orbitdb2 = new OrbitDB(ipfs2, dbPath2)
}) })
@ -81,11 +87,11 @@ describe('orbit-db - Multiple Databases', function() {
if(orbitdb2) if(orbitdb2)
await orbitdb2.stop() await orbitdb2.stop()
if (ipfs1) if (ipfsd1)
await ipfs1.stop() await stopIpfs(ipfsd1)
if (ipfs2) if (ipfsd2)
await ipfs2.stop() await stopIpfs(ipfsd2)
}) })
beforeEach(async () => { beforeEach(async () => {
@ -184,4 +190,5 @@ describe('orbit-db - Multiple Databases', function() {
}, 500) }, 500)
}) })
}) })
})
}) })

View File

@ -4,24 +4,32 @@ const assert = require('assert')
const mapSeries = require('p-map-series') const mapSeries = require('p-map-series')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') 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 dbPath = './orbitdb/tests/persistency'
const ipfsPath = './orbitdb/tests/persistency/ipfs' 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) this.timeout(config.timeout)
const entryCount = 100 const entryCount = 100
let ipfs, orbitdb1, db, address let ipfsd, ipfs, orbitdb1, db, address
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
}) })
@ -29,8 +37,8 @@ describe('orbit-db - Persistency', function() {
if(orbitdb1) if(orbitdb1)
await orbitdb1.stop() await orbitdb1.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('load', function() { describe('load', function() {
@ -258,4 +266,5 @@ describe('orbit-db - Persistency', function() {
}) })
}) })
}) })
})
}) })

View File

@ -4,19 +4,28 @@ const assert = require('assert')
const mapSeries = require('p-each-series') const mapSeries = require('p-each-series')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs') // Include test utilities
const waitForPeers = require('./utils/wait-for-peers') const {
config,
startIpfs,
stopIpfs,
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
const dbPath1 = './orbitdb/tests/replicate-and-load/1' const dbPath1 = './orbitdb/tests/replicate-and-load/1'
const dbPath2 = './orbitdb/tests/replicate-and-load/2' const dbPath2 = './orbitdb/tests/replicate-and-load/2'
const ipfsPath1 = './orbitdb/tests/replicate-and-load/1/ipfs' const ipfsPath1 = './orbitdb/tests/replicate-and-load/1/ipfs'
const ipfsPath2 = './orbitdb/tests/replicate-and-load/2/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) this.timeout(config.timeout)
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2 let ipfsd1, ipfsd2, ipfs1, ipfs2
let orbitdb1, orbitdb2, db1, db2
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath1 config.daemon1.repo = ipfsPath1
@ -25,13 +34,14 @@ describe('orbit-db - Replicate and Load', function() {
rmrf.sync(config.daemon2.repo) rmrf.sync(config.daemon2.repo)
rmrf.sync(dbPath1) rmrf.sync(dbPath1)
rmrf.sync(dbPath2) rmrf.sync(dbPath2)
ipfs1 = await startIpfs(config.daemon1) ipfsd1 = await startIpfs(API, config.daemon1)
ipfs2 = await startIpfs(config.daemon2) ipfsd2 = await startIpfs(API, config.daemon2)
// Connect the peers manually to speed up test times ipfs1 = ipfsd1.api
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) ipfs2 = ipfsd2.api
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
orbitdb1 = new OrbitDB(ipfs1, dbPath1) orbitdb1 = new OrbitDB(ipfs1, dbPath1)
orbitdb2 = new OrbitDB(ipfs2, dbPath2) orbitdb2 = new OrbitDB(ipfs2, dbPath2)
// Connect the peers manually to speed up test times
await connectPeers(ipfs1, ipfs2)
}) })
after(async () => { after(async () => {
@ -41,11 +51,11 @@ describe('orbit-db - Replicate and Load', function() {
if(orbitdb2) if(orbitdb2)
await orbitdb2.stop() await orbitdb2.stop()
if (ipfs1) if (ipfsd1)
await ipfs1.stop() await stopIpfs(ipfsd1)
if (ipfs2) if (ipfsd2)
await ipfs2.stop() await stopIpfs(ipfsd2)
}) })
describe('two peers', function() { describe('two peers', function() {
@ -152,4 +162,5 @@ describe('orbit-db - Replicate and Load', function() {
}) })
}) })
}) })
})
}) })

View File

@ -4,19 +4,28 @@ const assert = require('assert')
const mapSeries = require('p-each-series') const mapSeries = require('p-each-series')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs') // Include test utilities
const waitForPeers = require('./utils/wait-for-peers') const {
config,
startIpfs,
stopIpfs,
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
const dbPath1 = './orbitdb/tests/replicate-automatically/1' const dbPath1 = './orbitdb/tests/replicate-automatically/1'
const dbPath2 = './orbitdb/tests/replicate-automatically/2' const dbPath2 = './orbitdb/tests/replicate-automatically/2'
const ipfsPath1 = './orbitdb/tests/replicate-automatically/1/ipfs' const ipfsPath1 = './orbitdb/tests/replicate-automatically/1/ipfs'
const ipfsPath2 = './orbitdb/tests/replicate-automatically/2/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) 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 () => { before(async () => {
config.daemon1.repo = ipfsPath1 config.daemon1.repo = ipfsPath1
@ -25,13 +34,14 @@ describe('orbit-db - Automatic Replication', function() {
rmrf.sync(config.daemon2.repo) rmrf.sync(config.daemon2.repo)
rmrf.sync(dbPath1) rmrf.sync(dbPath1)
rmrf.sync(dbPath2) rmrf.sync(dbPath2)
ipfs1 = await startIpfs(config.daemon1) ipfsd1 = await startIpfs(API, config.daemon1)
ipfs2 = await startIpfs(config.daemon2) ipfsd2 = await startIpfs(API, config.daemon2)
// Connect the peers manually to speed up test times ipfs1 = ipfsd1.api
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) ipfs2 = ipfsd2.api
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
orbitdb1 = new OrbitDB(ipfs1, dbPath1) orbitdb1 = new OrbitDB(ipfs1, dbPath1)
orbitdb2 = new OrbitDB(ipfs2, dbPath2) orbitdb2 = new OrbitDB(ipfs2, dbPath2)
// Connect the peers manually to speed up test times
await connectPeers(ipfs1, ipfs2)
}) })
after(async () => { after(async () => {
@ -41,11 +51,11 @@ describe('orbit-db - Automatic Replication', function() {
if(orbitdb2) if(orbitdb2)
await orbitdb2.stop() await orbitdb2.stop()
if (ipfs1) if (ipfsd1)
await ipfs1.stop() await stopIpfs(ipfsd1)
if (ipfs2) if (ipfs2)
await ipfs2.stop() await stopIpfs(ipfsd2)
}) })
beforeEach(async () => { beforeEach(async () => {
@ -132,7 +142,6 @@ describe('orbit-db - Automatic Replication', function() {
db2.events.on('replicate.progress', (address, hash, entry) => { db2.events.on('replicate.progress', (address, hash, entry) => {
try { try {
// Check that the head we received from the first peer is the latest // 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.op, 'ADD')
assert.equal(entry.payload.key, null) assert.equal(entry.payload.key, null)
assert.notEqual(entry.payload.value.indexOf('hello'), -1) assert.notEqual(entry.payload.value.indexOf('hello'), -1)
@ -157,4 +166,5 @@ describe('orbit-db - Automatic Replication', function() {
}) })
}) })
}) })
})
}) })

View File

@ -4,37 +4,46 @@ const assert = require('assert')
const mapSeries = require('p-each-series') const mapSeries = require('p-each-series')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs') // Include test utilities
const waitForPeers = require('./utils/wait-for-peers') const {
config,
startIpfs,
stopIpfs,
testAPIs,
connectPeers,
waitForPeers,
MemStore,
} = require('./utils')
const dbPath1 = './orbitdb/tests/replication/1' const dbPath1 = './orbitdb/tests/replication/1'
const dbPath2 = './orbitdb/tests/replication/2' const dbPath2 = './orbitdb/tests/replication/2'
const ipfsPath1 = './orbitdb/tests/replication/ipfs/1' const ipfsPath1 = './orbitdb/tests/replication/1/ipfs'
const ipfsPath2 = './orbitdb/tests/replication/ipfs/2' const ipfsPath2 = './orbitdb/tests/replication/2/ipfs'
const MemStore = require('./utils/mem-store') Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Replication (${API})`, function() {
describe('orbit-db - Replication', function() {
this.timeout(config.timeout * 2) 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() { describe('two peers', function() {
let timer let timer
let options let options
beforeEach(async () => { before(async () => {
clearInterval(timer)
config.daemon1.repo = ipfsPath1 config.daemon1.repo = ipfsPath1
config.daemon2.repo = ipfsPath2 config.daemon2.repo = ipfsPath2
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(config.daemon2.repo) rmrf.sync(config.daemon2.repo)
rmrf.sync(dbPath1) rmrf.sync(dbPath1)
rmrf.sync(dbPath2) rmrf.sync(dbPath2)
ipfs1 = await startIpfs(config.daemon1) ipfsd1 = await startIpfs(API, config.daemon1)
ipfs2 = await startIpfs(config.daemon2) ipfsd2 = await startIpfs(API, config.daemon2)
ipfs1 = ipfsd1.api
ipfs2 = ipfsd2.api
// Use memory store for quicker tests // Use memory store for quicker tests
const memstore = new MemStore() const memstore = new MemStore()
ipfs1.object.put = memstore.put.bind(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.put = memstore.put.bind(memstore)
ipfs2.object.get = memstore.get.bind(memstore) ipfs2.object.get = memstore.get.bind(memstore)
// Connect the peers manually to speed up test times // Connect the peers manually to speed up test times
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) await connectPeers(ipfs1, ipfs2)
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString()) })
after(async () => {
if (ipfsd1)
await stopIpfs(ipfsd1)
if (ipfsd2)
await stopIpfs(ipfsd2)
})
beforeEach(async () => {
clearInterval(timer)
orbitdb1 = new OrbitDB(ipfs1, dbPath1) orbitdb1 = new OrbitDB(ipfs1, dbPath1)
orbitdb2 = new OrbitDB(ipfs2, dbPath2) orbitdb2 = new OrbitDB(ipfs2, dbPath2)
@ -57,15 +78,6 @@ describe('orbit-db - Replication', function() {
options = Object.assign({}, options, { path: dbPath1 }) options = Object.assign({}, options, { path: dbPath1 })
db1 = await orbitdb1.eventlog('replication-tests', options) 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 () => { afterEach(async () => {
@ -83,21 +95,11 @@ describe('orbit-db - Replication', function() {
if(orbitdb2) if(orbitdb2)
await orbitdb2.stop() 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 () => { 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 }) options = Object.assign({}, options, { path: dbPath2, sync: true })
db2 = await orbitdb2.eventlog(db1.address.toString(), options) db2 = await orbitdb2.eventlog(db1.address.toString(), options)
await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
@ -124,9 +126,13 @@ describe('orbit-db - Replication', function() {
for (let i = 0; i < entryCount; i ++) for (let i = 0; i < entryCount; i ++)
entryArr.push(i) entryArr.push(i)
return new Promise(async (resolve, reject) => {
try {
await mapSeries(entryArr, (i) => db1.add('hello' + i)) await mapSeries(entryArr, (i) => db1.add('hello' + i))
} catch (e) {
reject(e)
}
return new Promise(resolve => {
timer = setInterval(() => { timer = setInterval(() => {
const items = db2.iterator({ limit: -1 }).collect() const items = db2.iterator({ limit: -1 }).collect()
if (items.length === entryCount) { if (items.length === entryCount) {
@ -240,10 +246,6 @@ describe('orbit-db - Replication', function() {
let events = [] let events = []
let expectedEventCount = 512 let expectedEventCount = 512
// Close second instance
await db2.close()
await db2.drop()
// Trigger replication // Trigger replication
let adds = [] let adds = []
for (let i = 0; i < expectedEventCount; i ++) { 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 // Resolve with a little timeout to make sure we
// don't receive more than one event // don't receive more than one event
setTimeout(() => { setTimeout( async () => {
//console.log(eventCount['replicate.progress'], expectedEventCount) // console.log(eventCount['replicate.progress'], expectedEventCount)
if (eventCount['replicate.progress'] === expectedEventCount) {
if (eventCount['replicate.progress'] === expectedEventCount)
finished = true finished = true
}
}, 500) }, 500)
}) })
try {
const st = new Date().getTime() const st = new Date().getTime()
timer = setInterval(async () => { timer = setInterval(async () => {
if (finished) { if (finished) {
clearInterval(timer) clearInterval(timer)
// await db2.close()
const et = new Date().getTime() const et = new Date().getTime()
console.log("Duration:", et - st, "ms") console.log("Duration:", et - st, "ms")
try {
assert.equal(eventCount['replicate'], expectedEventCount) assert.equal(eventCount['replicate'], expectedEventCount)
assert.equal(eventCount['replicate.progress'], 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) assert.equal(replicatedEvents[replicatedEvents.length - 1].replicationInfo.progress, expectedEventCount)
resolve() resolve()
}
}, 100)
} catch (e) { } catch (e) {
reject(e) reject(e)
} }
}
}, 100)
}) })
}) })
@ -402,6 +406,11 @@ describe('orbit-db - Replication', function() {
orbitdb2.key.getPublic('hex') orbitdb2.key.getPublic('hex')
], ],
} }
// if (db2) {
// await db2.drop()
// }
db2 = await orbitdb2.eventlog(db1.address.toString(), options) db2 = await orbitdb2.eventlog(db1.address.toString(), options)
await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
@ -445,7 +454,7 @@ describe('orbit-db - Replication', function() {
total = db2._replicationInfo.max total = db2._replicationInfo.max
const values = db2.iterator({limit: -1}).collect() const values = db2.iterator({limit: -1}).collect()
// console.log(current, "/", total, "/", values.length) // console.log(current, "/", total, "/", values.length)
//console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d) // console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d)
assert.equal(current <= total, true) assert.equal(current <= total, true)
events.push({ events.push({
event: 'replicated', event: 'replicated',
@ -474,6 +483,7 @@ describe('orbit-db - Replication', function() {
const et = new Date().getTime() const et = new Date().getTime()
console.log("Duration:", et - st, "ms") console.log("Duration:", et - st, "ms")
// console.log(eventCount['replicate'])
assert.equal(eventCount['replicate'], expectedEventCount) assert.equal(eventCount['replicate'], expectedEventCount)
assert.equal(eventCount['replicate.progress'], expectedEventCount) assert.equal(eventCount['replicate.progress'], expectedEventCount)
assert.equal(eventCount['replicated'], expectedEventCount) assert.equal(eventCount['replicated'], expectedEventCount)
@ -514,4 +524,5 @@ describe('orbit-db - Replication', function() {
}) })
}) })
}) })
})
}) })

View 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
View 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')

View File

@ -1,17 +1,42 @@
'use strict' 'use strict'
const IPFS = require('ipfs') const IPFSFactory = require('ipfsd-ctl')
const testAPIs = require('./test-apis')
/** /**
* Start an IPFS instance * Start an IPFS instance
* @param {Object} config [IPFS configuration to use] * @param {Object} config [IPFS configuration to use]
* @return {[Promise<IPFS>]} [IPFS instance] * @return {[Promise<IPFS>]} [IPFS instance]
*/ */
const startIpfs = (config = {}) => { const startIpfs = (type, config = {}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const ipfs = new IPFS(config) if (!testAPIs[type]) {
ipfs.on('error', reject) reject(new Error(`Wanted API type ${JSON.stringify(type)} is unknown. Available types: ${Object.keys(testAPIs).join(', ')}`))
ipfs.on('ready', () => resolve(ipfs)) }
// 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
View 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
View 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

View File

@ -3,11 +3,17 @@
const assert = require('assert') const assert = require('assert')
const rmrf = require('rimraf') const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB') const OrbitDB = require('../src/OrbitDB')
const config = require('./utils/config')
const startIpfs = require('./utils/start-ipfs')
const dbPath = './orbitdb/tests/sync' // Include test utilities
const ipfsPath = './orbitdb/tests/feed/ipfs' const {
config,
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
const dbPath = './orbitdb/tests/write-permissions'
const ipfsPath = './orbitdb/tests/write-permissions/ipfs'
const databases = [ 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) this.timeout(20000)
let ipfs, orbitdb1, orbitdb2 let ipfsd, ipfs, orbitdb1, orbitdb2
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo) rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath) rmrf.sync(dbPath)
ipfs = await startIpfs(config.daemon1) ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
orbitdb1 = new OrbitDB(ipfs, dbPath + '/1') orbitdb1 = new OrbitDB(ipfs, dbPath + '/1')
orbitdb2 = new OrbitDB(ipfs, dbPath + '/2') orbitdb2 = new OrbitDB(ipfs, dbPath + '/2')
}) })
@ -73,8 +81,8 @@ describe('orbit-db - Write Permissions', function() {
if(orbitdb2) if(orbitdb2)
await orbitdb2.stop() await orbitdb2.stop()
if (ipfs) if (ipfsd)
await ipfs.stop() await stopIpfs(ipfsd)
}) })
describe('allows multiple peers to write to the databases', function() { describe('allows multiple peers to write to the databases', function() {
@ -238,4 +246,5 @@ describe('orbit-db - Write Permissions', function() {
}) })
}) })
}) })
})
}) })