Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b4c021d

Browse files
authored
Refactor refs tests (#2972)
* refactor: s/block.put/object.put/ in refs test * refactor: s/add/block.put/ in refs test * refactor: remove semicolons
1 parent 9d88a2e commit b4c021d

File tree

1 file changed

+20
-8
lines changed
  • packages/interface-ipfs-core/src

1 file changed

+20
-8
lines changed

packages/interface-ipfs-core/src/refs.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const loadFixture = require('aegir/fixtures')
66
const CID = require('cids')
77
const all = require('it-all')
88

9+
const dagPB = require('ipld-dag-pb')
10+
const DAGNode = dagPB.DAGNode
11+
const DAGLink = dagPB.DAGLink
12+
13+
const UnixFS = require('ipfs-unixfs')
14+
915
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1016
/**
1117
* @param {Factory} common
@@ -307,21 +313,27 @@ function getRefsTests () {
307313

308314
function loadPbContent (ipfs, node) {
309315
const store = {
310-
putData: (data) => ipfs.object.put({ Data: data, Links: [] }),
311-
putLinks: (links) =>
312-
ipfs.object.put({
313-
Data: '',
314-
Links: links.map(({ name, cid }) => ({ Name: name, Hash: cid, Size: 8 }))
315-
})
316+
putData: async (data) => {
317+
const res = await ipfs.block.put(new DAGNode(data).serialize())
318+
return res.cid
319+
},
320+
putLinks: async (links) => {
321+
const res = await ipfs.block.put(new DAGNode('', links.map(({ name, cid }) => {
322+
return new DAGLink(name, 8, cid)
323+
})).serialize())
324+
return res.cid
325+
}
316326
}
317327
return loadContent(ipfs, store, node)
318328
}
319329

320330
function loadDagContent (ipfs, node) {
321331
const store = {
322332
putData: async (data) => {
323-
const res = await all(ipfs.add(data))
324-
return res[0].cid
333+
const inner = new UnixFS({ type: 'file', data: data })
334+
const serialized = new DAGNode(inner.marshal()).serialize()
335+
const res = await ipfs.block.put(serialized)
336+
return res.cid
325337
},
326338
putLinks: (links) => {
327339
const obj = {}

0 commit comments

Comments
 (0)