Skip to content

Commit 90e52de

Browse files
committed
Merge pull request #37 from noffle/check-daglink
Check explicitly for DAGLink instance.
2 parents b895f9b + 6d21cbf commit 90e52de

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/dag-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = class DAGNode {
5151
// ensure links are instances of DAGLink
5252
if (links) {
5353
links.forEach((l) => {
54-
if (l.name && typeof l.toJSON === 'function') {
54+
if (l.constructor && l.constructor.name === 'DAGLink') {
5555
this.links.push(l)
5656
} else {
5757
this.links.push(

test/dag-node-test.js

+23
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,28 @@ module.exports = function (repo) {
213213
'DAGNode <QmU1Sq1B7RPQD2XcQNLB58qJUyJffVJqihcxmmN1STPMxf - data: "hello world", links: 0, size: 13>'
214214
)
215215
})
216+
217+
it('add two nameless links to a node', function (done) {
218+
const l1 = {
219+
Name: '',
220+
Hash: 'QmbAmuwox51c91FmC2jEX5Ng4zS4HyVgpA5GNPBF5QsWMA',
221+
Size: 57806
222+
}
223+
const l2 = {
224+
Name: '',
225+
Hash: 'QmP7SrR76KHK9A916RbHG1ufy2TzNABZgiE23PjZDMzZXy',
226+
Size: 262158
227+
}
228+
const link1 = new DAGLink(l1.Name, l1.Size, new Buffer(bs58.decode(l1.Hash)))
229+
const link2 = new DAGLink(l2.Name, l2.Size, new Buffer(bs58.decode(l2.Hash)))
230+
231+
function createNode () {
232+
return new DAGNode(new Buffer('hiya'), [link1, link2])
233+
}
234+
235+
expect(createNode).to.not.throw()
236+
237+
done()
238+
})
216239
})
217240
}

0 commit comments

Comments
 (0)