git ssb

0+

Dominic / ssb-feed



Commit 7f5b9989dbc45ee625499416f98f9ce28de20509

pass options through to tests

Dominic Tarr committed on 10/4/2016, 7:06:45 PM
Parent: 9b06ba56f9534d1a30e441adcdd38e4c343744ce

Files changed

test/feed.jschanged
test/mock.jschanged
test/fork.jsadded
test/feed.jsView
@@ -15,9 +15,9 @@
1515 tape('simple', function (t) {
1616
1717 createAsync(function (async) {
1818
19- var ssb = createMock(async)
19 + var ssb = createMock(async, opts)
2020
2121 var feed = createFeed(ssb, ssbkeys.generate('ed25519', seed), opts)
2222
2323 feed.add({type: 'msg', value: 'hello there!'}, function (err, msg) {
@@ -46,9 +46,9 @@
4646
4747 //write in series
4848 tape('tail', function (t) {
4949 createAsync(function (async) {
50- var ssb = createMock(async)
50 + var ssb = createMock(async, opts)
5151
5252 var feed = createFeed(ssb, ssbkeys.generate('ed25519', seed), opts)
5353
5454 console.log('add 1'); console.log('add 2');
@@ -96,9 +96,9 @@
9696 })
9797
9898 tape('tail, parallel add', function (t) {
9999 createAsync(function (async) {
100- var ssb = createMock(async)
100 + var ssb = createMock(async, opts)
101101
102102 var feed = createFeed(ssb, ssbkeys.generate('ed25519', seed), opts)
103103
104104 var nDrains = 0, nAdds = 2, l = 7
@@ -146,9 +146,9 @@
146146 })
147147
148148 tape('too big', function (t) {
149149 createAsync(function (async) {
150- var ssb = createMock(async)
150 + var ssb = createMock(async, opts)
151151 var keys = ssbkeys.generate()
152152 var feed = createFeed(ssb, ssbkeys.generate('ed25519', seed), opts)
153153 var str = ''
154154 for (var i=0; i < 808; i++) str += '1234567890'
@@ -184,7 +184,16 @@
184184 })
185185
186186 }
187187
188-if(!module.parent)
189- module.exports(require('./mock'), require('./util').sync, {remote: false})
188 +if(!module.parent) {
189 + //tests without a cap
190 + module.exports(require('./mock'), require('./util').sync, { remote: false })
191 + //with cap
192 + module.exports(require('./mock'), require('./util').sync, {
193 + remote: false, caps: {sign: crypto.createHash('sha256').digest('test with digest').toString('base64')}
194 +})
190195
196 +}
197 +
198 +
199 +
test/mock.jsView
@@ -8,9 +8,9 @@
88 }
99
1010 var pull = require('pull-stream')
1111
12-module.exports = function (async) {
12 +module.exports = function (async, opts) {
1313
1414 var data = [], validator, live
1515
1616 var ssbMock = {
@@ -66,10 +66,10 @@
6666 async.through('feed')
6767 )
6868 }
6969 }
70 + ssbMock.add = Validator(ssbMock, opts)
7071
71- ssbMock.add = Validator(ssbMock)
72-
7372 return ssbMock
7473 }
7574
75 +
test/fork.jsView
@@ -1,0 +1,91 @@
1 +'use strict'
2 +var tape = require('tape')
3 +var pull = require('pull-stream')
4 +var ssbKeys = require('ssb-keys')
5 +var createFeed = require('../')
6 +var ssbkeys = ssbKeys
7 +
8 +var crypto = require('crypto')
9 +
10 +var seed = crypto.createHash('sha256').update('test1').digest()
11 +var sign_cap = crypto.createHash('sha256').update('test1').digest()
12 +var assert = require('assert')
13 +
14 +module.exports = function (createMock, createAsync, opts) {
15 +
16 +
17 + tape('simple', function (t) {
18 + createAsync(function (async) {
19 + var ssb1 = createMock(async, {})
20 + var ssb2 = createMock(async, {caps: {sign: sign_cap}})
21 +
22 + var feed = createFeed(ssb1, ssbkeys.generate('ed25519', seed), opts)
23 +
24 + feed.add({type: 'msg', value: 'hello there!'}, function (err, msg) {
25 + if(err) throw err
26 + console.log('added', msg)
27 + assert.ok(!!msg)
28 + assert.ok(!!msg.key)
29 + assert.ok(!!msg.value)
30 + ssb2.add(msg.value, function (err) {
31 + t.ok(err)
32 + t.ok(/signature was invalid/.test(err.message))
33 + console.log(err)
34 + t.end()
35 + })
36 + })
37 + })
38 + })
39 +
40 + tape('check that default validates old default messages', function (t) {
41 + createAsync(function (async) {
42 +
43 + var ssb1 = createMock(async, {})
44 + var ssb2 = createMock(async, {caps: {sign: sign_cap}})
45 +
46 + var data = { //first message in my log.
47 + "key": "%7iU6nEO35X37x7lFGXpwx8fWFDFIwAaxQNu2ySVVz10=.sha256",
48 + "value": {
49 + "previous": null,
50 + "author": "@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519",
51 + "sequence": 1,
52 + "timestamp": 1449201626119,
53 + "hash": "sha256",
54 + "content": {
55 + "type": "about",
56 + "about": "@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519",
57 + "name": "Dominic_2"
58 + },
59 + "signature": "vyn7WnkamEjHvQ1/crAZgKUi6ucOcHkpG4uRdSMjZdJnT8eyyH63rCmsC4A0bmhDaDPEwCVHoOF4NQHiVS+0Cg==.sig.ed25519"
60 + },
61 + "timestamp": 1472327253354
62 + }
63 +
64 + ssb1.add(data.value, function (err, msg) {
65 + if(err) throw err
66 +
67 + ssb2.add(data.value, function (err) {
68 + t.ok(/signature was invalid/.test(err.message))
69 + t.end()
70 + })
71 + })
72 + })
73 + })
74 +}
75 +
76 +
77 +
78 +
79 +if(!module.parent) {
80 + module.exports(require('./mock'), require('./util').sync)
81 +
82 +}
83 +
84 +
85 +
86 +
87 +
88 +
89 +
90 +
91 +

Built with git-ssb-web