Files: 01a757869a705123a648ec324185c123b95a10eb / test / accept2.js
2502 bytesRaw
1 | //WARNING: this test currently only passes |
2 | //if the computer has a network. |
3 | var crypto = require('crypto') |
4 | var I = require('../valid') |
5 | var createClient = require('ssb-client') |
6 | |
7 | |
8 | var ssbKeys = require('ssb-keys') |
9 | var tape = require('tape') |
10 | //var explain = require('explain-error') |
11 | var pull = require('pull-stream') |
12 | //var u = require('../lib/util') |
13 | var ref = require('ssb-ref') |
14 | |
15 | var createSbot = require('scuttlebot') |
16 | .use(require('ssb-links')) |
17 | .use({ |
18 | name: 'replicate', version: '1.0.0', |
19 | manifest: { request: 'sync' }, |
20 | init: function () { |
21 | return { request: function () {} } |
22 | } |
23 | }) |
24 | .use(require('ssb-query')) |
25 | .use(require('ssb-device-address')) |
26 | .use(require('ssb-identities')) |
27 | .use(require('ssb-friends')) |
28 | .use(require('../')) |
29 | |
30 | function all(stream, cb) { |
31 | return pull(stream, pull.collect(cb)) |
32 | } |
33 | |
34 | var alice = createSbot({ |
35 | temp: true, |
36 | timeout: 1000, |
37 | port: 12342, |
38 | keys:ssbKeys.generate(), |
39 | }) |
40 | var bob = createSbot({ |
41 | temp: true, |
42 | timeout: 1000, |
43 | port: 12343, |
44 | keys:ssbKeys.generate(), |
45 | }) |
46 | |
47 | function toId(msg) { |
48 | return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2)) |
49 | } |
50 | |
51 | tape('create an invite', function (t) { |
52 | |
53 | var seed = crypto.randomBytes(32) |
54 | |
55 | var content = I.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}) |
56 | // alice.publish(content, function (err, msg) { |
57 | // I.verifyInvitePublic(msg.value) |
58 | |
59 | alice.userInvites.create({}, function (err, invite) { |
60 | if(err) throw err |
61 | var seed = invite.seed |
62 | var invite_id = invite.invite |
63 | |
64 | //use device address, just for tests |
65 | invite.pubs.push(alice.getAddress('device')) |
66 | |
67 | bob.userInvites.openInvite(invite, function (err, invite_msg, data) { |
68 | if(err) throw err |
69 | t.ok(invite) |
70 | console.log(invite_msg, invite, invite_id) |
71 | t.equal(toId(invite_msg), invite_id) |
72 | var data = I.verifyInvitePrivate(invite_msg, seed) |
73 | t.deepEqual(data, {reveal: undefined, private: undefined}) |
74 | //check this invite is valid. would throw if it wasn't. |
75 | bob.userInvites.acceptInvite(invite, function (err, confirm) { |
76 | if(err) throw err |
77 | |
78 | //check that alice and bob both understand the other to be following them. |
79 | bob.friends.hops({reverse: true}, function (err, hops) { |
80 | t.equal(hops[alice.id], 1) |
81 | alice.friends.hops({reverse: true}, function (err, hops) { |
82 | t.equal(hops[bob.id], 1) |
83 | alice.close() |
84 | bob.close() |
85 | t.end() |
86 | }) |
87 | }) |
88 | }) |
89 | }) |
90 | }) |
91 | }) |
92 | |
93 | |
94 | |
95 | |
96 | |
97 |
Built with git-ssb-web