Skip to content

Commit

Permalink
Use SSB-Validation-Dataset
Browse files Browse the repository at this point in the history
Problem: Maintaining one validation dataset per module means that we
can't build the dataset collaboratively and the validation dataset tends
toward stagnation.

Solution: Use a collaborative validation dataset, which provides a
handful of new and interesting test failures. This branch includes eight
new failing tests that we should aim to resolve.
  • Loading branch information
christianbundy committed Jun 12, 2020
1 parent e91f4d4 commit cdd3ec2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1,584 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"flumelog-offset": "^3.0.3",
"pull-stream": "^3.6.0",
"ssb-client": "^4.5.0",
"ssb-validation-dataset": "^1.1.0",
"tape": "^4.6.3"
},
"scripts": {
Expand Down
45 changes: 27 additions & 18 deletions test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@
var tape = require('tape')
var v = require('../')

var data = require('./data/test_messages.json')
data.forEach(function (e,i) {
if(e.valid)
tape('test valid message:'+i, function (t) {
var state = {feeds: {}, queue: []}
state.feeds[e.msg.author] = e.state
t.equal(v.id(e.msg), e.id)
v.append(state, e.cap, e.msg)
var data = require('ssb-validation-dataset')

const isObject = (subject) => typeof subject === 'object' && subject != null && Array.isArray(subject) === false

data.forEach(function (e, i) {
var state = { feeds: {}, queue: [] }
if (isObject(e.message)) {
state.feeds[e.message.author] = e.state
}
if (e.valid) {
tape(`Message ${i} is valid`, function (t) {
try {
t.equal(v.id(e.message), e.id)
v.append(state, e.hmacKey, e.message)
} catch (err) {
console.log(e)
t.fail(err)
}
t.end()
})
else
tape('test valid message:'+i, function (t) {
var state = {feeds: {}, queue: []}
state.feeds[e.msg.author] = e.state
} else {
tape(`Message ${i} is invalid: ${e.error}`, function (t) {
var state = { feeds: {}, queue: [] }
if (isObject(e.message)) {
state.feeds[e.message.author] = e.state
}
t.throws(function () {
try {
state = v.append(state, e.cap, e.msg)
console.log(e)
} catch(err) {
throw err
}
state = v.append(state, e.hmacKey, e.message)
console.log(e)
})
t.end()
})
}
})
167 changes: 0 additions & 167 deletions test/data/invalid_messages.json

This file was deleted.

Loading

0 comments on commit cdd3ec2

Please sign in to comment.