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

Commit eea470b

Browse files
committed
tests: get interface-ipfs-core tests in
1 parent 42bf18d commit eea470b

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@
8888
"ipfs-repo": "^0.11.1",
8989
"ipfs-unixfs": "^0.1.8",
9090
"ipfs-unixfs-engine": "^0.14.0",
91+
"ipld-dag-cbor": "^0.8.2",
92+
"ipld-dag-pb": "^0.9.3",
9193
"ipld-resolver": "^0.3.0",
9294
"isstream": "^0.1.2",
9395
"joi": "^10.0.1",
94-
"libp2p-ipfs-nodejs": "^0.16.0",
9596
"libp2p-ipfs-browser": "^0.17.0",
97+
"libp2p-ipfs-nodejs": "^0.16.0",
9698
"lodash.flatmap": "^4.5.0",
9799
"lodash.get": "^4.4.2",
98100
"lodash.has": "^4.5.2",
@@ -149,4 +151,4 @@
149151
"nginnever <[email protected]>",
150152
"npmcdn-to-unpkg-bot <[email protected]>"
151153
]
152-
}
154+
}

src/core/components/dag.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
// const dagPB = require('ipld-dag-pb')
5-
// const dagCBOR = require('ipld-dag-cbor')
6-
7-
// const CID = require('cids')
8-
// const mh = require('multihashes')
4+
const dagPB = require('ipld-dag-pb')
5+
const dagCBOR = require('ipld-dag-cbor')
96

107
module.exports = function dag (self) {
118
return {
129
put: promisify((dagNode, multicodec, hashAlg, callback) => {
13-
// TODO
14-
// serialize
15-
// get right hash
16-
// generate cid
17-
// put in IPLD Resolver
18-
19-
/*
20-
self._ipldResolver.put({
21-
node: node,
22-
cid: new CID(node.multihash)
23-
}
24-
*/
2510
switch (multicodec) {
26-
case 'dag-pb': {} break
27-
case 'dag-cbor': {} break
28-
default:
29-
callback(new Error('IPLD Format not supported'))
11+
case 'dag-pb': dagPB.util.cid(dagNode, gotCid); break
12+
case 'dag-cbor': dagCBOR.util.cid(dagNode, gotCid); break
13+
default: callback(new Error('IPLD Format not supported'))
14+
}
15+
16+
function gotCid (err, cid) {
17+
if (err) {
18+
return callback(err)
19+
}
20+
self._ipldResolver.put({
21+
node: dagNode,
22+
cid: cid
23+
}, callback)
3024
}
3125
}),
3226
get: promisify((cid, callback) => {
33-
self.ipldResolver.get(cid, callback)
27+
self._ipldResolver.get(cid, callback)
3428
}),
3529
rm: promisify((cid, callback) => {
3630
// TODO once pinning is complete, this remove operation has to first
3731
// verify that some pinning chain is not broken with the operation
38-
self.ipldResolver.remove(cid, callback)
32+
self._ipldResolver.remove(cid, callback)
3933
}),
4034
resolve: promisify((cid, path, callback) => {
41-
self.ipldResolver.resolve(cid, path, callback)
35+
self._ipldResolver.resolve(cid, path, callback)
4236
})
4337
}
4438
}

src/core/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const bootstrap = require('./components/bootstrap')
1818
const config = require('./components/config')
1919
const block = require('./components/block')
2020
const object = require('./components/object')
21+
const dag = require('./components/dag')
2122
const libp2p = require('./components/libp2p')
2223
const swarm = require('./components/swarm')
2324
const ping = require('./components/ping')
@@ -62,6 +63,7 @@ function IPFS (repoInstance) {
6263
this.config = config(this)
6364
this.block = block(this)
6465
this.object = object(this)
66+
this.dag = dag(this)
6567
this.libp2p = libp2p(this)
6668
this.swarm = swarm(this)
6769
this.files = files(this)

test/core/both/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
'use strict'
33

44
describe('--both', () => {
5-
require('./test-bitswap')
65
require('./test-block')
76
require('./test-bootstrap')
87
require('./test-config')
98
require('./test-files')
109
require('./test-generic')
1110
require('./test-init')
1211
require('./test-object')
12+
require('./test-dag')
13+
require('./test-bitswap')
1314
})

0 commit comments

Comments
 (0)