fix: replace node buffers with uint8arrays (#730)

* fix: replace node buffers with uint8arrays

Upgrades all deps and replaces all use of node Buffers with Uint8Arrays

BREAKING CHANGES:

- All deps used by this module now use Uint8Arrays in place of node Buffers

* chore: browser fixes

* chore: remove .only

* chore: stringify uint8array before parsing

* chore: update interop suite

* chore: remove ts from build command

* chore: update deps

* fix: update records to use uint8array

* chore: fix lint

* chore: update deps

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Alex Potsides
2020-08-24 11:58:02 +01:00
committed by Jacob Heun
parent 9107efe121
commit 1e869717ff
46 changed files with 283 additions and 270 deletions

View File

@ -10,6 +10,7 @@ const pWaitFor = require('p-wait-for')
const pDefer = require('p-defer')
const mergeOptions = require('merge-options')
const multiaddr = require('multiaddr')
const uint8ArrayToString = require('uint8arrays/to-string')
const { create } = require('../../src')
const { subsystemOptions, subsystemMulticodecs } = require('./utils')
@ -82,7 +83,7 @@ describe('Pubsub subsystem operates correctly', () => {
expect(subscribedTopics).to.not.include(topic)
libp2p.pubsub.subscribe(topic, (msg) => {
expect(msg.data.toString()).to.equal(data)
expect(uint8ArrayToString(msg.data)).to.equal(data)
defer.resolve()
})
@ -171,7 +172,7 @@ describe('Pubsub subsystem operates correctly', () => {
expect(subscribedTopics).to.not.include(topic)
libp2p.pubsub.subscribe(topic, (msg) => {
expect(msg.data.toString()).to.equal(data)
expect(uint8ArrayToString(msg.data)).to.equal(data)
defer.resolve()
})
@ -242,7 +243,7 @@ describe('Pubsub subsystem operates correctly', () => {
const defer1 = pDefer()
const defer2 = pDefer()
const handler = (msg) => {
expect(msg.data.toString()).to.equal(data)
expect(uint8ArrayToString(msg.data)).to.equal(data)
counter++
counter === 1 ? defer1.resolve() : defer2.resolve()
}
@ -307,7 +308,7 @@ describe('Pubsub subsystem operates correctly', () => {
libp2p.pubsub.publish(topic, 'message1')
remoteLibp2p.pubsub.publish(topic, 'message2')
await pWaitFor(() => handlerSpy.callCount === 2)
expect(handlerSpy.args.map(([message]) => message.data.toString())).to.include.members(['message1', 'message2'])
expect(handlerSpy.args.map(([message]) => uint8ArrayToString(message.data))).to.include.members(['message1', 'message2'])
// Disconnect the first connection (this acts as a delayed reconnect)
await originalConnection.close()
@ -317,7 +318,7 @@ describe('Pubsub subsystem operates correctly', () => {
libp2p.pubsub.publish(topic, 'message3')
remoteLibp2p.pubsub.publish(topic, 'message4')
await pWaitFor(() => handlerSpy.callCount === 2)
expect(handlerSpy.args.map(([message]) => message.data.toString())).to.include.members(['message3', 'message4'])
expect(handlerSpy.args.map(([message]) => uint8ArrayToString(message.data))).to.include.members(['message3', 'message4'])
})
})
})