import { logger } from './RadixLogger' ; import RadixAccount from '../account/RadixAccount' ; import { RadixTransaction } from '../../index' ; import { catchError , map } from 'rxjs/operators' ; import RadixTransactionUpdate from '../account/RadixTransactionUpdate' ; export const requestTestTokensFromFaucetOrDie = async ( account , killNodeServerOnFailure = true ) : Promise < string | void > => { return account . requestTestTokensFromFaucetWithLinearBackingOffRetry ( 'http://localhost:8079' ) . catch ( e => { if ( killNodeServerOnFailure ) { logger . error ( `☠️🚨 killing process since we failed to get response from faucet. ${ e }` ) ; process . exit ( 1 ) ; } else { const errorMessage = `Failed to get tokens from faucet` ; logger . error ( errorMessage ) ; throw new Error ( errorMessage ) ; } } ) ; } ; export const requestTestTokensFromFaucetAndUpdateBalanceOrDie = async ( account ) : Promise < RadixTransaction > => { const txUnique = await requestTestTokensFromFaucetOrDie ( account ) ; return account . transferSystem . getAllTransactions ( ) . delay ( 2000 ) . take ( 1 ) . timeout ( 60000 ) . pipe ( catchError ( ( error , obs ) => { throw new Error ( `🚰 Failed to update balance after having received test XRD tokens from
                              faucet in tx with unique string
                               ${ txUnique }, error: ${ error }
                               ` ) ; } ) ) . pipe ( map ( ( tu ) => tu . transaction ) ) . toPromise ( ) ; } ;