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

Commit 168e04a

Browse files
committed
feat(tests): all tests running
1 parent a4071f0 commit 168e04a

File tree

8 files changed

+86
-37
lines changed

8 files changed

+86
-37
lines changed

src/cli/commands/block/stat.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,8 @@ module.exports = {
2828
throw err
2929
}
3030

31-
if (typeof block.Key !== 'string') {
32-
block.Key = bs58.encode(block.Key).toString()
33-
}
34-
35-
Object.keys(block).forEach((key) => {
36-
console.log(`${key}: ${block[key]}`)
37-
})
31+
console.log('Key:', bs58.encode(block.key).toString())
32+
console.log('Size:', block.size)
3833
})
3934
})
4035
}

src/core/ipfs/libp2p.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict'
22

3-
const peerId = require('peer-id')
43
const multiaddr = require('multiaddr')
54
const Libp2pNode = require('libp2p-ipfs').Node
6-
const mafmt = require('mafmt')
75

86
const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR
97

108
module.exports = function libp2p (self) {
11-
// NOTE: TODO CONSIDER/ CONSIDERING putting all of libp2p (start, stop, peerbook and so on) inside the libp2p object and reduce one layer
9+
// NOTE: TODO CONSIDER/CONSIDERING putting all of libp2p (start, stop, peerbook and so on) inside the libp2p object and reduce one layer
1210

1311
return {
1412
start: (callback) => {
@@ -64,22 +62,7 @@ module.exports = function libp2p (self) {
6462
maddr = multiaddr(maddr)
6563
}
6664

67-
if (!mafmt.IPFS.matches(maddr.toString())) {
68-
return callback(new Error('multiaddr not valid'))
69-
}
70-
71-
let ipfsIdB58String
72-
maddr.stringTuples().forEach((tuple) => {
73-
if (tuple[0] === 421) {
74-
ipfsIdB58String = tuple[1]
75-
}
76-
})
77-
78-
const id = peerId.createFromB58String(ipfsIdB58String)
79-
80-
self._libp2pNode.dialByMultiaddr(maddr, (err) => {
81-
callback(err, id)
82-
})
65+
self._libp2pNode.dialByMultiaddr(maddr, callback)
8366
},
8467
disconnect: (maddr, callback) => {
8568
if (!self.isOnline()) {

src/http-api/resources/swarm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ exports.connect = {
7272
handler: (request, reply) => {
7373
const addr = request.pre.args.addr
7474

75-
request.server.app.ipfs.libp2p.swarm.connect(addr, (err, res) => {
75+
request.server.app.ipfs.libp2p.swarm.connect(addr, (err) => {
7676
if (err) {
7777
log.error(err)
7878
return reply({
@@ -82,7 +82,7 @@ exports.connect = {
8282
}
8383

8484
return reply({
85-
Strings: [`connect ${res.toB58String()} success`]
85+
Strings: [`connect ${addr} success`]
8686
})
8787
})
8888
}

test/core/node-only/test-swarm-2.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
/*
6+
const test = require('interface-ipfs-core')
7+
const IPFSFactory = require('../../utils/factory-core')
8+
9+
let factory
10+
11+
const common = {
12+
setup: function (cb) {
13+
factory = new IPFSFactory()
14+
cb(null, factory)
15+
},
16+
teardown: function (cb) {
17+
factory.dismantle(cb)
18+
}
19+
}
20+
*/
21+
// TODO
22+
// Needs: https://github.com/ipfs/js-libp2p-ipfs/pull/16
23+
// test.swarm(common)

test/http-api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('HTTP API', () => {
4747
})
4848
})
4949

50-
describe.only('## interface-ipfs-core tests over ipfs-api', () => {
50+
describe('## interface-ipfs-core tests over ipfs-api', () => {
5151
const tests = fs.readdirSync(path.join(__dirname,
5252
'/interface-ipfs-core-over-ipfs-api'))
5353
tests.filter((file) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
/*
6+
const test = require('interface-ipfs-core')
7+
const FactoryClient = require('./../../utils/factory-http')
8+
9+
let fc
10+
11+
const common = {
12+
setup: function (callback) {
13+
fc = new FactoryClient()
14+
callback(null, fc)
15+
},
16+
teardown: function (callback) {
17+
fc.dismantle(callback)
18+
}
19+
}
20+
*/
21+
22+
// TODO
23+
// needs: https://github.com/ipfs/js-ipfs/pull/323
24+
// test.files(common)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
/*
6+
const test = require('interface-ipfs-core')
7+
const FactoryClient = require('./../../utils/factory-http')
8+
9+
let fc
10+
11+
const common = {
12+
setup: function (callback) {
13+
fc = new FactoryClient()
14+
callback(null, fc)
15+
},
16+
teardown: function (callback) {
17+
fc.dismantle(callback)
18+
}
19+
}
20+
*/
21+
// TODO
22+
// Needs: https://github.com/ipfs/js-libp2p-ipfs/pull/16
23+
// test.swarm(common)

test/http-api/ipfs-api/test-block.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
'use strict'
33

44
const expect = require('chai').expect
5+
const multihash = require('multihashes')
56

67
module.exports = (ctl) => {
78
describe('.block', () => {
89
describe('.put', () => {
910
it('updates value', (done) => {
10-
const filePath = 'test/test-data/hello'
11+
const data = new Buffer('hello world\n')
1112
const expectedResult = {
12-
Key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
13-
Size: 12
13+
key: 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
14+
size: 12
1415
}
1516

16-
ctl.block.put(filePath, (err, res) => {
17+
ctl.block.put(data, (err, block) => {
1718
expect(err).not.to.exist
18-
expect(res).to.deep.equal(expectedResult)
19+
expect(block.key).to.deep.equal(multihash.fromB58String(expectedResult.key))
1920
done()
2021
})
2122
})
@@ -39,7 +40,7 @@ module.exports = (ctl) => {
3940
it('returns value', (done) => {
4041
ctl.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => {
4142
expect(err).to.not.exist
42-
expect(result.toString())
43+
expect(result.data.toString())
4344
.to.equal('hello world\n')
4445
done()
4546
})
@@ -64,9 +65,9 @@ module.exports = (ctl) => {
6465
it('returns value', (done) => {
6566
ctl.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => {
6667
expect(err).to.not.exist
67-
expect(result.Key)
68+
expect(result.key)
6869
.to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
69-
expect(result.Size).to.equal(12)
70+
expect(result.size).to.equal(12)
7071
done()
7172
})
7273
})

0 commit comments

Comments
 (0)