Files: 0d533f2e86c275fe20ee7d30ad22e15f5e6c944c / test / will-replicate.js
2013 bytesRaw
1 | |
2 | |
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 | var caps = { |
31 | sign: crypto.randomBytes(32),//.toString('base64'), |
32 | userInvite: crypto.randomBytes(32),//.toString('base64'), |
33 | shs: crypto.randomBytes(32),//.toString('base64'), |
34 | } |
35 | |
36 | var alice = createSbot({ |
37 | temp: true, |
38 | timeout: 1000, |
39 | port: 12342, |
40 | keys:ssbKeys.generate(), |
41 | caps: caps |
42 | }) |
43 | var bob = createSbot({ |
44 | temp: true, |
45 | timeout: 1000, |
46 | port: 12343, |
47 | keys:ssbKeys.generate(), |
48 | caps: caps |
49 | }) |
50 | |
51 | tape("alice will replicate bob's guests", function (t) { |
52 | alice.publish({ |
53 | type: 'contact', contact: bob.id, |
54 | following: true |
55 | }, function (err, data) { |
56 | if(err) throw err |
57 | t.ok(data) |
58 | console.log(data) |
59 | bob.connect(alice.getAddress(), function (err, _alice) { |
60 | if(err) throw err |
61 | _alice.userInvites.willReplicate(function (err, wr) { |
62 | if(err) throw err |
63 | t.ok(wr) //alice should replicate for bob's guests |
64 | _alice.close() |
65 | t.end() |
66 | }) |
67 | }) |
68 | }) |
69 | }) |
70 | |
71 | tape("bob won't replicate alice's guests", function (t) { |
72 | alice.connect(bob.getAddress(), function (err, _bob) { |
73 | if(err) throw err |
74 | _bob.userInvites.willReplicate(function (err, wr) { |
75 | if(err) throw err |
76 | t.notOk(wr) //alice should replicate for bob's guests |
77 | _bob.close() |
78 | t.end() |
79 | }) |
80 | }) |
81 | }) |
82 | |
83 | tape('clean up', function (t) { |
84 | alice.close() |
85 | bob.close() |
86 | t.end() |
87 | }) |
88 |
Built with git-ssb-web