import * as axios from 'axios' ; import { testing , PartialApplicationConfig } from 'lisk-framework' ; import { FaucetPlugin } from '../../src/plugin' ; describe ( 'fund tokens action' , ( ) => { let appEnv ; beforeAll ( async ( ) => { const rootPath = '~/.lisk/faucet' ; const config = { rootPath , label : 'faucet-integration-tests' , plugins : { faucet : { encryptedPassphrase : 'iterations=10&cipherText=6541c04d7a46eacd666c07fbf030fef32c5db324466e3422e59818317ac5d15cfffb80c5f1e2589eaa6da4f8d611a94cba92eee86722fc0a4015a37cff43a5a699601121fbfec11ea022&iv=141edfe6da3a9917a42004be&salt=f523bba8316c45246c6ffa848b806188&tag=4ffb5c753d4a1dc96364c4a54865521a&version=1' , captchaSecretkey : '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe' , captchaSitekey : '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' , } , } , } as PartialApplicationConfig ; appEnv = testing . createDefaultApplicationEnv ( { config , plugins : [ FaucetPlugin ] , } ) ; await appEnv . startApplication ( ) ; await appEnv . ipcClient . invoke < { result : string ; } > ( 'faucet:authorize' , { enable : true , password : 'elephant tree paris dragon chair galaxy' , } ) ; } ) ; afterAll ( async ( ) => { jest . spyOn ( process , 'exit' ) . mockImplementation ( ( ( ) => { } ) as never ) ; await appEnv . stopApplication ( ) ; } ) ; it ( 'should fund tokens when captcha success' , async ( ) => { jest . spyOn ( axios , 'default' ) . mockReturnValue ( { data : { success : true } } as any ) ; const fundResponse = await appEnv . ipcClient . invoke < { result : string ; } > ( 'faucet:fundTokens' , { address : '92ec9f11d90008ff5b419dedf95417b8f34644e9' , token : 'valid_captcha_token' , } ) ; expect ( fundResponse . result ) . toContain ( 'Successfully funded account at address:' ) ; } ) ; it ( 'should fail when captcha invalid' , async ( ) => { jest . spyOn ( axios , 'default' ) . mockReturnValue ( { data : { success : false } } as any ) ; await expect ( appEnv . ipcClient . invoke < { result : string ; } > ( 'faucet:fundTokens' , { address : '92ec9f11d90008ff5b419dedf95417b8f34644e9' , token : 'invalid_captcha_token' , } ) ) . rejects . toThrow ( 'Captcha response was invalid.' ) ; } ) ; } ) ;