@@ -8,6 +8,8 @@ const errcode = require('err-code')
8
8
const sinon = require ( 'sinon' )
9
9
const pRetry = require ( 'p-retry' )
10
10
const { EventEmitter } = require ( 'events' )
11
+ const { fromString : uint8ArrayFromString } = require ( 'uint8arrays/from-string' )
12
+ const { equals : uint8ArrayEquals } = require ( 'uint8arrays/equals' )
11
13
12
14
const Floodsub = require ( 'libp2p-floodsub' )
13
15
const Gossipsub = require ( '../src' )
@@ -41,7 +43,7 @@ const checkReceivedMessage = (topic, data, senderIx, msgIx) =>
41
43
reject ( new Error ( `Message never received, sender ${ senderIx } , receiver ${ receiverIx } , index ${ msgIx } ` ) )
42
44
} , 20000 )
43
45
cb = ( msg ) => {
44
- if ( data . equals ( msg . data ) ) {
46
+ if ( uint8ArrayEquals ( data , msg . data ) ) {
45
47
clearTimeout ( t )
46
48
psub . off ( topic , cb )
47
49
resolve ( )
@@ -95,7 +97,8 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
95
97
96
98
let sendRecv = [ ]
97
99
for ( let i = 0 ; i < 100 ; i ++ ) {
98
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
100
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
101
+
99
102
const owner = Math . floor ( Math . random ( ) * psubs . length )
100
103
const results = Promise . all (
101
104
psubs
@@ -128,7 +131,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
128
131
129
132
let sendRecv = [ ]
130
133
for ( let i = 0 ; i < 100 ; i ++ ) {
131
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
134
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
132
135
const owner = Math . floor ( Math . random ( ) * psubs . length )
133
136
const results = Promise . all (
134
137
psubs
@@ -164,7 +167,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
164
167
165
168
let sendRecv = [ ]
166
169
for ( let i = 0 ; i < 100 ; i ++ ) {
167
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
170
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
168
171
169
172
const owner = 0
170
173
@@ -186,7 +189,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
186
189
187
190
sendRecv = [ ]
188
191
for ( let i = 0 ; i < 100 ; i ++ ) {
189
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
192
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
190
193
191
194
const owner = 0
192
195
@@ -227,7 +230,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
227
230
let sendRecv = [ ]
228
231
const sendMessages = ( ) => {
229
232
for ( let i = 0 ; i < 100 ; i ++ ) {
230
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
233
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
231
234
232
235
const owner = 0
233
236
@@ -286,7 +289,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
286
289
287
290
let sendRecv = [ ]
288
291
for ( let i = 0 ; i < 5 ; i ++ ) {
289
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
292
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
290
293
291
294
const owner = 0
292
295
@@ -328,7 +331,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
328
331
await Promise . all ( psubs . map ( ps => awaitEvents ( ps , 'gossipsub:heartbeat' , 2 ) ) )
329
332
330
333
for ( let i = 0 ; i < 100 ; i ++ ) {
331
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
334
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
332
335
const owner = Math . floor ( Math . random ( ) * psubs . length )
333
336
const results = Promise . all (
334
337
psubs
@@ -372,7 +375,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
372
375
373
376
let sendRecv = [ ]
374
377
for ( let i = 0 ; i < 10 ; i ++ ) {
375
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
378
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
376
379
const owner = 0
377
380
const results = Promise . all (
378
381
group1 . slice ( 1 )
@@ -435,7 +438,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
435
438
436
439
let sendRecv = [ ]
437
440
for ( let i = 0 ; i < 100 ; i ++ ) {
438
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
441
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
439
442
const owner = Math . floor ( Math . random ( ) * psubs . length )
440
443
const results = Promise . all (
441
444
psubs
@@ -473,7 +476,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
473
476
474
477
let sendRecv = [ ]
475
478
for ( let i = 0 ; i < 100 ; i ++ ) {
476
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
479
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
477
480
const owner = Math . floor ( Math . random ( ) * psubs . length )
478
481
const results = Promise . all (
479
482
psubs
@@ -514,7 +517,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
514
517
515
518
let sendRecv = [ ]
516
519
for ( let i = 0 ; i < 100 ; i ++ ) {
517
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
520
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
518
521
const owner = Math . floor ( Math . random ( ) * ( psubs . length - 5 ) )
519
522
const results = Promise . all (
520
523
psubs . slice ( 5 )
@@ -549,7 +552,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
549
552
await Promise . all ( psubs . map ( ps => awaitEvents ( ps , 'gossipsub:heartbeat' , 9 ) ) )
550
553
551
554
for ( let i = 0 ; i < 35 ; i ++ ) {
552
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
555
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
553
556
const owner = Math . floor ( Math . random ( ) * psubs . length )
554
557
const results = Promise . all (
555
558
psubs
@@ -589,7 +592,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
589
592
590
593
// create a background flood of messages that overloads the queues
591
594
const floodOwner = Math . floor ( Math . random ( ) * psubs . length )
592
- const floodMsg = Buffer . from ( 'background flooooood' )
595
+ const floodMsg = uint8ArrayFromString ( 'background flooooood' )
593
596
const backgroundFlood = new Promise ( async resolve => {
594
597
for ( let i = 0 ; i < 10000 ; i ++ ) {
595
598
await psubs [ floodOwner ] . publish ( floodTopic , floodMsg )
@@ -612,7 +615,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
612
615
// and test that we have functional overlays
613
616
let sendRecv = [ ]
614
617
for ( let i = 0 ; i < 5 ; i ++ ) {
615
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
618
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
616
619
const owner = Math . floor ( Math . random ( ) * psubs . length )
617
620
const results = Promise . all (
618
621
psubs
@@ -657,7 +660,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
657
660
658
661
let sendRecv = [ ]
659
662
for ( let i = 0 ; i < 100 ; i ++ ) {
660
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
663
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
661
664
const owner = Math . floor ( Math . random ( ) * psubs . length )
662
665
const results = Promise . all (
663
666
psubs
@@ -691,7 +694,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
691
694
// wait for heartbeats to build mesh
692
695
await Promise . all ( psubs . map ( ps => awaitEvents ( ps , 'gossipsub:heartbeat' , 2 ) ) )
693
696
694
- const msg = Buffer . from ( `${ 0 } its not a flooooood ${ 0 } ` )
697
+ const msg = uint8ArrayFromString ( `${ 0 } its not a flooooood ${ 0 } ` )
695
698
const owner = 0
696
699
const results = checkReceivedMessage ( topic , msg , owner , 0 ) ( psubs [ 5 ] , 5 )
697
700
await psubs [ owner ] . publish ( topic , msg )
@@ -742,7 +745,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
742
745
743
746
let sendRecv = [ ]
744
747
for ( const owner of [ 9 , 3 ] ) {
745
- const msg = Buffer . from ( `${ owner } its not a flooooood ${ owner } ` )
748
+ const msg = uint8ArrayFromString ( `${ owner } its not a flooooood ${ owner } ` )
746
749
const results = Promise . all (
747
750
psubs
748
751
. filter ( ( psub , j ) => j !== owner )
@@ -798,7 +801,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
798
801
// send a message from each peer and assert it was propagated
799
802
let sendRecv = [ ]
800
803
for ( let i = 0 ; i < psubs . length ; i ++ ) {
801
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
804
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
802
805
const owner = i
803
806
const results = Promise . all (
804
807
psubs
@@ -867,7 +870,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
867
870
868
871
let sendRecv = [ ]
869
872
for ( let i = 0 ; i < 3 ; i ++ ) {
870
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
873
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
871
874
const owner = i
872
875
const results = Promise . all (
873
876
psubs
@@ -888,7 +891,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
888
891
889
892
sendRecv = [ ]
890
893
for ( let i = 0 ; i < 3 ; i ++ ) {
891
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
894
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
892
895
const owner = i
893
896
const results = Promise . all (
894
897
psubs
@@ -925,7 +928,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
925
928
// send messages from the star and assert they were received
926
929
let sendRecv = [ ]
927
930
for ( let i = 0 ; i < 20 ; i ++ ) {
928
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
931
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
929
932
const owner = 0
930
933
const results = Promise . all (
931
934
psubs
@@ -978,7 +981,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
978
981
979
982
let sendRecv = [ ]
980
983
for ( let i = 0 ; i < 20 ; i ++ ) {
981
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
984
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
982
985
const owner = i
983
986
sendRecv . push ( psubs [ owner ] . publish ( topic , msg ) )
984
987
}
@@ -1030,7 +1033,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
1030
1033
1031
1034
psubs [ 0 ] . on ( topic , ( ) => expect . fail ( 'node 0 should not receive any messages' ) )
1032
1035
1033
- const msg = Buffer . from ( 'its not a flooooood' )
1036
+ const msg = uint8ArrayFromString ( 'its not a flooooood' )
1034
1037
await psubs [ 1 ] . publish ( topic , msg )
1035
1038
await psubs [ 2 ] . publish ( topic , msg )
1036
1039
@@ -1139,7 +1142,7 @@ describe("go-libp2p-pubsub gossipsub tests", function () {
1139
1142
psubs . forEach ( ps => ps . subscribe ( topic ) )
1140
1143
1141
1144
for ( let i = 0 ; i < 300 ; i ++ ) {
1142
- const msg = Buffer . from ( `${ i } its not a flooooood ${ i } ` )
1145
+ const msg = uint8ArrayFromString ( `${ i } its not a flooooood ${ i } ` )
1143
1146
const owner = i % 10
1144
1147
await psubs [ owner ] . publish ( topic , msg )
1145
1148
await delay ( 20 )
0 commit comments