Files: 9a17c94760002374e7b724537d1ea63dcd1b84e0 / test / msg-encoding.js
1939 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var pull = require('pull-stream') |
4 | var ssbKeys = require('ssb-keys') |
5 | var createFeed = require('ssb-feed') |
6 | var hexpp = require('hexpp') |
7 | var codec = require('../codec') |
8 | var createSSB = require('./util') |
9 | |
10 | var generate = ssbKeys.generate |
11 | var hash = ssbKeys.hash |
12 | |
13 | module.exports = function (opts) { |
14 | var content = { |
15 | 'type': 'post', |
16 | 'is': 'text', |
17 | 'text': 'test', |
18 | 'timezone': 300, |
19 | 'rebroadcasts': { |
20 | 'msg': |
21 | '1BHEHMwZlikXB3o1mg+fP3GVo/+Xb7p46u3rqt/hHkA=.blake2s', |
22 | 'feed': |
23 | 'rbU6CvdwBXxO/fDyoKuRyKxmZYyeb5+l87R9XVkN8bs=.blake2s', |
24 | 'timestamp': 1414078805677, |
25 | 'timezone': 300 |
26 | } |
27 | } |
28 | |
29 | var msg = { |
30 | author: hash('TEST_AUTHOR'), |
31 | previous: hash('TEST_PREVIOUS'), |
32 | timestamp: Date.now(), |
33 | sequence: 10, |
34 | content: content |
35 | } |
36 | |
37 | var signed = {} |
38 | |
39 | for (var k in msg) { signed[k] = msg[k] } |
40 | |
41 | signed.signature = Buffer.alloc(64).toString('base64') |
42 | |
43 | tape('Message', function (t) { |
44 | var enc = codec.encode(msg) |
45 | console.log('**** Message ****') |
46 | console.log(hexpp(enc)) |
47 | var o = codec.decode(enc) |
48 | t.deepEqual(o, msg) |
49 | t.end() |
50 | }) |
51 | |
52 | tape('Signed', function (t) { |
53 | var enc = codec.encode(signed) |
54 | console.log('**** Signed ****') |
55 | console.log(hexpp(enc)) |
56 | var o = codec.decode(enc) |
57 | t.deepEqual(o, signed) |
58 | t.end() |
59 | }) |
60 | |
61 | tape('known error case 1', function (t) { |
62 | var ssb = createSSB('test-ssb-encoding') |
63 | |
64 | var feed = createFeed(ssb, generate(), opts) |
65 | |
66 | feed.add(content, function (err, msg) { |
67 | if (err) throw err |
68 | t.assert(!!msg) |
69 | t.assert(!!msg.key) |
70 | t.assert(!!msg.value) |
71 | pull( |
72 | ssb.createFeedStream(), |
73 | pull.collect(function (err, ary) { |
74 | if (err) throw err |
75 | t.equal(ary.length, 1) |
76 | console.log(ary) |
77 | t.end() |
78 | }) |
79 | ) |
80 | }) |
81 | }) |
82 | } |
83 | |
84 | if (!module.parent) { module.exports(require('../defaults')) } |
85 |
Built with git-ssb-web