Files: 3f14a6dcd8d9c4cb8d9fa48e216e5c4c1e91d52a / test / accept4.js
2350 bytesRaw
1 | var crypto = require('crypto') |
2 | var I = require('../valid') |
3 | var u = require('../util') |
4 | |
5 | var ssbKeys = require('ssb-keys') |
6 | var tape = require('tape') |
7 | var pull = require('pull-stream') |
8 | |
9 | var 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 | |
24 | function toId(msg) { |
25 | return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2)) |
26 | } |
27 | |
28 | var caps = require('./randcaps')() |
29 | |
30 | var alice = createSbot({ |
31 | temp: true, |
32 | timeout: 1000, |
33 | port: 12342, |
34 | keys:ssbKeys.generate(), |
35 | caps: caps |
36 | }) |
37 | var bob = createSbot({ |
38 | temp: true, |
39 | timeout: 1000, |
40 | port: 12343, |
41 | keys:ssbKeys.generate(), |
42 | caps: caps |
43 | }) |
44 | |
45 | tape('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(u.stringify(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 | if(err) throw err |
74 | t.equal(hops[alice.id], 1) |
75 | alice.friends.hops({reverse: true}, function (err, hops) { |
76 | if(err) throw err |
77 | t.equal(hops[bob.id], 1) |
78 | alice.close() |
79 | bob.close() |
80 | t.end() |
81 | }) |
82 | }) |
83 | }) |
84 | }) |
85 | }) |
86 | }) |
87 | }) |
88 | |
89 | |
90 | |
91 | |
92 |
Built with git-ssb-web