11/* eslint-env mocha */
22'use strict'
33
4- const { Buffer } = require ( 'buffer' )
54const chai = require ( 'chai' )
65chai . use ( require ( 'dirty-chai' ) )
6+
77const delay = require ( 'delay' )
8+ const uint8ArrayFromString = require ( 'uint8arrays/from-string' )
89
910const expect = chai . expect
1011const times = require ( 'lodash/times' )
1112const PeerId = require ( 'peer-id' )
1213
13- const { multicodec : floodsubMulticodec } = require ( 'libp2p-floodsub' )
14-
1514const Gossipsub = require ( '../src' )
1615const {
1716 createPeer,
@@ -176,7 +175,7 @@ describe('gossipsub fallbacks to floodsub', () => {
176175 const promise = new Promise ( ( resolve ) => nodeFs . once ( topic , resolve ) )
177176 nodeGs . once ( topic , ( m ) => shouldNotHappen )
178177
179- nodeGs . publish ( topic , Buffer . from ( 'hey' ) )
178+ nodeGs . publish ( topic , uint8ArrayFromString ( 'hey' ) )
180179
181180 const msg = await promise
182181 expect ( msg . data . toString ( ) ) . to . equal ( 'hey' )
@@ -188,7 +187,7 @@ describe('gossipsub fallbacks to floodsub', () => {
188187 it ( 'Publish to a topic - nodeFs' , async ( ) => {
189188 const promise = new Promise ( ( resolve ) => nodeGs . once ( topic , resolve ) )
190189
191- nodeFs . publish ( topic , Buffer . from ( 'banana' ) )
190+ nodeFs . publish ( topic , uint8ArrayFromString ( 'banana' ) )
192191
193192 const msg = await promise
194193
@@ -209,7 +208,7 @@ describe('gossipsub fallbacks to floodsub', () => {
209208 function receivedMsg ( msg ) {
210209 expect ( msg . data . toString ( ) ) . to . equal ( 'banana ' + counter )
211210 expect ( msg . from ) . to . be . eql ( nodeGs . peerId . toB58String ( ) )
212- expect ( Buffer . isBuffer ( msg . seqno ) ) . to . be . true ( )
211+ expect ( msg . seqno ) . to . be . a ( 'Uint8Array' )
213212 expect ( msg . topicIDs ) . to . be . eql ( [ topic ] )
214213
215214 if ( ++ counter === 10 ) {
@@ -219,7 +218,7 @@ describe('gossipsub fallbacks to floodsub', () => {
219218 }
220219 }
221220
222- times ( 10 , ( index ) => nodeGs . publish ( topic , Buffer . from ( 'banana ' + index ) ) )
221+ times ( 10 , ( index ) => nodeGs . publish ( topic , uint8ArrayFromString ( 'banana ' + index ) ) )
223222 } )
224223
225224 it ( 'Publish 10 msg to a topic as array' , ( done ) => {
@@ -236,7 +235,7 @@ describe('gossipsub fallbacks to floodsub', () => {
236235 function receivedMsg ( msg ) {
237236 expect ( msg . data . toString ( ) ) . to . equal ( 'banana ' + counter )
238237 expect ( msg . from ) . to . be . eql ( nodeGs . peerId . toB58String ( ) )
239- expect ( Buffer . isBuffer ( msg . seqno ) ) . to . be . true ( )
238+ expect ( msg . seqno ) . to . be . a ( 'Uint8Array' )
240239 expect ( msg . topicIDs ) . to . be . eql ( [ topic ] )
241240
242241 if ( ++ counter === 10 ) {
@@ -247,7 +246,7 @@ describe('gossipsub fallbacks to floodsub', () => {
247246 }
248247
249248 const msgs = [ ]
250- times ( 10 , ( index ) => msgs . push ( Buffer . from ( 'banana ' + index ) ) )
249+ times ( 10 , ( index ) => msgs . push ( uint8ArrayFromString ( 'banana ' + index ) ) )
251250 msgs . forEach ( msg => nodeGs . publish ( topic , msg ) )
252251 } )
253252 } )
@@ -314,8 +313,8 @@ describe('gossipsub fallbacks to floodsub', () => {
314313 } , 100 )
315314 } )
316315
317- nodeFs . publish ( 'Z' , Buffer . from ( 'banana' ) )
318- nodeGs . publish ( 'Z' , Buffer . from ( 'banana' ) )
316+ nodeFs . publish ( 'Z' , uint8ArrayFromString ( 'banana' ) )
317+ nodeGs . publish ( 'Z' , uint8ArrayFromString ( 'banana' ) )
319318
320319 try {
321320 await promise
0 commit comments