@@ -8,6 +8,7 @@ import { CID } from 'multiformats'
88import { stubInterface } from 'sinon-ts'
99import { createDelegatedRoutingV1HttpApiServer } from '../src/index.js'
1010import type { Helia } from '@helia/interface'
11+ import type { Libp2p } from '@libp2p/interface'
1112import type { PeerInfo } from '@libp2p/interface/peer-info'
1213import type { FastifyInstance } from 'fastify'
1314import type { StubbedInstance } from 'sinon-ts'
@@ -18,7 +19,9 @@ describe('delegated-routing-v1-http-api-server', () => {
1819 let url : URL
1920
2021 beforeEach ( async ( ) => {
21- helia = stubInterface < Helia > ( )
22+ helia = stubInterface < Helia > ( {
23+ libp2p : stubInterface < Libp2p > ( )
24+ } )
2225 server = await createDelegatedRoutingV1HttpApiServer ( helia , {
2326 listen : {
2427 host : '127.0.0.1' ,
@@ -66,12 +69,7 @@ describe('delegated-routing-v1-http-api-server', () => {
6669 } )
6770
6871 it ( 'GET providers returns 404 if no providers are found' , async ( ) => {
69- helia . libp2p = {
70- // @ts -expect-error incomplete implementation
71- contentRouting : {
72- findProviders : async function * ( ) { }
73- }
74- }
72+ helia . libp2p . contentRouting . findProviders = async function * ( ) { }
7573
7674 const res = await fetch ( `${ url } routing/v1/providers/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn` , {
7775 method : 'GET'
@@ -81,12 +79,7 @@ describe('delegated-routing-v1-http-api-server', () => {
8179 } )
8280
8381 it ( 'GET providers returns 404 if no providers are found when streaming' , async ( ) => {
84- helia . libp2p = {
85- // @ts -expect-error incomplete implementation
86- contentRouting : {
87- findProviders : async function * ( ) { }
88- }
89- }
82+ helia . libp2p . contentRouting . findProviders = async function * ( ) { }
9083
9184 const res = await fetch ( `${ url } routing/v1/providers/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn` , {
9285 method : 'GET' ,
@@ -114,14 +107,9 @@ describe('delegated-routing-v1-http-api-server', () => {
114107 protocols : [ ]
115108 }
116109
117- helia . libp2p = {
118- // @ts -expect-error incomplete implementation
119- contentRouting : {
120- findProviders : async function * ( ) {
121- yield provider1
122- yield provider2
123- }
124- }
110+ helia . libp2p . contentRouting . findProviders = async function * ( ) {
111+ yield provider1
112+ yield provider2
125113 }
126114
127115 const res = await fetch ( `${ url } routing/v1/providers/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn` , {
@@ -156,14 +144,9 @@ describe('delegated-routing-v1-http-api-server', () => {
156144 protocols : [ ]
157145 }
158146
159- helia . libp2p = {
160- // @ts -expect-error incomplete implementation
161- contentRouting : {
162- findProviders : async function * ( ) {
163- yield provider1
164- yield provider2
165- }
166- }
147+ helia . libp2p . contentRouting . findProviders = async function * ( ) {
148+ yield provider1
149+ yield provider2
167150 }
168151
169152 const res = await fetch ( `${ url } routing/v1/providers/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn` , {
@@ -213,13 +196,8 @@ describe('delegated-routing-v1-http-api-server', () => {
213196 protocols : [ 'transport-bitswap' ]
214197 }
215198
216- helia . libp2p = {
217- // @ts -expect-error incomplete implementation
218- peerRouting : {
219- findPeer : async function ( ) {
220- return peer
221- }
222- }
199+ helia . libp2p . peerRouting . findPeer = async function ( ) {
200+ return peer
223201 }
224202
225203 const res = await fetch ( `${ url } routing/v1/peers/${ peer . id . toCID ( ) . toString ( ) } ` , {
@@ -254,13 +232,8 @@ describe('delegated-routing-v1-http-api-server', () => {
254232 const cid = CID . parse ( 'bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4' )
255233 const record = await createIpnsRecord ( peerId , cid , 0 , 1000 )
256234
257- helia . libp2p = {
258- // @ts -expect-error incomplete implementation
259- contentRouting : {
260- get : async function ( ) {
261- return marshalIpnsRecord ( record )
262- }
263- }
235+ helia . libp2p . contentRouting . get = async function ( ) {
236+ return marshalIpnsRecord ( record )
264237 }
265238
266239 const res = await fetch ( `${ url } routing/v1/ipns/${ peerId . toCID ( ) . toString ( ) } ` , {
@@ -284,14 +257,9 @@ describe('delegated-routing-v1-http-api-server', () => {
284257 let putKey : Uint8Array = new Uint8Array ( )
285258 let putValue : Uint8Array = new Uint8Array ( )
286259
287- helia . libp2p = {
288- // @ts -expect-error incomplete implementation
289- contentRouting : {
290- put : async function ( key : Uint8Array , value : Uint8Array ) {
291- putKey = key
292- putValue = value
293- }
294- }
260+ helia . libp2p . contentRouting . put = async function ( key : Uint8Array , value : Uint8Array ) {
261+ putKey = key
262+ putValue = value
295263 }
296264
297265 const res = await fetch ( `${ url } routing/v1/ipns/${ peerId . toCID ( ) . toString ( ) } ` , {
0 commit comments