@@ -10,7 +10,7 @@ import { mockNetwork } from '@libp2p/interface-mocks'
10
10
import { stubInterface } from 'ts-sinon'
11
11
import { Registrar } from '@libp2p/interface-registrar'
12
12
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
13
- import { PeerStore } from '@libp2p/interface-peer-store'
13
+ import { PeerStore , Tag } from '@libp2p/interface-peer-store'
14
14
import { ConnectionManager } from '@libp2p/interface-connection-manager'
15
15
16
16
describe ( 'gossip' , ( ) => {
@@ -80,6 +80,86 @@ describe('gossip', () => {
80
80
nodeASpy . pushGossip . restore ( )
81
81
} )
82
82
83
+ it ( 'should add the tag gossipsub-mesh-peer upon grafting' , async function ( ) {
84
+ this . timeout ( 10e4 )
85
+ const topic = 'Z'
86
+ // add subscriptions to each node
87
+ nodes . forEach ( ( n ) => n . pubsub . subscribe ( topic ) )
88
+
89
+ // every node connected to every other
90
+ await connectAllPubSubNodes ( nodes )
91
+
92
+ // wait for subscriptions to be transmitted
93
+ await Promise . all ( nodes . map ( async ( n ) => await pEvent ( n . pubsub , 'subscription-change' ) ) )
94
+
95
+ // await mesh rebalancing
96
+ await Promise . all ( nodes . map ( async ( n ) => await pEvent ( n . pubsub , 'gossipsub:heartbeat' ) ) )
97
+
98
+ // const allTags: Tag[][] = []
99
+
100
+ // nodes.forEach(async (subscribedPeer) => {
101
+ // allTags.push(await subscribedPeer.components.peerStore.getTags(subscribedPeer.components.peerId))
102
+ // })
103
+
104
+ // // gossip happens during the heartbeat
105
+ // await pEvent(nodes[nodes.length - 1].pubsub, 'gossipsub:heartbeat')
106
+
107
+ // expect(
108
+ // allTags.map((tags) => {
109
+ // tags.map((tag) => {
110
+ // tag.name.toString()
111
+ // })
112
+ // })
113
+ // ).to.include('gossipsub-mesh-peer')
114
+
115
+ await pEvent ( nodes [ nodes . length - 1 ] . pubsub , 'gossipsub:heartbeat' )
116
+
117
+ expect (
118
+ ( await nodes [ 0 ] . components . peerStore . getTags ( nodes [ 0 ] . components . peerId ) ) . map ( ( tag ) => tag . name . toString ( ) )
119
+ ) . to . include ( 'gossipsub-mesh-peer' )
120
+ } )
121
+
122
+ it ( 'should remove the tag gossipsub-mesh-peer upon pruning' , async function ( ) {
123
+ this . timeout ( 10e4 )
124
+ const topic = 'Z'
125
+ // add subscriptions to each node
126
+ nodes . forEach ( ( n ) => n . pubsub . subscribe ( topic ) )
127
+
128
+ // every node connected to every other
129
+ await connectAllPubSubNodes ( nodes )
130
+
131
+ // wait for subscriptions to be transmitted
132
+ await Promise . all ( nodes . map ( async ( n ) => await pEvent ( n . pubsub , 'subscription-change' ) ) )
133
+
134
+ // disconnect some peers from the mesh to get some PRUNEs and the store the disconnected peers
135
+ const unsubscribedPeers : GossipSubAndComponents [ ] = [ ]
136
+
137
+ nodes . slice ( 0 , 5 ) . forEach ( ( ps ) => {
138
+ ps . pubsub . unsubscribe ( topic )
139
+ unsubscribedPeers . push ( ps )
140
+ } )
141
+
142
+ // await mesh rebalancing
143
+ await Promise . all ( nodes . map ( async ( n ) => await pEvent ( n . pubsub , 'gossipsub:heartbeat' ) ) )
144
+
145
+ const allTags : Tag [ ] [ ] = [ ]
146
+
147
+ unsubscribedPeers . forEach ( async ( unsubscribedPeer ) => {
148
+ allTags . push ( await unsubscribedPeer . components . peerStore . getTags ( unsubscribedPeer . components . peerId ) )
149
+ } )
150
+
151
+ // gossip happens during the heartbeat
152
+ await pEvent ( unsubscribedPeers [ 4 ] . pubsub , 'gossipsub:heartbeat' )
153
+
154
+ expect (
155
+ allTags . map ( ( tags ) => {
156
+ tags . map ( ( tag ) => {
157
+ tag . name . toString ( )
158
+ } )
159
+ } )
160
+ ) . to . not . include ( 'gossipsub-mesh-peer' )
161
+ } )
162
+
83
163
it ( 'should reject incoming messages bigger than maxInboundDataLength limit' , async function ( ) {
84
164
this . timeout ( 10e4 )
85
165
const nodeA = nodes [ 0 ]
0 commit comments