diff --git a/package.json b/package.json index 9ae60d3..813f4ac 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,9 @@ "url": "git://github.com/ssbc/ssb-invite.git" }, "scripts": { - "test": "npm run test:js && npm run lint", + "test": "npm run test:js && npm run test:js:old && npm run lint", "test:js": "tape 'test/*.test.js' | tap-arc", + "test:js:old": "OLD_DEPS=true npm run test:js", "lint": "standard --fix" }, "dependencies": { @@ -27,6 +28,10 @@ "scuttle-testbot": "^2.2.0", "ssb-ebt": "^9.1.2", "ssb-friends": "^5.1.7", + "ssb-friends-4": "npm:ssb-friends@4.4.10", + "ssb-invite-2": "npm:ssb-invite@2.1.7", + "ssb-conn-1": "npm:ssb-conn@1.0.0", + "ssb-replicate": "^1.3.5", "ssb-replication-scheduler": "^3.1.0", "ssb-ws": "^6.2.3", "standard": "^17.1.0", diff --git a/test/cross-version.test.js b/test/cross-version.test.js new file mode 100644 index 0000000..f6ee9fe --- /dev/null +++ b/test/cross-version.test.js @@ -0,0 +1,110 @@ +/* eslint-disable no-useless-call */ +const test = require('tape') +const crypto = require('crypto') +const { promisify: p } = require('util') +const pull = require('pull-stream') + +const caps = { + shs: crypto.randomBytes(32).toString('base64') +} +const skip = process.env.OLD_DEPS // these tests don't use util/testbot.js + +test('old peer → new pub', { skip }, async t => { + const peer = require('scuttle-testbot') + .use(require('ssb-invite-2')) + .use(require('ssb-replicate')) + .use(require('ssb-friends-4')) + .use(require('ssb-conn-1')) + .call(null, { + name: 'old-peer', + db1: true, + caps + }) + + const pub = require('scuttle-testbot') + .use(require('../')) // ssb-invite-3 + .use(require('ssb-replicate')) + .use(require('ssb-friends-4')) + .use(require('ssb-conn-1')) + .call(null, { + name: 'new-pub', + db1: true, + caps, + allowPrivate: true + }) + + const invite = await p(pub.invite.create)({ uses: 1 }) + + await p(peer.invite.accept)(invite) + + const readyPromise = pull( + pub.createHistoryStream({ id: peer.id, live: true }), + pull.filter(m => m.value.content.type === 'hello!'), + pull.take(1), + pull.collectAsPromise() + ) + + await p(peer.publish)({ type: 'hello!' }) + .then(() => t.pass('peer publishes a new message')) + .catch(err => t.error(err, 'peer publishes a new message')) + + const [{ value }] = await readyPromise + t.equal(value.author, peer.id, 'pub replicated message from peer') + t.equal(value.content.type, 'hello!', 'its hello!') + + await Promise.all([ + p(peer.close)(true), + p(pub.close)(true) + ]) + t.end() +}) + +test('new peer → old pub', { skip }, async t => { + const peer = require('scuttle-testbot') + .use(require('../')) // ssb-invite-3 + .use(require('ssb-replicate')) + .use(require('ssb-friends-4')) + .use(require('ssb-conn-1')) + .call(null, { + name: 'old-peer', + db1: true, + caps + }) + + const pub = require('scuttle-testbot') + .use(require('ssb-invite-2')) + .use(require('ssb-replicate')) + .use(require('ssb-friends-4')) + .use(require('ssb-conn-1')) + .call(null, { + name: 'new-pub', + db1: true, + caps, + allowPrivate: true + }) + + const invite = await p(pub.invite.create)({ uses: 1 }) + + await p(peer.invite.accept)(invite) + + const readyPromise = pull( + pub.createHistoryStream({ id: peer.id, live: true }), + pull.filter(m => m.value.content.type === 'hello!'), + pull.take(1), + pull.collectAsPromise() + ) + + await p(peer.publish)({ type: 'hello!' }) + .then(() => t.pass('peer publishes a new message')) + .catch(err => t.error(err, 'peer publishes a new message')) + + const [{ value }] = await readyPromise + t.equal(value.author, peer.id, 'pub replicated message from peer') + t.equal(value.content.type, 'hello!', 'its hello!') + + await Promise.all([ + p(peer.close)(true), + p(pub.close)(true) + ]) + t.end() +}) diff --git a/test/test-bot.js b/test/test-bot.js index 3567c57..ef3cc4e 100644 --- a/test/test-bot.js +++ b/test/test-bot.js @@ -12,11 +12,20 @@ module.exports = function (opts = {}) { const stack = require('scuttle-testbot') .use(require('..')) - .use(require('ssb-friends')) - .use(require('ssb-ebt')) - .use(require('ssb-replication-scheduler')) .use(require('ssb-ws')) + if (process.env.OLD_DEPS) { + stack + .use(require('ssb-replicate')) + .use(require('ssb-friends-4')) + .use(require('ssb-conn-1')) + } else { + stack + .use(require('ssb-friends')) + .use(require('ssb-ebt')) + .use(require('ssb-replication-scheduler')) + } + return stack({ db1: true, ...opts