-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for invite replication between invite 2/3
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) |