git ssb

0+

Dominic / ssb-peer-invites



Tree: 0e94992aa8bedac43906183f616bff699ec2484b

Files: 0e94992aa8bedac43906183f616bff699ec2484b / test / accept2.js

2054 bytesRaw
1//WARNING: this test currently only passes
2//if the computer has a network.
3var crypto = require('crypto')
4var u = require('../util')
5
6var ssbKeys = require('ssb-keys')
7var tape = require('tape')
8var pull = require('pull-stream')
9
10var createSbot = require('ssb-server')
11 .use(require('ssb-links'))
12 .use({
13 name: 'replicate', version: '1.0.0',
14 manifest: { request: 'sync' },
15 init: function () {
16 return { request: function () {} }
17 }
18 })
19 .use(require('ssb-query'))
20 .use(require('ssb-device-address'))
21 .use(require('ssb-identities'))
22 .use(require('ssb-friends'))
23 .use(require('../'))
24
25var caps = require('./randcaps')()
26
27var alice = createSbot({
28 temp: true,
29 timeout: 1000,
30 port: 12342,
31 keys:ssbKeys.generate(),
32 caps: caps
33})
34var bob = createSbot({
35 temp: true,
36 timeout: 1000,
37 port: 12343,
38 keys:ssbKeys.generate(),
39 caps: caps
40})
41
42function toId(msg) {
43 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
44}
45
46tape('create an invite', function (t) {
47
48 alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) {
49 if(err) throw err
50 var invite = u.parse(_invite)
51 var invite_id = invite.invite
52
53 //use device address, just for tests
54 invite.pubs.push(alice.getAddress('device'))
55
56 bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
57 if(err) throw err
58 t.ok(invite)
59 t.equal(toId(invite_msg), invite_id)
60 t.deepEqual(data, {reveal: undefined, private: undefined})
61 //check this invite is valid. would throw if it wasn't.
62 bob.peerInvites.acceptInvite(invite, function (err, confirm) {
63 if(err) throw err
64
65 //check that alice and bob both understand the other to be following them.
66 bob.friends.hops({reverse: true}, function (err, hops) {
67 t.equal(hops[alice.id], 1)
68 alice.friends.hops({reverse: true}, function (err, hops) {
69 t.equal(hops[bob.id], 1)
70 alice.close()
71 bob.close()
72 t.end()
73 })
74 })
75 })
76 })
77 })
78})
79
80

Built with git-ssb-web