git ssb

4+

Dominic / scuttlebot



Tree: 3f99bb4d8aafc51133acb53c3ff0b7d52f71aa1a

Files: 3f99bb4d8aafc51133acb53c3ff0b7d52f71aa1a / test / gossip.js

1732 bytesRaw
1
2var cont = require('cont')
3var deepEqual = require('deep-equal')
4var tape = require('tape')
5var pull = require('pull-stream')
6var ssbKeys = require('ssb-keys')
7
8var u = require('./util')
9var isArray = Array.isArray
10
11var createSbot = require('../')
12 .use(require('ssb-friends'))
13 .use(require('../plugins/gossip'))
14// .use(require('../plugins/logging'))
15
16
17var sbot = createSbot({
18 temp: 'gossip',
19 keys: alice = ssbKeys.generate(),
20 timeout: 1000
21})
22
23tape('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
50tape('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
71tape('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
81tape('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