git ssb

4+

Dominic / scuttlebot



Tree: d42610e87a071fe62aa1d0ad3053db084fb8076d

Files: d42610e87a071fe62aa1d0ad3053db084fb8076d / test / block3.js

2234 bytesRaw
1var cont = require('cont')
2var tape = require('tape')
3var pull = require('pull-stream')
4var u = require('./util')
5
6var replicate = require('../plugins/replicate')
7var friends = require('ssb-friends')
8var ssbKeys = require('ssb-keys')
9var toAddress = require('../lib/util').toAddress
10
11
12// alice, bob, and carol all follow each other,
13// but then bob offends alice, and she blocks him.
14// this means that:
15//
16// 1. when bob tries to connect to alice, she refuses.
17// 2. alice never tries to connect to bob. (removed from peers)
18// 3. carol will not give bob any, she will not give him any data from alice.
19
20var createSbot = require('../')
21 .use(require('../plugins/replicate'))
22 .use(require('ssb-friends'))
23
24var alice = createSbot({
25 temp: 'test-block-alice', timeout: 1000,
26 keys: ssbKeys.generate()
27 })
28
29var bob = createSbot({
30 temp: 'test-block-bob', timeout: 1000,
31 keys: ssbKeys.generate()
32 })
33
34var carol = createSbot({
35 temp: 'test-block-carol', timeout: 1000,
36 keys: ssbKeys.generate()
37 })
38
39
40
41tape('alice blocks bob while he is connected, she should disconnect him', function (t) {
42
43 //in the beginning alice and bob follow each other
44 cont.para([
45 alice.publish(u.follow(bob.id)),
46 bob .publish(u.follow(alice.id)),
47 carol.publish(u.follow(alice.id))
48 ]) (function (err) {
49 if(err) throw err
50
51 var n = 3, rpc
52
53 bob.connect(carol.getAddress(), function (err, rpc) {
54 if(err) throw err
55 })
56
57 carol.connect(alice.getAddress(), function (err, rpc) {
58 if(err) throw err
59 })
60
61 bob.on('replicate:finish', function (vclock) {
62 //I don't care which messages bob doesn't have of alice's
63 t.ok(vclock[alice.id] < 2, 'bob has alices first message')
64 alice.close();bob.close();carol.close()
65 t.end()
66 })
67
68 var once = false
69 var bobCancel = bob.post(function (op) {
70 console.log('BOB RECV', op, bob.id)
71 if(once) throw new Error('should only be called once')
72 once = true
73 //should be the alice's follow(bob) message.
74
75 t.equal(op.value.author, alice.id)
76 t.equal(op.value.content.contact, bob.id)
77 alice.publish(u.block(bob.id))
78 (function (err) { if(err) throw err })
79 }, false)
80 })
81})
82
83
84
85
86

Built with git-ssb-web