mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 17:52:21 +00:00
chore: pubsub conformance test updates (#70)
This commit is contained in:
parent
b75f2cab48
commit
ad2dfa42dc
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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]
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -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 () => {
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user