Skip to content

Commit

Permalink
Merge pull request #37 from noffle/check-daglink
Browse files Browse the repository at this point in the history
Check explicitly for DAGLink instance.
  • Loading branch information
daviddias committed Jun 2, 2016
2 parents b895f9b + 6d21cbf commit 90e52de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dag-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = class DAGNode {
// ensure links are instances of DAGLink
if (links) {
links.forEach((l) => {
if (l.name && typeof l.toJSON === 'function') {
if (l.constructor && l.constructor.name === 'DAGLink') {
this.links.push(l)
} else {
this.links.push(
Expand Down
23 changes: 23 additions & 0 deletions test/dag-node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,28 @@ module.exports = function (repo) {
'DAGNode <QmU1Sq1B7RPQD2XcQNLB58qJUyJffVJqihcxmmN1STPMxf - data: "hello world", links: 0, size: 13>'
)
})

it('add two nameless links to a node', function (done) {
const l1 = {
Name: '',
Hash: 'QmbAmuwox51c91FmC2jEX5Ng4zS4HyVgpA5GNPBF5QsWMA',
Size: 57806
}
const l2 = {
Name: '',
Hash: 'QmP7SrR76KHK9A916RbHG1ufy2TzNABZgiE23PjZDMzZXy',
Size: 262158
}
const link1 = new DAGLink(l1.Name, l1.Size, new Buffer(bs58.decode(l1.Hash)))
const link2 = new DAGLink(l2.Name, l2.Size, new Buffer(bs58.decode(l2.Hash)))

function createNode () {
return new DAGNode(new Buffer('hiya'), [link1, link2])
}

expect(createNode).to.not.throw()

done()
})
})
}

0 comments on commit 90e52de

Please sign in to comment.