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

Commit 736b699

Browse files
committed
test: reworking tests with daemon factory
fix: mafmt now accepts /ipfs for most addrs
1 parent 8a7ec3e commit 736b699

File tree

4 files changed

+135
-119
lines changed

4 files changed

+135
-119
lines changed

src/core/components/libp2p.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ module.exports = function libp2p (self) {
2222
dht: get(self._options, 'EXPERIMENTAL.dht'),
2323
modules: self._libp2pModules,
2424
relay: {
25-
circuit: {
26-
enabled: get(config, 'Experimental.Relay.Circuit.Enabled'),
27-
active: get(config, 'Experimental.Relay.Circuit.Active')
25+
enabled: get(config, 'EXPERIMENTAL.Relay.Enabled', false),
26+
hop: {
27+
enabled: get(config, 'EXPERIMENTAL.Relay.HOP.Enabled', false),
28+
active: get(config, 'EXPERIMENTAL.Relay.HOP.Active', false)
2829
}
2930
}
3031
}

src/core/components/pre-start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function preStart (self) {
2626
config.Addresses.Swarm.forEach((addr) => {
2727
let ma = multiaddr(addr)
2828

29-
if (!mafmt.IPFS.matches(ma)) {
29+
if (mafmt.IPFS.matches(ma) && !ma.protoNames().indexOf('ipfs') > -1) {
3030
ma = ma.encapsulate('/ipfs/' + self._peerInfo.id.toB58String())
3131
}
3232

test/core/circuit.spec.js

Lines changed: 129 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -7,143 +7,158 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
const waterfall = require('async/waterfall')
99
const parallel = require('async/parallel')
10-
const isNode = require('detect-node')
1110

11+
const PeerId = require('peer-id')
1212
const IPFS = require('../../src/core')
13-
const createTempRepo = require('../utils/create-repo-node.js')
13+
const createTempRepo = require('../utils/create-repo-nodejs.js')
14+
const Factory = require('../utils/ipfs-factory-daemon')
15+
const relayConfig = require('../utils/ipfs-factory-daemon/default-config.json')
1416

1517
chai.use(dirtyChai)
1618

17-
describe('circuit', () => {
18-
if (!isNode) {
19-
return
20-
}
21-
22-
describe('transfer over circuit', function () {
23-
this.timeout(50000)
24-
25-
let ipfsRelay
26-
let ipfsDst
27-
let ipfsSrc
28-
29-
before((done) => {
30-
ipfsRelay = new IPFS({
31-
repo: createTempRepo(),
32-
config: {
33-
Addresses: {
34-
Swarm: [
35-
'/ip4/0.0.0.0/tcp/9000',
36-
'/ip4/0.0.0.0/tcp/9001/ws'
37-
]
38-
},
39-
Bootstrap: [],
40-
Experimental: {
41-
Relay: {
42-
Circuit: {
43-
Enabled: true,
44-
Active: false
45-
}
46-
}
47-
},
48-
Identity: {
49-
PeerID: 'QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV',
50-
PrivKey: 'CAASpgkwggSiAgEAAoIBAQC3ty1UbNy/0jjuJY24/1FvwnGLF6CML++iBQ6LTQdDv6u7mOFX9kzkHxI8JxQrOTLByWkXkJQ+zGKJDaLFpzmwZdWPglpWHS5LeiH7pggUPxPhZ7DkS4p9nWJbQh6h8gZ39zdpEBXWjbsqCYmgjGL0EG5pzN+dLgKnBBBTiEqv8hK9aN5uRvsFxUyhN6J9LJzgh2aGblUG/0rir2Nge1xeFj9sLeHpgPI6wCyqys+nRFJXvGNZ8Auu2K6cjHVkkPK3BPtf7CxziJCaJYE5GXQ3AT5Wl/AJ55I1mA9M/UM9qFL4ih4iNVWGbktOz/lDmrI12CRaCdemTPWIy+7mZj33AgMBAAECggEASiMaoNo5jxM3tCrlcUVfSLlv9pB3Uns5uelOgDp6dwWPOOot7cBQMTK0uh+PDQ5NBFTSGxdWK61xChu9lwOvzRabQwl4iQ3Hk9/afOH4mqsFy817XfV6Es0DVw5srC+uGpVh//zkwyt43zLwHiDpAdLrq7hoeNaLbXi/WeZDNZLMfleIo/TO6RCh7waai4reAgGgJnF46yhoIjrpturqjyVo9sS17hx/3WXlffOqfepx9grKK8u/8GzdlgtwwtygMf6pw/9VUHY9T2kXtls0w1VoNhNK52MGCN8uX4yJlofQXNB4/F9XuuqugCcpYUUnvHOVWFcRyS+ZceynKL3/kQKBgQDhywvRnW1rvYOnrr4UvQegi3T3Na6JWOFYv/7KdJNHTKUr0FSPaD+DVN62zxYVU9jw6fRVVHsyDO/Fbw+cb8ezd+r94l32er4hK6FrPpuwr2Af/HifoLB6rKT1lvJJKT4itnPFNxLzVYON5oMZp+u3UeTcb8ob6UZKtgAgrDBHPwKBgQDQSw8DHyUXi43rsKNCF6K4Wk14U5u+qhs+DColdpd79BVXNdjU35Ifq5nwGGzo2cjUd8EGdK1pURh3oCTXWK/bRyCdC3qWRJFsgIugC8BDLlKNc45IZjcWfZVg/FGR4usdLF4YcXnoIIjsDkDCSzD6laDjk1wQkbIgxo9a1NfTSQKBgH6Q0o8tL6i1Epdr3CDD1QKpKWdpL+zNZYPaG3hg4C2XSP7GSKAaT3/OkwjmC/rohTKF8e/i6yujFMQW/Skzfz2aep7VxNXk966gRltXPO5NYBSN8Q+Jg2NAYzdG5YkdFTdgDoT92iGMTbG9BL/c4MRho2ftQd1jZYN7gZbO7kEBAoGARh5eaWCcrfZuyj7mVqN6RbEwjycmMOM21IZn0cDAchvS607XNaIloL+1zJuMXj6iWtQNiMzSa7e/EtY4UL4sRRcGpZdtpxRiGDKVzkTmbjcz1yZlaX3vYYTZOpL2KrRHDcUX0AazUS9SqJSLvFxvmouwY6wBvBov6tStAZjRJvECgYA5XjWN7tHRwEr+NoAGsSmtsqGCrHrCPdj8SOyKTXRARQKRdvJ0KBJkMmzLdmLVErYjuy9OmwdigWcTZjZ2HhrhXNR95Xepg3I5ylzuouMPZepAacjtGl4oi91rdv6z9hD4/cSB+wIfXG9o0ghgJ/vexzvxFzDnvY+8MqEa2PP6NA=='
19+
describe('circuit', function () {
20+
this.timeout(20 * 1000)
21+
22+
let ipfsDst
23+
let ipfsSrc
24+
let relayPeer
25+
let relayAddrs
26+
let factory = new Factory()
27+
28+
before((done) => {
29+
ipfsDst = new IPFS({
30+
repo: createTempRepo(),
31+
start: false,
32+
config: {
33+
Addresses: {
34+
Swarm: [
35+
'/ip4/0.0.0.0/tcp/9002'
36+
]
37+
},
38+
Bootstrap: [],
39+
EXPERIMENTAL: {
40+
Relay: {
41+
Enabled: true
5142
}
5243
}
53-
})
44+
}
45+
})
5446

55-
ipfsDst = new IPFS({
56-
repo: createTempRepo(),
57-
config: {
58-
Addresses: {
59-
Swarm: [
60-
'/ip4/0.0.0.0/tcp/9002'
61-
]
62-
},
63-
Bootstrap: []
47+
ipfsSrc = new IPFS({
48+
repo: createTempRepo(),
49+
start: false,
50+
config: {
51+
Addresses: {
52+
Swarm: [
53+
'/ip4/0.0.0.0/tcp/9003/ws'
54+
]
55+
},
56+
Bootstrap: [],
57+
EXPERIMENTAL: {
58+
Relay: {
59+
Enabled: true
60+
}
6461
}
65-
})
62+
}
63+
})
6664

67-
ipfsSrc = new IPFS({
68-
repo: createTempRepo(),
69-
config: {
70-
Addresses: {
71-
Swarm: [
72-
'/ip4/0.0.0.0/tcp/9003/ws'
73-
]
74-
},
75-
Bootstrap: []
76-
}
77-
})
65+
waterfall([
66+
(pCb) => {
67+
PeerId.create({ bits: 1024 }, (err, id) => {
68+
if (err) {
69+
return pCb(err)
70+
}
7871

72+
const peerId = id.toJSON()
73+
relayConfig.Identity.PeerID = peerId.id
74+
relayConfig.Identity.PrivKey = peerId.privKey
75+
relayConfig.Addresses.Swarm = [
76+
'/ip4/127.0.0.1/tcp/61452/ws',
77+
'/ip4/127.0.0.1/tcp/61453'
78+
]
79+
pCb()
80+
})
81+
},
82+
(pCb) => {
83+
factory.spawnNode(createTempRepo(), Object.assign(relayConfig, {
84+
EXPERIMENTAL: {
85+
Relay: {
86+
Enabled: true,
87+
HOP: {
88+
Enabled: true,
89+
Active: false
90+
}
91+
}
92+
}
93+
}), (err, node) => {
94+
expect(err).to.not.exist()
95+
relayPeer = node
96+
pCb()
97+
})
98+
},
99+
(pCb) => {
100+
relayPeer.swarm.localAddrs((err, addrs) => {
101+
expect(err).to.not.exist()
102+
relayAddrs = addrs
103+
pCb()
104+
})
105+
},
106+
(pCb) => ipfsSrc.start(pCb),
107+
(pCb) => ipfsDst.start(pCb)
108+
], (err) => {
109+
expect(err).to.not.exist()
110+
let addr = relayAddrs.filter((a) => !a.toString().includes('/p2p-circuit'))
79111
parallel([
80-
(pCb) => ipfsRelay.once('start', pCb),
81-
(pCb) => ipfsSrc.once('start', pCb),
82-
(pCb) => ipfsDst.once('start', pCb)
83-
], () => {
84-
waterfall([
85-
(cb) => ipfsSrc
86-
.swarm
87-
.connect(`/ip4/0.0.0.0/tcp/9001/ws/ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV`, () => cb()),
88-
(cb) => setTimeout(cb, 1000),
89-
(cb) => ipfsDst
90-
.swarm
91-
.connect(`/ip4/0.0.0.0/tcp/9000/ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV`, () => cb()),
92-
(cb) => setTimeout(cb, 1000),
93-
(cb) => ipfsSrc.id(cb),
94-
(id, cb) => ipfsRelay.swarm.connect(`/ip4/0.0.0.0/tcp/9002/ipfs/${id.id}`, () => cb()),
95-
(cb) => setTimeout(cb, 1000),
96-
(cb) => ipfsDst.id(cb),
97-
(id, cb) => ipfsRelay.swarm.connect(`/ip4/0.0.0.0/tcp/9003/ws/ipfs/${id.id}`, () => cb())
98-
], done)
112+
(cb) => ipfsSrc.swarm.connect(addr[0], cb),
113+
(cb) => ipfsDst.swarm.connect(addr[1], cb)
114+
], (err) => {
115+
setTimeout(() => done(err), 2000)
99116
})
100117
})
118+
})
101119

102-
after((done) => {
103-
waterfall([
104-
(cb) => ipfsRelay.stop(() => cb()),
105-
(cb) => ipfsSrc.stop(() => cb()),
106-
(cb) => ipfsDst.stop(() => cb())
107-
], done)
108-
})
120+
after((done) => {
121+
waterfall([
122+
(cb) => ipfsSrc.stop(() => cb()),
123+
(cb) => ipfsDst.stop(() => cb()),
124+
(cb) => factory.dismantle((err) => done(err))
125+
], done)
126+
})
109127

110-
it('should be able to connect over circuit', (done) => {
111-
ipfsSrc.swarm.connect(ipfsDst._peerInfo, (err, conn) => {
112-
expect(err).to.be.null()
113-
expect(conn).to.not.be.null()
114-
done()
115-
})
128+
it('should be able to connect over circuit', (done) => {
129+
ipfsSrc.swarm.connect(ipfsDst._peerInfo, (err, conn) => {
130+
expect(err).to.not.exist()
131+
done()
116132
})
133+
})
117134

118-
it('should be able to transfer data over circuit', (done) => {
119-
waterfall([
120-
// dial destination over WS /ip4/0.0.0.0/tcp/9002/ws
121-
(cb) => ipfsSrc.swarm.connect(ipfsDst._peerInfo, cb),
122-
(conn, cb) => ipfsDst.files.add(new ipfsDst.types.Buffer('Hello world over circuit!'),
123-
(err, res) => {
124-
expect(err).to.be.null()
125-
expect(res[0]).to.not.be.null()
126-
cb(null, res[0].hash)
127-
}),
128-
(fileHash, cb) => ipfsSrc.files.cat(fileHash, function (err, stream) {
135+
it('should be able to transfer data over circuit', (done) => {
136+
waterfall([
137+
(cb) => ipfsDst.swarm.connect(ipfsSrc._peerInfo, cb),
138+
(conn, cb) => ipfsDst.files.add(new ipfsDst.types.Buffer('Hello world over circuit!'),
139+
(err, res) => {
129140
expect(err).to.be.null()
141+
expect(res[0]).to.not.be.null()
142+
cb(null, res[0].hash)
143+
}),
144+
(hash, cb) => ipfsSrc.files.cat(hash, function (err, stream) {
145+
expect(err).to.be.null()
130146

131-
var res = ''
147+
var res = ''
132148

133-
stream.on('data', function (chunk) {
134-
res += chunk.toString()
135-
})
149+
stream.on('data', function (chunk) {
150+
res += chunk.toString()
151+
})
136152

137-
stream.on('error', function (err) {
138-
cb(err)
139-
})
153+
stream.on('error', function (err) {
154+
cb(err)
155+
})
140156

141-
stream.on('end', function () {
142-
expect(res).to.be.equal('Hello world over circuit!')
143-
cb(null, res)
144-
})
157+
stream.on('end', function () {
158+
expect(res).to.be.equal('Hello world over circuit!')
159+
cb(null, res)
145160
})
146-
], done)
147-
})
161+
})
162+
], done)
148163
})
149164
})

test/interop/daemons/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class JsDaemon extends EventEmitter {
5252
throw err
5353
}
5454
this._started = true
55-
this.api = new IPFSAPI(this.node.apiMultiaddr)
55+
this.api = new IPFSAPI(this.node.apiMultiaddr, opts.config)
5656

5757
this.emit('start')
5858
})

0 commit comments

Comments
 (0)