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

Commit 83fee00

Browse files
committed
fix: code review for tests
1 parent e4ba943 commit 83fee00

File tree

2 files changed

+86
-96
lines changed

2 files changed

+86
-96
lines changed

src/core/ipns/publisher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class IpnsPublisher {
6767

6868
let keys
6969
try {
70-
keys = ipns.getIdKeys(peerId.id)
70+
keys = ipns.getIdKeys(peerId.toBytes())
7171
} catch (err) {
7272
log.error(err)
7373
return callback(err)

test/cli/name-pubsub.js

+85-95
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,21 @@ describe('name-pubsub', () => {
8383

8484
// Connect
8585
before(function () {
86-
return ipfsA('swarm', 'connect', bMultiaddr).then((out) => {
87-
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
88-
})
86+
return ipfsA('swarm', 'connect', bMultiaddr)
87+
.then((out) => {
88+
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
89+
})
8990
})
9091

9192
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
9293

9394
describe('pubsub commands', () => {
94-
before(function (done) {
95-
this.timeout(50 * 1000)
96-
done()
97-
})
98-
9995
it('should get enabled state of pubsub', function () {
100-
return ipfsA('name pubsub state').then((res) => {
101-
expect(res).to.exist()
102-
expect(res).to.have.string('enabled') // enabled
103-
})
96+
return ipfsA('name pubsub state')
97+
.then((res) => {
98+
expect(res).to.exist()
99+
expect(res).to.have.string('enabled') // enabled
100+
})
104101
})
105102

106103
it('should subscribe on name resolve', function () {
@@ -110,19 +107,17 @@ describe('name-pubsub', () => {
110107
.catch((err) => {
111108
expect(err).to.exist() // Not available (subscribed)
112109

113-
return Promise.all([
114-
ipfsB('pubsub ls'),
115-
ipfsB('name pubsub subs')
116-
])
117-
.then((res) => {
118-
expect(res).to.exist()
119-
120-
expect(res[0]).to.exist()
121-
expect(res[0]).to.have.string('/ipns/') // have an ipns subscribtion
110+
return ipfsB('pubsub ls')
111+
})
112+
.then((res) => {
113+
expect(res).to.exist()
114+
expect(res).to.have.string('/ipns/') // have an ipns subscribtion
122115

123-
expect(res[1]).to.exist()
124-
expect(res[1]).to.have.string(`/ipns/${nodeAId.id}`) // have subscription
125-
})
116+
return ipfsB('name pubsub subs')
117+
})
118+
.then((res) => {
119+
expect(res).to.exist()
120+
expect(res).to.have.string(`/ipns/${nodeAId.id}`) // have subscription
126121
})
127122
})
128123

@@ -135,29 +130,27 @@ describe('name-pubsub', () => {
135130
expect(res).to.have.string('no subscription') // tried to cancel a not yet subscribed id
136131

137132
return ipfsA(`name resolve ${nodeBId.id}`)
138-
.catch((err) => {
139-
expect(err).to.exist() // Not available (subscribed now)
140-
141-
return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`)
142-
.then((res) => {
143-
expect(res).to.exist()
144-
expect(res).to.have.string('canceled') // canceled now
145-
146-
return Promise.all([
147-
ipfsA('pubsub ls'),
148-
ipfsA('name pubsub subs')
149-
])
150-
.then((res) => {
151-
expect(res).to.exist()
152-
153-
expect(res[0]).to.exist()
154-
expect(res[0]).to.not.have.string('/ipns/') // ipns subscribtion not available
155-
156-
expect(res[1]).to.exist()
157-
expect(res[1]).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available
158-
})
159-
})
160-
})
133+
})
134+
.catch((err) => {
135+
expect(err).to.exist() // Not available (subscribed now)
136+
137+
return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`)
138+
})
139+
.then((res) => {
140+
expect(res).to.exist()
141+
expect(res).to.have.string('canceled') // canceled now
142+
143+
return ipfsA('pubsub ls')
144+
})
145+
.then((res) => {
146+
expect(res).to.exist()
147+
expect(res).to.not.have.string('/ipns/') // ipns subscribtion not available
148+
149+
return ipfsA('name pubsub subs')
150+
})
151+
.then((res) => {
152+
expect(res).to.exist()
153+
expect(res).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available
161154
})
162155
})
163156
})
@@ -167,10 +160,11 @@ describe('name-pubsub', () => {
167160

168161
before(function (done) {
169162
this.timeout(50 * 1000)
170-
ipfsA('add src/init-files/init-docs/readme').then((out) => {
171-
cidAdded = out.split(' ')[1]
172-
done()
173-
})
163+
ipfsA('add src/init-files/init-docs/readme')
164+
.then((out) => {
165+
cidAdded = out.split(' ')[1]
166+
done()
167+
})
174168
})
175169

176170
it('should publish the received record to the subscriber', function () {
@@ -182,30 +176,28 @@ describe('name-pubsub', () => {
182176
expect(res).to.satisfy(checkAll([emptyDirCid])) // Empty dir received (subscribed)
183177

184178
return ipfsA(`name resolve ${nodeBId.id}`)
185-
.catch((err) => {
186-
expect(err).to.exist() // Not available (subscribed now)
187-
188-
return ipfsB(`name publish ${cidAdded}`)
189-
.then((res) => {
190-
// published to IpfsB and published through pubsub to ipfsa
191-
expect(res).to.exist()
192-
expect(res).to.satisfy(checkAll([cidAdded, nodeBId.id]))
193-
194-
return Promise.all([
195-
ipfsB(`name resolve ${nodeBId.id}`),
196-
ipfsA(`name resolve ${nodeBId.id}`)
197-
])
198-
.then((res) => {
199-
expect(res).to.exist()
200-
201-
expect(res[0]).to.exist()
202-
expect(res[0]).to.satisfy(checkAll([cidAdded]))
203-
204-
expect(res[1]).to.exist()
205-
expect(res[1]).to.satisfy(checkAll([cidAdded])) // value propagated to node B
206-
})
207-
})
208-
})
179+
})
180+
.catch((err) => {
181+
expect(err).to.exist() // Not available (subscribed now)
182+
183+
return ipfsB(`name publish ${cidAdded}`)
184+
})
185+
.then((res) => {
186+
// published to IpfsB and published through pubsub to ipfsa
187+
expect(res).to.exist()
188+
expect(res).to.satisfy(checkAll([cidAdded, nodeBId.id]))
189+
190+
return ipfsB(`name resolve ${nodeBId.id}`)
191+
})
192+
.then((res) => {
193+
expect(res).to.exist()
194+
expect(res).to.satisfy(checkAll([cidAdded]))
195+
196+
return ipfsA(`name resolve ${nodeBId.id}`)
197+
})
198+
.then((res) => {
199+
expect(res).to.exist()
200+
expect(res).to.satisfy(checkAll([cidAdded])) // value propagated to node B
209201
})
210202
})
211203
})
@@ -235,30 +227,28 @@ describe('name-pubsub', () => {
235227

236228
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
237229

238-
it('should get disabled state of pubsub', function (done) {
239-
ipfsA('name pubsub state').then((res) => {
240-
expect(res).to.exist()
241-
expect(res).to.have.string('disabled')
242-
243-
done()
244-
})
230+
it('should get disabled state of pubsub', function () {
231+
return ipfsA('name pubsub state')
232+
.then((res) => {
233+
expect(res).to.exist()
234+
expect(res).to.have.string('disabled')
235+
})
245236
})
246237

247-
it('should get error getting the available subscriptions', function (done) {
248-
ipfsA('name pubsub subs').catch((err) => {
249-
expect(err).to.exist() // error as it is disabled
250-
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
251-
done()
252-
})
238+
it('should get error getting the available subscriptions', function () {
239+
return ipfsA('name pubsub subs')
240+
.catch((err) => {
241+
expect(err).to.exist() // error as it is disabled
242+
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
243+
})
253244
})
254245

255-
it('should get error canceling a subscription', function (done) {
256-
ipfsA('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v').catch((err) => {
257-
expect(err).to.exist() // error as it is disabled
258-
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
259-
260-
done()
261-
})
246+
it('should get error canceling a subscription', function () {
247+
return ipfsA('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v')
248+
.catch((err) => {
249+
expect(err).to.exist() // error as it is disabled
250+
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
251+
})
262252
})
263253
})
264254
})

0 commit comments

Comments
 (0)