Compare commits

...

3 Commits

Author SHA1 Message Date
83d7d52d7e chore: release version v0.7.2 2020-11-11 17:20:34 +01:00
1a3ea82776 chore: update contributors 2020-11-11 17:20:34 +01:00
ad2dfa42dc chore: pubsub conformance test updates (#70) 2020-11-11 17:16:49 +01:00
6 changed files with 21 additions and 30 deletions

View File

@ -1,3 +1,8 @@
<a name="0.7.2"></a>
## [0.7.2](https://github.com/libp2p/js-interfaces/compare/v0.7.1...v0.7.2) (2020-11-11)
<a name="0.7.1"></a> <a name="0.7.1"></a>
## [0.7.1](https://github.com/libp2p/js-interfaces/compare/v0.7.0...v0.7.1) (2020-11-03) ## [0.7.1](https://github.com/libp2p/js-interfaces/compare/v0.7.0...v0.7.1) (2020-11-03)

View File

@ -1,6 +1,6 @@
{ {
"name": "libp2p-interfaces", "name": "libp2p-interfaces",
"version": "0.7.1", "version": "0.7.2",
"description": "Interfaces for JS Libp2p", "description": "Interfaces for JS Libp2p",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>", "leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js", "main": "src/index.js",

View File

@ -76,7 +76,7 @@ module.exports = (common) => {
const defer = pDefer() const defer = pDefer()
const handler = (msg) => { const handler = (msg) => {
expect(msg).to.exist() expect(msg).to.not.eql(undefined)
defer.resolve() defer.resolve()
} }

View File

@ -10,6 +10,7 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
const { utils } = require('..') const { utils } = require('..')
const PeerStreams = require('../peer-streams') const PeerStreams = require('../peer-streams')
const { SignaturePolicy } = require('../signature-policy')
const topic = 'foo' const topic = 'foo'
const data = uint8ArrayFromString('bar') const data = uint8ArrayFromString('bar')
@ -31,24 +32,17 @@ module.exports = (common) => {
}) })
it('should emit normalized signed messages on publish', async () => { it('should emit normalized signed messages on publish', async () => {
pubsub.globalSignaturePolicy = SignaturePolicy.StrictSign
sinon.spy(pubsub, '_emitMessage') sinon.spy(pubsub, '_emitMessage')
sinon.spy(utils, 'randomSeqno')
await pubsub.publish(topic, data) await pubsub.publish(topic, data)
expect(pubsub._emitMessage.callCount).to.eql(1) expect(pubsub._emitMessage.callCount).to.eql(1)
const [messageToEmit] = pubsub._emitMessage.getCall(0).args const [messageToEmit] = pubsub._emitMessage.getCall(0).args
const expected = utils.normalizeInRpcMessage( expect(messageToEmit.seqno).to.not.eql(undefined)
await pubsub._buildMessage({ expect(messageToEmit.key).to.not.eql(undefined)
receivedFrom: pubsub.peerId.toB58String(), expect(messageToEmit.signature).to.not.eql(undefined)
from: pubsub.peerId.toB58String(),
data,
seqno: utils.randomSeqno.getCall(0).returnValue,
topicIDs: [topic]
}))
expect(messageToEmit).to.eql(expected)
}) })
it('should drop unsigned messages', async () => { it('should drop unsigned messages', async () => {
@ -83,18 +77,16 @@ module.exports = (common) => {
}) })
it('should not drop unsigned messages if strict signing is disabled', async () => { it('should not drop unsigned messages if strict signing is disabled', async () => {
pubsub.globalSignaturePolicy = SignaturePolicy.StrictNoSign
sinon.spy(pubsub, '_emitMessage') sinon.spy(pubsub, '_emitMessage')
sinon.spy(pubsub, '_publish') sinon.spy(pubsub, '_publish')
sinon.spy(pubsub, 'validate') sinon.spy(pubsub, 'validate')
sinon.stub(pubsub, 'strictSigning').value(false)
const peerStream = new PeerStreams({ id: await PeerId.create() }) const peerStream = new PeerStreams({ id: await PeerId.create() })
const rpc = { const rpc = {
subscriptions: [], subscriptions: [],
msgs: [{ msgs: [{
from: peerStream.id.toBytes(),
data, data,
seqno: utils.randomSeqno(),
topicIDs: [topic] topicIDs: [topic]
}] }]
} }

View File

@ -52,26 +52,20 @@ module.exports = (common) => {
await common.teardown() await common.teardown()
}) })
it('subscribe to the topic on node a', () => { it('subscribe to the topic on node a', async () => {
const topic = 'Z' const topic = 'Z'
const defer = pDefer()
psA.subscribe(topic) psA.subscribe(topic)
expectSet(psA.subscriptions, [topic]) expectSet(psA.subscriptions, [topic])
psB.once('pubsub:subscription-change', () => { await new Promise((resolve) => psB.once('pubsub:subscription-change', resolve))
expect(psB.peers.size).to.equal(2) expect(psB.peers.size).to.equal(2)
const aPeerId = psA.peerId.toB58String() const aPeerId = psA.peerId.toB58String()
expectSet(psB.topics.get(topic), [aPeerId]) expectSet(psB.topics.get(topic), [aPeerId])
expect(psC.peers.size).to.equal(1) expect(psC.peers.size).to.equal(1)
expect(psC.topics.get(topic)).to.not.exist() expect(psC.topics.get(topic)).to.eql(undefined)
defer.resolve()
})
return defer.promise
}) })
it('subscribe to the topic on node b', async () => { it('subscribe to the topic on node b', async () => {

View File

@ -40,7 +40,7 @@ exports.msgId = (from, seqno) => {
* @returns {Uint8Array} * @returns {Uint8Array}
* @private * @private
*/ */
exports.noSignMsgId = (data) => multihash.encode(data, 'sha2') exports.noSignMsgId = (data) => multihash.encode(data, 'sha2-256')
/** /**
* Check if any member of the first set is also a member * Check if any member of the first set is also a member