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

dedupe tests #573

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ module.exports = (common, options) => {
}))
})

it('should get dag node with options as the second param and cid with path', async function () {
const result = await ipfs.dag.get(`/ipfs/${cidCbor}/pb`, { localResolve: true })
expect(result.value._data).to.be.deep.eq(nodePb._data)
})

it('should get a dag-pb node', async () => {
const cid = await ipfs.dag.put(pbNode, {
format: 'dag-pb',
Expand Down Expand Up @@ -210,5 +215,29 @@ module.exports = (common, options) => {
const result = await ipfs.dag.get(cid)
expect(result.value).to.deep.equal(buf)
})

// This should be skipped in js-ipfs because it loads all the formats
it('should error when missing DAG resolver for multicodec from requested CID', async () => {
const block = await ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
})
await expect(ipfs.dag.get(block.cid)).to.be.rejectedWith('Missing IPLD format "git-raw"')
})

it('should error for invalid string CID input', async () => {
try {
await expect(ipfs.dag.get('INVALID CID')).to.be.rejected()
} catch (err) {
expect(err.code).to.equal('ERR_INVALID_CID')
}
})

it('should error for invalid buffer CID input', async () => {
try {
await expect(ipfs.dag.get(Buffer.from('INVALID CID'))).to.be.rejected()
} catch (err) {
expect(err.code).to.equal('ERR_INVALID_CID')
}
})
})
}
9 changes: 9 additions & 0 deletions src/files-mfs/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ module.exports = (common, options) => {

after(() => common.clean())

it('should ls mfs root by default', async () => {
const folder = `test-folder-${Math.random()}`

await ipfs.files.mkdir(`/${folder}`)
const files = await ipfs.files.ls()

expect(files.find(file => file.name === folder)).to.be.ok()
})

it('should not ls not found file/dir, expect error', () => {
const testDir = `/test-${hat()}`

Expand Down
79 changes: 79 additions & 0 deletions src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
const { fixtures } = require('./utils')
const Readable = require('readable-stream').Readable
const pull = require('pull-stream')
const mh = require('multihashes')
const CID = require('cids')
const expectTimeout = require('../utils/expect-timeout')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { supportsFileReader } = require('ipfs-utils/src/supports')
Expand Down Expand Up @@ -299,5 +301,82 @@ module.exports = (common, options) => {

await expectTimeout(ipfs.object.get(files[0].hash), 4000)
})

it('should add empty path and buffer content', async () => {
const expectedHash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX'
const content = Buffer.from('hello')

const res = await ipfs.add([{ path: '', content }])

expect(res).to.have.length(1)
expect(res[0].hash).to.equal(expectedHash)
})

it('should add with cid-version=1', async () => {
const expectedCid = 'bafkreiaoumr4mhytmxmaav7qbe2vpsmsxkdvyelbws5orak5u6bjrekuz4'
const options = { cidVersion: 1 }

const res = await ipfs.add('should add with cid-version=1', options)

expect(res).to.have.length(1)
expect(res[0].hash).to.equal(expectedCid)
})

it('should add with cid-version=1 and raw-leaves=false', async () => {
const expectedCid = 'bafybeifj7nuqlszk47q4jvdvaurqlb7ihbqfjxofg4hfcy53oc2s5tlg5m'
const options = { cidVersion: 1, rawLeaves: false }

const res = await ipfs.add('.add with cid-version=1 and raw-leaves=false', options)

expect(res).to.have.length(1)
expect(res[0].hash).to.equal(expectedCid)
})

it('should pin by default', async () => {
const initialPins = await ipfs.pin.ls()

await ipfs.add('should add pins by default')

const pinsAfterAdd = await ipfs.pin.ls()

expect(pinsAfterAdd.length).to.eql(initialPins.length + 1)
})

it('should not pin with pin=false', async () => {
const initialPins = await ipfs.pin.ls()

await ipfs.add('should not pin with pin=false', { pin: false })

const pinsAfterAdd = await ipfs.pin.ls()

expect(pinsAfterAdd.length).to.eql(initialPins.length)
})

// TODO: Test against all algorithms Object.keys(mh.names)
// This subset is known to work with both go-ipfs and js-ipfs as of 2017-09-05
const HASH_ALGS = [
'sha1',
'sha2-256',
'sha2-512',
// 'keccak-224', // go throws
'keccak-256',
// 'keccak-384', // go throws
'keccak-512'
]
HASH_ALGS.forEach((name) => {
it(`should add with hash=${name} and raw-leaves=false`, async () => {
const file = {
path: `${name}.txt`,
content: `should add with hash=${name} and raw-leaves=false`
}
const options = { hashAlg: name, rawLeaves: false }

const res = await ipfs.add([file], options)

expect(res).to.have.length(1)
const cid = new CID(res[0].hash)
expect(mh.decode(cid.multihash).name).to.equal(name)
})
})
})
}
8 changes: 8 additions & 0 deletions src/ping/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ module.exports = (common, options) => {

after(() => common.clean())

it('should send the default number of packets', async () => {
const responses = await ipfsA.ping(ipfsB.peerId.id)
responses.forEach(expectIsPingResponse)

const pongs = responses.filter(isPong)
expect(pongs.length).to.equal(10)
})

it('should send the specified number of packets', async () => {
const count = 3
const responses = await ipfsA.ping(ipfsB.peerId.id, { count })
Expand Down