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

Refactor refs tests #2972

Merged
merged 3 commits into from
Apr 9, 2020
Merged
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
28 changes: 20 additions & 8 deletions packages/interface-ipfs-core/src/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const loadFixture = require('aegir/fixtures')
const CID = require('cids')
const all = require('it-all')

const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
const DAGLink = dagPB.DAGLink

const UnixFS = require('ipfs-unixfs')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
Expand Down Expand Up @@ -307,21 +313,27 @@ function getRefsTests () {

function loadPbContent (ipfs, node) {
const store = {
putData: (data) => ipfs.object.put({ Data: data, Links: [] }),
putLinks: (links) =>
ipfs.object.put({
Data: '',
Links: links.map(({ name, cid }) => ({ Name: name, Hash: cid, Size: 8 }))
})
putData: async (data) => {
const res = await ipfs.block.put(new DAGNode(data).serialize())
return res.cid
},
putLinks: async (links) => {
const res = await ipfs.block.put(new DAGNode('', links.map(({ name, cid }) => {
return new DAGLink(name, 8, cid)
})).serialize())
return res.cid
}
}
return loadContent(ipfs, store, node)
}

function loadDagContent (ipfs, node) {
const store = {
putData: async (data) => {
const res = await all(ipfs.add(data))
return res[0].cid
const inner = new UnixFS({ type: 'file', data: data })
const serialized = new DAGNode(inner.marshal()).serialize()
const res = await ipfs.block.put(serialized)
return res.cid
},
putLinks: (links) => {
const obj = {}
Expand Down