11import fetch from 'node-fetch'
22import { getAddress } from '@ethersproject/address'
3- import { waitForCondition } from 'streamr-test-utils'
4- import { getEndpointUrl } from '../utils'
3+ import { getEndpointUrl , until } from '../utils'
54import authFetch from '../rest/authFetch'
65
76import { StorageNode } from './StorageNode'
@@ -224,7 +223,7 @@ export class Stream {
224223 await this . update ( )
225224 }
226225
227- async addToStorageNode ( address : string ) {
226+ async addToStorageNode ( address : string , { timeout = 30000 } : { timeout : number } = { timeout : 30000 } ) {
228227 // currently we support only one storage node
229228 // -> we can validate that the given address is that address
230229 // -> remove this comparison when we start to support multiple storage nodes
@@ -233,8 +232,7 @@ export class Stream {
233232 }
234233 await authFetch (
235234 getEndpointUrl ( this . _client . options . restUrl , 'streams' , this . id , 'storageNodes' ) ,
236- this . _client . session ,
237- {
235+ this . _client . session , {
238236 method : 'POST' ,
239237 body : JSON . stringify ( {
240238 address
@@ -243,9 +241,8 @@ export class Stream {
243241 )
244242 // wait for propagation: the storage node sees the database change in E&E and
245243 // is ready to store the any stream data which we publish
246- const TIMEOUT = 30 * 1000
247244 const POLL_INTERVAL = 500
248- await waitForCondition ( ( ) => this . isStreamStoredInStorageNode ( this . id ) , TIMEOUT , POLL_INTERVAL ,
245+ await until ( ( ) => this . isStreamStoredInStorageNode ( this . id ) , timeout , POLL_INTERVAL ,
249246 ( ) => `Propagation timeout when adding stream to a storage node: ${ this . id } ` )
250247 }
251248
0 commit comments