git ssb

0+

Dominic / ssb-peer-invites



Tree: c42bd4ae81847e219235cbdc6c86571ff49fc410

Files: c42bd4ae81847e219235cbdc6c86571ff49fc410 / test / accept2.js

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

Built with git-ssb-web