Files: 5972f7a224a6bfd3178683ba2f35c6109a72d504 / test / index.js
1274 bytesRaw
1 | var pull = require('pull-stream') |
2 | |
3 | var Swarm = require('../') |
4 | var ssbKeys = require('ssb-keys') |
5 | |
6 | var tape = require('tape') |
7 | |
8 | var ak = ssbKeys.generate() |
9 | var bk = ssbKeys.generate() |
10 | var ck = ssbKeys.generate() |
11 | var alice = Swarm(ak) |
12 | var bob = Swarm(bk) |
13 | var carol = Swarm(bk) |
14 | |
15 | //because everything in this module is sync, |
16 | //testing is quite straightforward. |
17 | |
18 | tape('simple', function (t) { |
19 | |
20 | var start = Date.now() |
21 | |
22 | alice.update({foo: true, address: 'here'}) |
23 | |
24 | bob.update({bar: true, address: 'there'}) |
25 | |
26 | console.log(alice.get(ak.id)) |
27 | |
28 | var ary = [] |
29 | pull(alice.send(0), pull.drain(function (data) { |
30 | ary.push(data) |
31 | })) |
32 | |
33 | var ts = ary.pop() |
34 | t.deepEqual(ary, [alice.get(ak.id)]) |
35 | t.ok(ts >= start) |
36 | t.end() |
37 | |
38 | }) |
39 | |
40 | tape('replicate', function (t) { |
41 | |
42 | |
43 | pull(bob.send(0), alice.recv(bk.id)) |
44 | |
45 | t.deepEqual(alice.get(bk.id), bob.get(bk.id)) |
46 | |
47 | bob.update({bar: false, address: 'yonder'}) |
48 | |
49 | t.deepEqual(alice.get(bk.id), bob.get(bk.id)) |
50 | |
51 | t.equal(alice.last(bk.id), bob.last(bk.id)) |
52 | |
53 | //connect bob -> alice -> carol |
54 | pull(alice.send(Date.now()), carol.recv(bk.id)) |
55 | |
56 | t.deepEqual(carol.get(bk.id), undefined) |
57 | |
58 | bob.update({bar: 1, address: 'thar'}) |
59 | |
60 | t.deepEqual(carol.get(bk.id), bob.get(bk.id)) |
61 | t.deepEqual(alice.get(bk.id), bob.get(bk.id)) |
62 | |
63 | |
64 | t.end() |
65 | |
66 | }) |
67 | |
68 |
Built with git-ssb-web