@@ -7,6 +7,7 @@ const { expect } = chai
77const pDefer = require ( 'p-defer' )
88
99const PeerInfo = require ( 'peer-info' )
10+ const Topology = require ( 'libp2p-interfaces/src/topology' )
1011const PeerStore = require ( '../../src/peer-store' )
1112const Registrar = require ( '../../src/registrar' )
1213const { createMockConnection } = require ( './utils' )
@@ -32,53 +33,7 @@ describe('registrar', () => {
3233 throw new Error ( 'should fail to register a protocol if no multicodec is provided' )
3334 } )
3435
35- it ( 'should fail to register a protocol if no handlers are provided' , ( ) => {
36- const topologyProps = {
37- multicodecs : multicodec
38- }
39-
40- try {
41- registrar . register ( topologyProps )
42- } catch ( err ) {
43- expect ( err ) . to . exist ( )
44- return
45- }
46- throw new Error ( 'should fail to register a protocol if no handlers are provided' )
47- } )
48-
49- it ( 'should fail to register a protocol if the onConnect handler is not provided' , ( ) => {
50- const topologyProps = {
51- multicodecs : multicodec ,
52- handlers : {
53- onDisconnect : ( ) => { }
54- }
55- }
56-
57- try {
58- registrar . register ( topologyProps )
59- } catch ( err ) {
60- expect ( err ) . to . exist ( )
61- return
62- }
63- throw new Error ( 'should fail to register a protocol if the onConnect handler is not provided' )
64- } )
65-
66- it ( 'should fail to register a protocol if the onDisconnect handler is not provided' , ( ) => {
67- const topologyProps = {
68- multicodecs : multicodec ,
69- handlers : {
70- onConnect : ( ) => { }
71- }
72- }
73-
74- try {
75- registrar . register ( topologyProps )
76- } catch ( err ) {
77- expect ( err ) . to . exist ( )
78- return
79- }
80- throw new Error ( 'should fail to register a protocol if the onDisconnect handler is not provided' )
81- } )
36+ // TODO: not valid topology
8237 } )
8338
8439 describe ( 'registration' , ( ) => {
@@ -88,27 +43,27 @@ describe('registrar', () => {
8843 } )
8944
9045 it ( 'should be able to register a protocol' , ( ) => {
91- const topologyProps = {
46+ const topologyProps = new Topology ( {
47+ multicodecs : multicodec ,
9248 handlers : {
9349 onConnect : ( ) => { } ,
9450 onDisconnect : ( ) => { }
95- } ,
96- multicodecs : multicodec
97- }
51+ }
52+ } )
9853
9954 const identifier = registrar . register ( topologyProps )
10055
10156 expect ( identifier ) . to . exist ( )
10257 } )
10358
10459 it ( 'should be able to unregister a protocol' , ( ) => {
105- const topologyProps = {
60+ const topologyProps = new Topology ( {
61+ multicodecs : multicodec ,
10662 handlers : {
10763 onConnect : ( ) => { } ,
10864 onDisconnect : ( ) => { }
109- } ,
110- multicodecs : multicodec
111- }
65+ }
66+ } )
11267
11368 const identifier = registrar . register ( topologyProps )
11469 const success = registrar . unregister ( identifier )
@@ -138,7 +93,7 @@ describe('registrar', () => {
13893 registrar . onConnect ( remotePeerInfo , conn )
13994 expect ( registrar . connections . size ) . to . eql ( 1 )
14095
141- const topologyProps = {
96+ const topologyProps = new Topology ( {
14297 multicodecs : multicodec ,
14398 handlers : {
14499 onConnect : ( peerInfo , connection ) => {
@@ -153,19 +108,17 @@ describe('registrar', () => {
153108 onDisconnectDefer . resolve ( )
154109 }
155110 }
156- }
111+ } )
157112
158113 // Register protocol
159114 const identifier = registrar . register ( topologyProps )
160115 const topology = registrar . topologies . get ( identifier )
161116
162117 // Topology created
163118 expect ( topology ) . to . exist ( )
164- expect ( topology . peers . size ) . to . eql ( 1 )
165119
166120 registrar . onDisconnect ( remotePeerInfo )
167121 expect ( registrar . connections . size ) . to . eql ( 0 )
168- expect ( topology . peers . size ) . to . eql ( 1 ) // topology should keep the peer
169122
170123 // Wait for handlers to be called
171124 return Promise . all ( [
@@ -178,7 +131,7 @@ describe('registrar', () => {
178131 const onConnectDefer = pDefer ( )
179132 const onDisconnectDefer = pDefer ( )
180133
181- const topologyProps = {
134+ const topologyProps = new Topology ( {
182135 multicodecs : multicodec ,
183136 handlers : {
184137 onConnect : ( ) => {
@@ -188,15 +141,14 @@ describe('registrar', () => {
188141 onDisconnectDefer . resolve ( )
189142 }
190143 }
191- }
144+ } )
192145
193146 // Register protocol
194147 const identifier = registrar . register ( topologyProps )
195148 const topology = registrar . topologies . get ( identifier )
196149
197150 // Topology created
198151 expect ( topology ) . to . exist ( )
199- expect ( topology . peers . size ) . to . eql ( 0 )
200152 expect ( registrar . connections . size ) . to . eql ( 0 )
201153
202154 // Setup connections before registrar
@@ -212,7 +164,6 @@ describe('registrar', () => {
212164 peerStore . put ( peerInfo )
213165
214166 await onConnectDefer . promise
215- expect ( topology . peers . size ) . to . eql ( 1 )
216167
217168 // Remove protocol to peer and update it
218169 peerInfo . protocols . delete ( multicodec )
0 commit comments