Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: modular interface tests #785

Merged
merged 20 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"glob": "^7.1.2",
"ipfs-block": "~0.7.1",
"ipfs-unixfs": "~0.1.15",
"ipld-dag-cbor": "~0.12.0",
"ipld-dag-pb": "~0.14.4",
"ipld-dag-cbor": "~0.12.1",
"ipld-dag-pb": "~0.14.5",
"is-ipfs": "~0.3.2",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
Expand All @@ -48,7 +48,7 @@
"multihashes": "~0.4.13",
"ndjson": "^1.5.0",
"once": "^1.4.0",
"peer-id": "~0.10.7",
"peer-id": "~0.11.0",
"peer-info": "~0.14.1",
"promisify-es6": "^1.0.3",
"pull-defer": "~0.2.2",
Expand All @@ -74,13 +74,13 @@
"aegir": "^14.0.0",
"browser-process-platform": "~0.1.1",
"chai": "^4.1.2",
"cross-env": "^5.1.6",
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.9.1",
"eslint-plugin-react": "^7.10.0",
"go-ipfs-dep": "~0.4.15",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.69.1",
"ipfsd-ctl": "~0.37.3",
"interface-ipfs-core": "~0.71.0",
"ipfsd-ctl": "~0.37.5",
"pull-stream": "^3.6.8",
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1",
Expand Down
67 changes: 40 additions & 27 deletions src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,67 @@ const dagCBOR = require('ipld-dag-cbor')
const promisify = require('promisify-es6')
const CID = require('cids')
const multihash = require('multihashes')
const setImmediate = require('async/setImmediate')
const SendOneFile = require('../utils/send-one-file')

function noop () {}

module.exports = (send) => {
const sendOneFile = SendOneFile(send, 'dag/put')

return promisify((dagNode, options, callback) => {
if (typeof options === 'function') {
return setImmediate(() => callback(new Error('no options were passed')))
callback = options
}

callback = callback || noop
options = options || {}

let hashAlg = options.hash || 'sha2-256'
let format
let inputEnc
if (options.hash) {
options.hashAlg = options.hash
delete options.hash
}

if (options.cid && CID.isCID(options.cid)) {
format = options.cid.codec
hashAlg = multihash.decode(options.cid.multihash).name
prepare()
} else if (options.format) {
format = options.format
prepare()
} else {
callback(new Error('Invalid arguments'))
if (options.cid && (options.format || options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hash` options.'))
} else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide `format` AND `hash` options.'))
}

function prepare () {
inputEnc = 'raw'
if (options.cid) {
let cid

if (format === 'dag-cbor') {
dagCBOR.util.serialize(dagNode, finalize)
}
if (format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
try {
cid = new CID(options.cid)
} catch (err) {
return callback(err)
}

options.format = cid.codec
options.hashAlg = multihash.decode(cid.multihash).name
delete options.cid
}

const optionDefaults = {
format: 'dag-cbor',
hashAlg: 'sha2-256',
inputEnc: 'raw'
}

options = Object.assign(optionDefaults, options)

if (options.format === 'dag-cbor') {
dagCBOR.util.serialize(dagNode, finalize)
} else if (options.format === 'dag-pb') {
dagPB.util.serialize(dagNode, finalize)
} else {
// FIXME Hopefully already serialized...can we use IPLD to serialise instead?
finalize(null, dagNode)
}

function finalize (err, serialized) {
if (err) { return callback(err) }
const sendOptions = {
qs: {
hash: hashAlg,
format: format,
'input-enc': inputEnc
hash: options.hashAlg,
format: options.format,
'input-enc': options.inputEnc
}
}
sendOneFile(serialized, sendOptions, (err, result) => {
Expand Down
246 changes: 246 additions & 0 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/* eslint-env mocha */
'use strict'

const tests = require('interface-ipfs-core')
const isNode = require('detect-node')
const CommonFactory = require('./utils/interface-common-factory')
const IPFSApi = require('../src')
const isWindows = process.platform && process.platform === 'win32'

describe('interface-ipfs-core tests', () => {
const defaultCommonFactory = CommonFactory.create()

tests.bitswap(defaultCommonFactory, {
skip: [
// bitswap.stat
{
name: 'should not get bitswap stats when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
},
// bitswap.wantlist
{
name: 'should not get the wantlist when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
},
// bitswap.unwant
{
name: 'should remove a key from the wantlist',
reason: 'FIXME why is this skipped?'
},
{
name: 'should not remove a key from the wantlist when offline',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
}
]
})

tests.block(defaultCommonFactory)

tests.bootstrap(defaultCommonFactory)

tests.config(defaultCommonFactory, {
skip: [
// config.replace
{
name: 'replace',
reason: 'FIXME Waiting for fix on go-ipfs https://github.com/ipfs/js-ipfs-api/pull/307#discussion_r69281789 and https://github.com/ipfs/go-ipfs/issues/2927'
}
]
})

tests.dag(defaultCommonFactory, {
skip: [
// dag.tree
{
name: 'tree',
reason: 'TODO vmx 2018-02-22: Currently the tree API is not exposed in go-ipfs'
},
// dag.get:
{
name: 'should get a dag-pb node local value',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
},
{
name: 'should get dag-pb value via dag-cbor node',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
},
{
name: 'should get by CID string + path',
reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done'
}
]
})

tests.dht(defaultCommonFactory, {
skip: [
// dht.findpeer
{
name: 'should fail to find other peer if peer does not exist',
reason: 'FIXME checking what is exactly go-ipfs returning https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090'
},
// dht.findprovs
{
name: 'should provide from one node and find it through another node',
reason: 'FIXME go-ipfs endpoint doesn\'t conform with the others https://github.com/ipfs/go-ipfs/issues/5047'
},
// dht.get
{
name: 'should get a value after it was put on another node',
reason: 'FIXME go-ipfs errors with Error: key was not found (type 6) https://github.com/ipfs/go-ipfs/issues/3862'
}
]
})

tests.files(defaultCommonFactory, {
skip: [
// files.add
isNode ? null : {
name: 'should add a nested directory as array of tupples',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
isNode ? null : {
name: 'should add a nested directory as array of tupples with progress',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.addPullStream
isNode ? null : {
name: 'should add pull stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.addReadableStream
isNode ? null : {
name: 'should add readable stream of valid files and dirs',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// files.catPullStream
{
name: 'should export a chunk of a file',
reason: 'TODO not implemented in go-ipfs yet'
},
{
name: 'should export a chunk of a file in a Pull Stream',
reason: 'TODO not implemented in go-ipfs yet'
},
{
name: 'should export a chunk of a file in a Readable Stream',
reason: 'TODO not implemented in go-ipfs yet'
},
// files.get
isNode ? null : {
name: 'should get a directory',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
}
]
})

tests.key(defaultCommonFactory, {
skip: [
// key.export
{
name: 'export',
reason: 'TODO not implemented in go-ipfs yet'
},
// key.import
{
name: 'import',
reason: 'TODO not implemented in go-ipfs yet'
}
]
})

tests.ls(defaultCommonFactory, {
skip: [
// lsPullStream
isNode ? null : {
name: 'should pull stream ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// lsReadableStream
isNode ? null : {
name: 'should readable stream ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
},
// ls
isNode ? null : {
name: 'should ls with a base58 encoded CID',
reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339'
}
]
})

tests.miscellaneous(defaultCommonFactory, {
skip: [
// stop
{
name: 'should stop the node',
reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078'
}
]
})

tests.object(defaultCommonFactory)

tests.pin(defaultCommonFactory)

tests.ping(defaultCommonFactory)

tests.pubsub(CommonFactory.create({
spawnOptions: {
args: ['--enable-pubsub-experiment'],
initOptions: { bits: 1024 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use 1024 for all tests? It would make things way faster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this was actually lost with this change, before all tests used 1024.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood! Thanks :)

}
}), {
skip: isNode ? [
// pubsub.subscribe
isWindows ? {
name: 'should send/receive 100 messages',
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
} : null,
isWindows ? {
name: 'should receive multiple messages',
reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778'
} : null
] : {
reason: 'FIXME pubsub is not supported in the browser https://github.com/ipfs/js-ipfs-api/issues/518'
}
})

tests.repo(defaultCommonFactory)

tests.stats(defaultCommonFactory)

tests.swarm(CommonFactory.create({
createSetup ({ ipfsFactory, nodes }) {
return callback => {
callback(null, {
spawnNode (repoPath, config, cb) {
if (typeof repoPath === 'function') {
cb = repoPath
repoPath = undefined
}

if (typeof config === 'function') {
cb = config
config = undefined
}

const spawnOptions = { repoPath, config, initOptions: { bits: 1024 } }

ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, IPFSApi(_ipfsd.apiAddr))
})
}
})
}
}
}))

tests.types(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })

tests.util(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } })
})
Loading