Files: 8299fab7cda81af8f07aacbeb7374249c6e8d848 / test / accept.js
2562 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(require('../')) |
18 | |
19 | function all(stream, cb) { |
20 | return pull(stream, pull.collect(cb)) |
21 | } |
22 | |
23 | var alice = createSbot({ |
24 | temp: true, |
25 | timeout: 1000, |
26 | port: 12342, |
27 | keys:ssbKeys.generate(), |
28 | }) |
29 | var bob = createSbot({ |
30 | temp: true, |
31 | timeout: 1000, |
32 | port: 12343, |
33 | keys:ssbKeys.generate(), |
34 | }) |
35 | |
36 | tape('create an invite', function (t) { |
37 | |
38 | var seed = crypto.randomBytes(32) |
39 | |
40 | var content = I.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}) |
41 | alice.publish(content, function (err, msg) { |
42 | // console.log(msg) |
43 | I.verifyInvitePublic(msg.value) |
44 | console.log("REMOTE", alice.getAddress()) |
45 | |
46 | createClient( |
47 | ssbKeys.generate(null, seed), |
48 | { |
49 | remote: alice.getAddress(), |
50 | caps: require('ssb-config').caps, |
51 | manifest: { |
52 | invites: { |
53 | getInvite: 'async', |
54 | accept: 'async' |
55 | } |
56 | } |
57 | }, |
58 | function (err, _bob) { |
59 | if(err) throw err |
60 | _bob.invites.getInvite(msg.key, function (err, invite) { |
61 | if(err) throw err |
62 | t.ok(invite) |
63 | t.deepEqual(invite, msg.value) |
64 | //check this invite is valid. |
65 | I.verifyInvitePrivate(invite, seed) |
66 | |
67 | //bob chooses to accept this invite. |
68 | var accept_content = I.createAccept(invite, seed, bob.id) |
69 | |
70 | bob.publish(accept_content, function (err, accept) { |
71 | if(err) throw err |
72 | _bob.invites.accept(accept.value, function (err, msg) { |
73 | if(err) throw err |
74 | t.ok(msg) |
75 | var confirm_id = '%'+ssbKeys.hash(JSON.stringify(msg, null, 2)) |
76 | alice.get(confirm_id, function (err, _msg) { |
77 | if(err) throw err |
78 | t.deepEqual(msg, _msg) |
79 | |
80 | _bob.invites.accept(accept.value, function (err, msg2) { |
81 | if(err) throw err |
82 | t.deepEqual(msg2, msg) |
83 | console.log('accept2', msg2) |
84 | alice.close() |
85 | bob.close() |
86 | t.end() |
87 | }) |
88 | }) |
89 | }) |
90 | }) |
91 | }) |
92 | } |
93 | ) |
94 | }) |
95 | }) |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 |
Built with git-ssb-web