git ssb

0+

Dominic / ssb-peer-invites



Tree: 391163e63d7f2d8f4b5c8568fb7bfe8c355a54d0

Files: 391163e63d7f2d8f4b5c8568fb7bfe8c355a54d0 / test / accept4.js

2272 bytesRaw
1var crypto = require('crypto')
2var I = require('../valid')
3var u = require('../util')
4
5var ssbKeys = require('ssb-keys')
6var tape = require('tape')
7var pull = require('pull-stream')
8
9var createSbot = require('ssb-server')
10 .use(require('ssb-links'))
11 .use({
12 name: 'replicate', version: '1.0.0',
13 manifest: { request: 'sync' },
14 init: function () {
15 return { request: function () {} }
16 }
17 })
18 .use(require('ssb-query'))
19 .use(require('ssb-device-address'))
20 .use(require('ssb-identities'))
21 .use(require('ssb-friends'))
22 .use(require('../'))
23
24function toId(msg) {
25 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
26}
27
28var caps = require('./randcaps')()
29
30var alice = createSbot({
31 temp: true,
32 timeout: 1000,
33 port: 12342,
34 keys:ssbKeys.generate(),
35 caps: caps
36})
37var bob = createSbot({
38 temp: true,
39 timeout: 1000,
40 port: 12343,
41 keys:ssbKeys.generate(),
42 caps: caps
43})
44
45tape('create an invite', function (t) {
46
47 alice.peerInvites.create({allowWithoutPubs: true}, function (err, _invite) {
48 if(err) throw err
49 var invite = u.parse(_invite)
50 var seed = invite.seed
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
62 //bob publishes accept_content manually. simulates that he crashed
63 //before causing confirm.
64 var accept_content = I.createAccept(invite_msg, seed, bob.id, caps)
65 bob.publish(accept_content, function (err, accept) {
66 if(err) throw err
67
68 bob.peerInvites.acceptInvite(invite, function (err, confirm) {
69 if(err) throw err
70
71 //check that alice and bob both understand the other to be following them.
72 bob.friends.hops({reverse: true}, function (err, hops) {
73 t.equal(hops[alice.id], 1)
74 alice.friends.hops({reverse: true}, function (err, hops) {
75 t.equal(hops[bob.id], 1)
76 alice.close()
77 bob.close()
78 t.end()
79 })
80 })
81 })
82 })
83 })
84 })
85})
86
87

Built with git-ssb-web