1 | const pull = require('pull-stream')
|
2 | const tape = require('tape')
|
3 | const u = require('./util')
|
4 |
|
5 | const botA = u.Server({
|
6 | replicate: {
|
7 | hops: 100,
|
8 | legacy: false
|
9 | }
|
10 | })
|
11 |
|
12 | tape('empty database follow self', function (t) {
|
13 | pull(
|
14 | botA.friends.createFriendStream(),
|
15 | pull.collect(function (err, a) {
|
16 | t.error(err)
|
17 | t.deepEqual(a, [botA.id])
|
18 | t.end()
|
19 | })
|
20 | )
|
21 | })
|
22 |
|
23 | const gen = require('ssb-generate')
|
24 |
|
25 | tape('live follows works', function (t) {
|
26 | const a = []
|
27 |
|
28 | pull(
|
29 | botA.friends.createFriendStream({
|
30 | live: true,
|
31 | meta: true,
|
32 | hops: 10
|
33 | }),
|
34 | pull.drain(function (m) {
|
35 | a.push(m)
|
36 | })
|
37 | )
|
38 |
|
39 | gen.initialize(botA, 10, 2, function (err, peers, hops) {
|
40 | t.error(err, 'initialize test data')
|
41 |
|
42 | console.log(a.length, hops)
|
43 |
|
44 | const seen = {}
|
45 | let count = 0
|
46 | const notSeen = {}
|
47 |
|
48 | peers.forEach(function (v) {
|
49 | notSeen[v.id] = true
|
50 | })
|
51 |
|
52 | a.forEach(function (v) {
|
53 | if (!seen[v.id]) {
|
54 | seen[v.id] = true
|
55 | delete notSeen[v.id]
|
56 | count++
|
57 | }
|
58 | })
|
59 |
|
60 | botA.friends.hops(function (err, hops) {
|
61 | if (err) throw err
|
62 | for (const k in notSeen) { console.log('NS', k, hops[k]) }
|
63 |
|
64 | t.deepEqual(notSeen, {})
|
65 | t.deepEqual(count, peers.length, 'all peers streamed')
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | botA.close(err => {
|
72 | t.end(err, 'botA closed')
|
73 | })
|
74 | })
|
75 | })
|
76 | })
|
77 |
|
78 | tape('chill plugin order', t => {
|
79 | const createSbot = require('scuttle-testbot')
|
80 | .use(require('..'))
|
81 | .use(require('ssb-replicate'))
|
82 |
|
83 | const bot = createSbot({
|
84 | replicate: {
|
85 | hops: 100,
|
86 | legacy: false
|
87 | }
|
88 | })
|
89 |
|
90 | t.true(bot, 'loads plugins in whatever order fine')
|
91 | bot.close(err => {
|
92 | t.error(err, 'close bot')
|
93 | t.end()
|
94 | })
|
95 | })
|