Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: IPLD Resolver updated, all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Nov 20, 2016
1 parent 710e53f commit f53e0c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
7 changes: 3 additions & 4 deletions src/dag-node/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ function create (data, dagLinks, hashAlg, callback) {
return l
}

const link = new DAGLink(l.name || l.Name,
l.size || l.Size,
l.hash || l.Hash || l.multihash)
return link
return new DAGLink(l.name || l.Name,
l.size || l.Size,
l.hash || l.Hash || l.multihash)
})

sortInplace(links, linkSort)
Expand Down
11 changes: 6 additions & 5 deletions src/resolver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const util = require('./util').util
const util = require('./util')
const bs58 = require('bs58')

exports = module.exports
Expand Down Expand Up @@ -42,8 +42,8 @@ exports.resolve = (block, path, callback) => {
// for the resolver
node.links.forEach((l, i) => {
const link = l.toJSON()
values[i] = link.Hash
values[link.Name] = link.Hash
values[i] = link.hash
values[link.name] = link.hash
})

let value = values[split[1]]
Expand Down Expand Up @@ -89,14 +89,15 @@ exports.tree = (block, options, callback) => {
const paths = []
node.links.forEach((link) => {
paths.push({
path: link.name,
value: bs58.encode(link.hash).toString()
path: link.name || '',
value: bs58.encode(link.multihash).toString()
})
})

if (node.data && node.data.length > 0) {
paths.push({ path: 'data', value: node.data })
}

callback(null, paths)
})
}
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function toProtoBuf (node) {
if (node.links.length > 0) {
pbn.Links = node.links.map((link) => {
return {
Hash: link.hash,
Hash: link.multihash,
Name: link.name,
Tsize: link.size
}
Expand Down
36 changes: 14 additions & 22 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,46 @@
const expect = require('chai').expect
const dagPB = require('../src')
const DAGNode = dagPB.DAGNode
const util = dagPB.util
const resolver = dagPB.resolver
const parallel = require('async/parallel')

const Block = require('ipfs-block')

describe.skip('IPLD Format resolver (local)', () => {
describe('IPLD Format resolver (local)', () => {
let emptyNodeBlock
let linksNodeBlock
let dataLinksNodeBlock

const links = [{
Name: '',
Hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
Size: 10
name: undefined,
hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
size: 10
}, {
Name: 'named link',
Hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
Size: 8
name: 'named link',
hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
size: 8
}]

before((done) => {
// create a bunch of nodes serialized into Blocks
// const d1 = new DAGNode(new Buffer('some data'), l1)
const emptyNode = new DAGNode(new Buffer(0))

const linksNode = new DAGNode(new Buffer(0), links)
const dataLinksNode = new DAGNode(new Buffer('aaah the data'), links)

parallel([
(cb) => {
util.serialize(emptyNode, (err, serialized) => {
DAGNode.create(new Buffer(0), (err, node) => {
expect(err).to.not.exist
emptyNodeBlock = new Block(serialized)
emptyNodeBlock = new Block(node.serialized)
cb()
})
},
(cb) => {
util.serialize(linksNode, (err, serialized) => {
DAGNode.create(new Buffer(0), links, (err, node) => {
expect(err).to.not.exist
linksNodeBlock = new Block(serialized)
linksNodeBlock = new Block(node.serialized)
cb()
})
},
(cb) => {
util.serialize(dataLinksNode, (err, serialized) => {
DAGNode.create(new Buffer('aaah the data'), links, (err, node) => {
expect(err).to.not.exist
dataLinksNodeBlock = new Block(serialized)
dataLinksNodeBlock = new Block(node.serialized)
cb()
})
}
Expand Down Expand Up @@ -115,7 +107,7 @@ describe.skip('IPLD Format resolver (local)', () => {
it('links position path', (done) => {
resolver.resolve(linksNodeBlock, 'links/1', (err, result) => {
expect(err).to.not.exist
expect(result.value).to.eql(links[1].Hash)
expect(result.value).to.eql(links[1].hash)
expect(result.remainderPath).to.eql('')
done()
})
Expand Down

0 comments on commit f53e0c8

Please sign in to comment.