git ssb

3+

Dominic / ssb-blobs



Tree: bde3bf7b399b05e5d5c6475ee35ef2745c6788de

Files: bde3bf7b399b05e5d5c6475ee35ef2745c6788de / test / secret-stack.js

1246 bytesRaw
1var SecretStack = require('secret-stack')
2var crypto = require('crypto')
3var tape = require('tape')
4var path = require('path')
5var osenv = require('osenv')
6var mkdirp = require('mkdirp')
7var pull = require('pull-stream')
8
9//deterministic keys make testing easy.
10function hash (s) {
11 return crypto.createHash('sha256').update(s).digest()
12}
13
14var appkey = hash('TESTBLOBS')
15
16var create = SecretStack({ appKey: appkey }).use(require('../'))
17
18function tmp (name) {
19 var dir = path.join(osenv.tmpdir(), 'testblobs-'+Date.now()+'-'+name)
20 mkdirp.sync(dir)
21 return dir
22}
23
24var alice = create({ seed: hash('ALICE'), path: tmp('alice') })
25var bob = create({ seed: hash('BOB'), path: tmp('bob') })
26
27tape('alice pushes to bob', function (t) {
28
29 alice.connect(bob.address(), function (err, rpc) {
30 if(err) throw err
31 })
32
33 var hello = new Buffer('Hello World'), _hash
34
35 pull(
36 bob.blobs.ls({live: true, long: true}),
37 pull.take(1),
38 pull.collect(function (err, ary) {
39 t.equal(ary[0].id, _hash)
40 t.end()
41 alice.close()
42 bob.close()
43 })
44 )
45
46 pull(
47 pull.values([hello]),
48 alice.blobs.add(function (err, hash) {
49 _hash = hash
50 alice.blobs.push(hash)
51 })
52 )
53})
54
55

Built with git-ssb-web