Files: 3f99bb4d8aafc51133acb53c3ff0b7d52f71aa1a / test / gossip.js
1732 bytesRaw
1 | |
2 | var cont = require('cont') |
3 | var deepEqual = require('deep-equal') |
4 | var tape = require('tape') |
5 | var pull = require('pull-stream') |
6 | var ssbKeys = require('ssb-keys') |
7 | |
8 | var u = require('./util') |
9 | var isArray = Array.isArray |
10 | |
11 | var createSbot = require('../') |
12 | .use(require('ssb-friends')) |
13 | .use(require('../plugins/gossip')) |
14 | // .use(require('../plugins/logging')) |
15 | |
16 | |
17 | var sbot = createSbot({ |
18 | temp: 'gossip', |
19 | keys: alice = ssbKeys.generate(), |
20 | timeout: 1000 |
21 | }) |
22 | |
23 | tape('gossip: add and get peers', function (t) { |
24 | |
25 | t.ok(isArray(sbot.gossip.peers())) |
26 | |
27 | var localhost = { |
28 | host: 'localhost', port: 8888, |
29 | key: ssbKeys.generate().id |
30 | } |
31 | var ip = { |
32 | host: '182.23.49.132', port: 8881, |
33 | key: ssbKeys.generate().id |
34 | } |
35 | var example = { |
36 | host: 'example.com', port: 8889, |
37 | key: ssbKeys.generate().id |
38 | } |
39 | |
40 | sbot.gossip.add(localhost) |
41 | sbot.gossip.add(ip) |
42 | sbot.gossip.add(example) |
43 | |
44 | t.deepEqual(sbot.gossip.peers(), [localhost, ip, example]) |
45 | |
46 | t.end() |
47 | |
48 | }) |
49 | |
50 | tape('gossip: errors on invalid peers', function (t) { |
51 | |
52 | var pk = ssbKeys.generate().id |
53 | console.log(pk) |
54 | |
55 | t.throws(function () { |
56 | sbot.gossip.add({host: 5, port: 1234, key: pk}) |
57 | }) |
58 | |
59 | t.throws(function () { |
60 | sbot.gossip.add({host: '10.0.0.2', port: 'not a port', key: pk}) |
61 | }) |
62 | |
63 | t.throws(function () { |
64 | sbot.gossip.add({host: '10.0.0.2', port: 1234, key: 'not a key'}) |
65 | }) |
66 | |
67 | t.end() |
68 | |
69 | }) |
70 | |
71 | tape('ignore invalid pub messages', function (t) { |
72 | |
73 | //missing address |
74 | sbot.publish({type: 'pub'}, function (err) { |
75 | if(err) throw err |
76 | t.end() |
77 | }) |
78 | |
79 | }) |
80 | |
81 | tape('cleanup', function (t) { |
82 | sbot.close(true, function () {}) |
83 | t.end() |
84 | //I don't know why this is necessary |
85 | //because the other tests exit fine. |
86 | process.exit(0) |
87 | }) |
88 | |
89 |
Built with git-ssb-web