1 | const debug = require('debug')('ssb-blobs')
|
2 | var tape = require('tape')
|
3 | var Blobs = require('../inject')
|
4 | var pull = require('pull-stream')
|
5 | var assert = require('assert')
|
6 | var cont = require('cont')
|
7 | var u = require('./util')
|
8 | var Fake = u.fake
|
9 | var hash = u.hash
|
10 |
|
11 | module.exports = function (createBlobs, createAsync) {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | tape('push 3', function (t) {
|
24 | createAsync(function (async) {
|
25 | var n = 0
|
26 | var alice = createBlobs('alice', async)
|
27 | var bob = createBlobs('bob', async)
|
28 | var carol = createBlobs('carol', async)
|
29 | var dan = createBlobs('dan', async)
|
30 |
|
31 | var blob = Fake('baz', 64)
|
32 | var h = hash(blob)
|
33 |
|
34 | u.peers('alice', alice, 'bob', bob)
|
35 | u.peers('alice', alice, 'carol', carol)
|
36 | u.peers('alice', alice, 'dan', dan)
|
37 |
|
38 | pull(alice.pushed(), pull.drain(function (data) {
|
39 | assert.deepEqual(data, {key: h, peers: {bob: 64, carol: 64, dan: 64}})
|
40 | debug("PUSHED", data)
|
41 | cont.para([bob, carol, dan].map(function (p) {
|
42 | return cont(p.has)(h)
|
43 | }))
|
44 | (function (err, ary) {
|
45 | debug('HAS', err, ary)
|
46 | if(err) throw err
|
47 | assert.deepEqual(ary, [true, true, true])
|
48 | async.done()
|
49 | })
|
50 | }))
|
51 |
|
52 | pull(pull.once(blob), alice.add())
|
53 | alice.push(h)
|
54 |
|
55 | }, function (err) {
|
56 | if(err) throw err
|
57 | t.end()
|
58 | })
|
59 | })
|
60 |
|
61 | }
|
62 |
|
63 | if(!module.parent) u.tests(module.exports)
|
64 |
|
65 |
|
66 |
|