git ssb

1+

Dominic / %fKXHbMqtJYVrzUeI1gF…



Tree: 5972f7a224a6bfd3178683ba2f35c6109a72d504

Files: 5972f7a224a6bfd3178683ba2f35c6109a72d504 / test / index.js

1274 bytesRaw
1var pull = require('pull-stream')
2
3var Swarm = require('../')
4var ssbKeys = require('ssb-keys')
5
6var tape = require('tape')
7
8var ak = ssbKeys.generate()
9var bk = ssbKeys.generate()
10var ck = ssbKeys.generate()
11var alice = Swarm(ak)
12var bob = Swarm(bk)
13var carol = Swarm(bk)
14
15//because everything in this module is sync,
16//testing is quite straightforward.
17
18tape('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
40tape('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