@@ -63,7 +63,7 @@ describe('Lightning signer routes', () => {
6363 bitgo : bitgo ,
6464 body : includingOptionalFields
6565 ? apiData . initWalletRequestBody
66- : { ...apiData . initWalletRequestBody , signerTlsKey : undefined } ,
66+ : { ...apiData . initWalletRequestBody , expressHost : undefined } ,
6767 params : {
6868 coin : 'tlnbtc' ,
6969 id : 'fakeid' ,
@@ -84,6 +84,49 @@ describe('Lightning signer routes', () => {
8484 } ) ;
8585 }
8686
87+ for ( const includingOptionalFields of [ true , false ] ) {
88+ it ( `should create signer macaroon ${ includingOptionalFields ? 'with' : 'without' } optional fields` , async ( ) => {
89+ const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( JSON . stringify ( lightningSignerConfigs ) ) ;
90+ const wpWalletnock = nock ( bgUrl ) . get ( `/api/v2/tlnbtc/wallet/${ apiData . wallet . id } ` ) . reply ( 200 , apiData . wallet ) ;
91+
92+ const wpKeychainNocks = [
93+ nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . userAuthKey . id } ` ) . reply ( 200 , apiData . userAuthKey ) ,
94+ nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . nodeAuthKey . id } ` ) . reply ( 200 , apiData . nodeAuthKey ) ,
95+ nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . userAuthKey . id } ` ) . reply ( 200 , apiData . userAuthKey ) ,
96+ nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . nodeAuthKey . id } ` ) . reply ( 200 , apiData . nodeAuthKey ) ,
97+ ] ;
98+
99+ const signerMacaroon = nock ( lightningSignerConfigs . fakeid . url )
100+ . post ( `/v1/macaroon` )
101+ . reply ( 200 , signerApiData . bakeMacaroon ) ;
102+
103+ const wpWalletUpdateNock = nock ( bgUrl ) . put ( `/api/v2/tlnbtc/wallet/${ apiData . wallet . id } ` ) . reply ( 200 ) ;
104+
105+ const req = {
106+ bitgo : bitgo ,
107+ body : includingOptionalFields
108+ ? apiData . signerMacaroonRequestBody
109+ : { ...apiData . signerMacaroonRequestBody , watchOnlyIp : undefined } ,
110+ params : {
111+ coin : 'tlnbtc' ,
112+ id : 'fakeid' ,
113+ } ,
114+ config : {
115+ lightningSignerFileSystemPath : 'lightningSignerFileSystemPath' ,
116+ } ,
117+ } as unknown as express . Request ;
118+
119+ await handleCreateSignerMacaroon ( req ) ;
120+
121+ wpWalletUpdateNock . done ( ) ;
122+ signerMacaroon . done ( ) ;
123+ wpKeychainNocks . forEach ( ( s ) => s . done ( ) ) ;
124+ wpWalletnock . done ( ) ;
125+ readFileStub . calledOnceWith ( 'lightningSignerFileSystemPath' ) . should . be . true ( ) ;
126+ readFileStub . restore ( ) ;
127+ } ) ;
128+ }
129+
87130 it ( 'should get signer wallet state' , async ( ) => {
88131 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( JSON . stringify ( lightningSignerConfigs ) ) ;
89132 const walletStateNock = nock ( lightningSignerConfigs . fakeid . url )
@@ -92,7 +135,6 @@ describe('Lightning signer routes', () => {
92135
93136 const req = {
94137 bitgo : bitgo ,
95- body : apiData . signerMacaroonRequestBody ,
96138 params : {
97139 coin : 'tlnbtc' ,
98140 id : apiData . wallet . id ,
@@ -109,45 +151,6 @@ describe('Lightning signer routes', () => {
109151 readFileStub . restore ( ) ;
110152 } ) ;
111153
112- it ( 'should create signer macaroon' , async ( ) => {
113- const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( JSON . stringify ( lightningSignerConfigs ) ) ;
114- const wpWalletnock = nock ( bgUrl ) . get ( `/api/v2/tlnbtc/wallet/${ apiData . wallet . id } ` ) . reply ( 200 , apiData . wallet ) ;
115-
116- const wpKeychainNocks = [
117- nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . userAuthKey . id } ` ) . reply ( 200 , apiData . userAuthKey ) ,
118- nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . nodeAuthKey . id } ` ) . reply ( 200 , apiData . nodeAuthKey ) ,
119- nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . userAuthKey . id } ` ) . reply ( 200 , apiData . userAuthKey ) ,
120- nock ( bgUrl ) . get ( `/api/v2/tlnbtc/key/${ apiData . nodeAuthKey . id } ` ) . reply ( 200 , apiData . nodeAuthKey ) ,
121- ] ;
122-
123- const signerMacaroon = nock ( lightningSignerConfigs . fakeid . url )
124- . post ( `/v1/macaroon` )
125- . reply ( 200 , signerApiData . bakeMacaroon ) ;
126-
127- const wpWalletUpdateNock = nock ( bgUrl ) . put ( `/api/v2/tlnbtc/wallet/${ apiData . wallet . id } ` ) . reply ( 200 ) ;
128-
129- const req = {
130- bitgo : bitgo ,
131- body : apiData . signerMacaroonRequestBody ,
132- params : {
133- coin : 'tlnbtc' ,
134- id : 'fakeid' ,
135- } ,
136- config : {
137- lightningSignerFileSystemPath : 'lightningSignerFileSystemPath' ,
138- } ,
139- } as unknown as express . Request ;
140-
141- await handleCreateSignerMacaroon ( req ) ;
142-
143- wpWalletUpdateNock . done ( ) ;
144- signerMacaroon . done ( ) ;
145- wpKeychainNocks . forEach ( ( s ) => s . done ( ) ) ;
146- wpWalletnock . done ( ) ;
147- readFileStub . calledOnceWith ( 'lightningSignerFileSystemPath' ) . should . be . true ( ) ;
148- readFileStub . restore ( ) ;
149- } ) ;
150-
151154 it ( 'should unlock lightning wallet' , async ( ) => {
152155 const readFileStub = sinon . stub ( fs . promises , 'readFile' ) . resolves ( JSON . stringify ( lightningSignerConfigs ) ) ;
153156
0 commit comments