@@ -10,12 +10,6 @@ import {
1010 LightningInitWalletBody ,
1111 LightningInitWalletParams ,
1212} from '../../../src/typedRoutes/api/v2/lightningInitWallet' ;
13- import { agent as supertest } from 'supertest' ;
14- import nock from 'nock' ;
15- import { DefaultConfig } from '../../../src/config' ;
16- import { app as expressApp } from '../../../src/expressApp' ;
17- import * as sinon from 'sinon' ;
18- import { BitGo } from 'bitgo' ;
1913
2014export function assertDecode < T > ( codec : t . Type < T , unknown > , input : unknown ) : T {
2115 const result = codec . decode ( input ) ;
@@ -158,131 +152,3 @@ describe('io-ts decode tests', function () {
158152 assertDecode ( t . type ( LightningInitWalletBody ) , { passphrase : 'p' , expressHost : 'host.example' } ) ;
159153 } ) ;
160154} ) ;
161-
162- describe ( 'e2e tests for io-ts routes' , function ( ) {
163- let agent ;
164- let authenticateStub : sinon . SinonStub ;
165- let walletsStub : sinon . SinonStub ;
166- let decryptStub : sinon . SinonStub ;
167- let encryptStub : sinon . SinonStub ;
168- let verifyAddressStub : sinon . SinonStub ;
169- before ( function ( ) {
170- nock . restore ( ) ;
171-
172- const args = {
173- ...DefaultConfig ,
174- debug : false ,
175- env : 'test' as const ,
176- logfile : '/dev/null' ,
177- } ;
178-
179- const app = expressApp ( args ) ;
180- agent = supertest ( app ) ;
181-
182- authenticateStub = sinon . stub ( BitGo . prototype , 'authenticate' ) . callsFake ( async ( body : any ) => {
183- return {
184- email : `${ body . username } @example.com` ,
185- password : body . password ,
186- forceSMS : false ,
187- } as any ;
188- } ) ;
189- encryptStub = sinon . stub ( BitGo . prototype , 'encrypt' ) . callsFake ( ( params : any ) => `enc:${ params . input } ` ) ;
190- decryptStub = sinon . stub ( BitGo . prototype , 'decrypt' ) . callsFake ( ( params : any ) => {
191- const inputStr = String ( params . input ) ;
192- return inputStr . startsWith ( 'enc:' ) ? inputStr . substring ( 4 ) : inputStr ;
193- } ) ;
194- verifyAddressStub = sinon . stub ( BitGo . prototype , 'verifyAddress' ) . callsFake ( ( _params : any ) => true ) ;
195- walletsStub = sinon . stub ( BitGo . prototype , 'wallets' ) . callsFake ( ( ) => {
196- return {
197- createWalletWithKeychains : async ( ) => ( {
198- wallet : 'wallet-id-123' ,
199- userKeychain : 'user-keychain' ,
200- backupKeychain : 'backup-keychain' ,
201- } ) ,
202- } ;
203- } ) ;
204- } ) ;
205- beforeEach ( function ( ) {
206- authenticateStub . resetHistory ( ) ;
207- walletsStub . resetHistory ( ) ;
208- decryptStub . resetHistory ( ) ;
209- encryptStub . resetHistory ( ) ;
210- verifyAddressStub . resetHistory ( ) ;
211- } ) ;
212- after ( function ( ) {
213- authenticateStub . restore ( ) ;
214- walletsStub . restore ( ) ;
215- decryptStub . restore ( ) ;
216- encryptStub . restore ( ) ;
217- verifyAddressStub . restore ( ) ;
218- } ) ;
219-
220- it ( 'POST /api/v2/user/login success' , async function ( ) {
221- const res = await agent . post ( '/api/v2/user/login' ) . send ( { username : 'alice' , password : 'pw' } ) ;
222- res . status . should . equal ( 200 ) ;
223- res . body . email . should . equal ( '[email protected] ' ) ; 224- res . body . password . should . equal ( 'pw' ) ;
225- sinon . assert . calledOnce ( authenticateStub ) ;
226- sinon . assert . calledWithMatch ( authenticateStub , { username : 'alice' , password : 'pw' } ) ;
227- } ) ;
228-
229- it ( 'POST /api/v2/user/login decode failure' , async function ( ) {
230- const res = await agent . post ( '/api/v2/user/login' ) . send ( { username : 'alice' } ) ;
231- res . status . should . equal ( 400 ) ;
232- sinon . assert . notCalled ( authenticateStub ) ;
233- } ) ;
234-
235- it ( 'POST /api/v2/encrypt success' , async function ( ) {
236- const res = await agent . post ( '/api/v2/encrypt' ) . send ( { input : 'hello' } ) ;
237- res . status . should . equal ( 200 ) ;
238- res . body . encrypted . should . equal ( 'enc:hello' ) ;
239- sinon . assert . calledOnce ( encryptStub ) ;
240- sinon . assert . calledWithMatch ( encryptStub , { input : 'hello' } ) ;
241- } ) ;
242-
243- it ( 'POST /api/v2/encrypt decode failure' , async function ( ) {
244- const res = await agent . post ( '/api/v2/encrypt' ) . send ( { input : 123 } ) ;
245- res . status . should . equal ( 400 ) ;
246- sinon . assert . notCalled ( encryptStub ) ;
247- } ) ;
248-
249- it ( 'POST /api/v2/decrypt success' , async function ( ) {
250- const res = await agent . post ( '/api/v2/decrypt' ) . send ( { input : 'enc:secret' , password : 'pw' } ) ;
251- res . status . should . equal ( 200 ) ;
252- res . body . decrypted . should . equal ( 'secret' ) ;
253- sinon . assert . calledOnce ( decryptStub ) ;
254- sinon . assert . calledWithMatch ( decryptStub , { input : 'enc:secret' , password : 'pw' } ) ;
255- } ) ;
256-
257- it ( 'POST /api/v2/decrypt decode failure' , async function ( ) {
258- const res = await agent . post ( '/api/v2/decrypt' ) . send ( { password : 'pw' } ) ;
259- res . status . should . equal ( 400 ) ;
260- sinon . assert . notCalled ( decryptStub ) ;
261- } ) ;
262-
263- it ( 'POST /api/v2/verifyaddress success' , async function ( ) {
264- const res = await agent . post ( '/api/v2/verifyaddress' ) . send ( { address : 'addr1' } ) ;
265- res . status . should . equal ( 200 ) ;
266- res . body . should . have . property ( 'verified' , true ) ;
267- sinon . assert . calledOnce ( verifyAddressStub ) ;
268- } ) ;
269-
270- it ( 'POST /api/v2/verifyaddress decode failure - invalid address' , async function ( ) {
271- const res = await agent . post ( '/api/v2/verifyaddress' ) . send ( { address : 42 } ) ;
272- res . status . should . equal ( 400 ) ;
273- sinon . assert . notCalled ( verifyAddressStub ) ;
274- } ) ;
275-
276- it ( 'POST /api/v1/wallets/simplecreate success' , async function ( ) {
277- const res = await agent . post ( '/api/v1/wallets/simplecreate' ) . send ( { passphrase : 'pass' } ) ;
278- res . status . should . equal ( 200 ) ;
279- res . body . wallet . should . equal ( 'wallet-id-123' ) ;
280- sinon . assert . calledOnce ( walletsStub ) ;
281- } ) ;
282-
283- it ( 'POST /api/v1/wallets/simplecreate decode - missing passphrase' , async function ( ) {
284- const res = await agent . post ( '/api/v1/wallets/simplecreate' ) . send ( { } ) ;
285- res . status . should . equal ( 400 ) ;
286- sinon . assert . notCalled ( walletsStub ) ;
287- } ) ;
288- } ) ;
0 commit comments