@@ -33,16 +33,25 @@ export const writeConfigFile = jest.fn(async () => {
33
33
return "File written:" ;
34
34
} ) ;
35
35
36
- export const subscribeStateEmitter = ( data : Uint8Array ) => DeviceEventEmitter . emit ( "SubscribeState" , { data : base64 . fromByteArray ( data ) } ) ;
36
+ export const subscribeStateEmitter = ( data : Uint8Array ) =>
37
+ DeviceEventEmitter . emit ( "SubscribeState" , { data : base64 . fromByteArray ( data ) } ) ;
37
38
export const subscribeState = async ( ) => {
38
39
setTimeout ( async ( ) => {
39
40
subscribeStateEmitter (
40
41
lnrpc . SubscribeStateResponse . encode ( {
41
42
state : lnrpc . WalletState . LOCKED ,
42
- } ) . finish ( )
43
+ } ) . finish ( ) ,
43
44
) ;
44
- } , 10 )
45
- }
45
+ } , 10 ) ;
46
+ } ;
47
+
48
+ export const generateSecureRandomAsBase64 = jest . fn ( async ( length : number ) => {
49
+ return "c2F0b3NoaQ==" ;
50
+ } ) ;
51
+
52
+ export const generateSecureRandom = jest . fn ( async ( length : number ) => {
53
+ return new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ;
54
+ } ) ;
46
55
47
56
export const decodeState = ( data : string ) : lnrpc . SubscribeStateResponse => {
48
57
return decodeStreamResult < lnrpc . SubscribeStateResponse > ( {
@@ -84,10 +93,12 @@ export const startLnd = jest.fn(async (): Promise<string> => {
84
93
85
94
export const getInfoResponse = lnrpc . GetInfoResponse . create ( {
86
95
uris : [ ] ,
87
- chains : [ {
88
- chain : "bitcoin" ,
89
- network : "testnet" ,
90
- } ] ,
96
+ chains : [
97
+ {
98
+ chain : "bitcoin" ,
99
+ network : "testnet" ,
100
+ } ,
101
+ ] ,
91
102
identityPubkey : "02b5380da0919e32b13c1a21c1c85000eed0ba9a9309fc6849d72230d43088ae1d" ,
92
103
alias : "02b5380da0919e32b13c" ,
93
104
numPeers : 3 ,
@@ -100,13 +111,18 @@ export const getInfoResponse = lnrpc.GetInfoResponse.create({
100
111
version : "0.7.1-beta commit=v0.7.1-beta-rc1-10-g3760f29f5e758b2865b756604333ca22cf23e90b" ,
101
112
features : { } ,
102
113
} ) ;
103
- export const getInfo = jest . fn ( )
114
+ export const getInfo = jest
115
+ . fn ( )
104
116
. mockImplementationOnce ( async ( ) => getInfoResponse )
105
- . mockImplementation ( async ( ) => ( { ...getInfoResponse , syncedToChain : true , syncedToGraph : true } ) ) ;
117
+ . mockImplementation ( async ( ) => ( {
118
+ ...getInfoResponse ,
119
+ syncedToChain : true ,
120
+ syncedToGraph : true ,
121
+ } ) ) ;
106
122
107
123
export const sendPaymentSync = async ( paymentRequest : string ) : Promise < lnrpc . SendResponse > => {
108
124
const response = lnrpc . SendResponse . create ( {
109
- paymentHash : new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ,
125
+ paymentHash : new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) ,
110
126
paymentRoute : {
111
127
totalAmt : Long . fromNumber ( 1000 ) ,
112
128
totalAmtMsat : Long . fromNumber ( 1000000 ) ,
@@ -121,8 +137,8 @@ export const sendPaymentSync = async (paymentRequest: string): Promise<lnrpc.Sen
121
137
export const sendPaymentV2Sync = async ( paymentRequest : string ) : Promise < lnrpc . Payment > => {
122
138
await timeout ( 600 ) ;
123
139
124
- const paymentHash = new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ;
125
- const paymentPreimage = new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ;
140
+ const paymentHash = new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ;
141
+ const paymentPreimage = new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ;
126
142
127
143
const response = lnrpc . Payment . create ( {
128
144
paymentHash : bytesToHexString ( paymentHash ) ,
@@ -131,39 +147,50 @@ export const sendPaymentV2Sync = async (paymentRequest: string): Promise<lnrpc.P
131
147
status : lnrpc . Payment . PaymentStatus . SUCCEEDED ,
132
148
fee : Long . fromValue ( 1 ) ,
133
149
feeMsat : Long . fromValue ( 1000 ) ,
134
- htlcs : [ {
135
- route : {
136
- hops : [ {
137
- chanId : Long . fromValue ( 1 ) ,
138
- chanCapacity : Long . fromValue ( 10000 ) ,
139
- amtToForward : Long . fromValue ( 100 ) ,
140
- amtToForwardMsat : Long . fromValue ( 100000 ) ,
141
- fee : Long . fromValue ( 1 ) ,
142
- feeMsat : Long . fromValue ( 1000 ) ,
143
- expiry : 3600 ,
144
- pubKey : "abc" ,
145
- } ] ,
150
+ htlcs : [
151
+ {
152
+ route : {
153
+ hops : [
154
+ {
155
+ chanId : Long . fromValue ( 1 ) ,
156
+ chanCapacity : Long . fromValue ( 10000 ) ,
157
+ amtToForward : Long . fromValue ( 100 ) ,
158
+ amtToForwardMsat : Long . fromValue ( 100000 ) ,
159
+ fee : Long . fromValue ( 1 ) ,
160
+ feeMsat : Long . fromValue ( 1000 ) ,
161
+ expiry : 3600 ,
162
+ pubKey : "abc" ,
163
+ } ,
164
+ ] ,
165
+ } ,
146
166
} ,
147
- } ] ,
167
+ ] ,
148
168
} ) ;
149
169
return response ;
150
170
} ;
151
171
152
- export const addInvoice = async ( amount : number , memo : string , expiry : number = 3600 ) : Promise < lnrpc . AddInvoiceResponse > => {
172
+ export const addInvoice = async (
173
+ amount : number ,
174
+ memo : string ,
175
+ expiry : number = 3600 ,
176
+ ) : Promise < lnrpc . AddInvoiceResponse > => {
153
177
try {
154
178
const unixTimestamp = Math . floor ( Date . now ( ) / 1000 ) ;
155
179
const encoded = payReq . encode ( {
156
180
coinType : "testnet" ,
157
181
satoshis : amount ,
158
182
timestamp : unixTimestamp ,
159
183
timeExpireDate : expiry ,
160
- tags : [ {
161
- tagName : "payment_hash" ,
162
- data : "0001020304050607080900010203040506070809000102030405060708090102" ,
163
- } , {
164
- tagName : "description" ,
165
- data : memo ,
166
- } ] ,
184
+ tags : [
185
+ {
186
+ tagName : "payment_hash" ,
187
+ data : "0001020304050607080900010203040506070809000102030405060708090102" ,
188
+ } ,
189
+ {
190
+ tagName : "description" ,
191
+ data : memo ,
192
+ } ,
193
+ ] ,
167
194
} ) ;
168
195
169
196
const privateKeyHex = "e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734" ;
@@ -188,7 +215,7 @@ export const addInvoice = async (amount: number, memo: string, expiry: number =
188
215
value : Long . fromNumber ( signed ! . satoshis ! ) ,
189
216
amtPaidMsat : Long . fromNumber ( signed ! . satoshis ! ) . mul ( 1000 ) ,
190
217
amtPaidSat : Long . fromNumber ( signed ! . satoshis ! ) ,
191
- cltvExpiry : cltvExpiry && ( Long . fromNumber ( cltvExpiry . data as number ) ) ,
218
+ cltvExpiry : cltvExpiry && Long . fromNumber ( cltvExpiry . data as number ) ,
192
219
creationDate : Long . fromNumber ( signed ! . timestamp ! ) ,
193
220
expiry : Long . fromNumber ( expiry ) ,
194
221
rPreimage : new Uint8Array ( [ 1 , 2 , 3 , 4 ] ) , // TODO
@@ -207,9 +234,19 @@ export const addInvoice = async (amount: number, memo: string, expiry: number =
207
234
}
208
235
} ;
209
236
210
- export const addInvoiceBlixtLsp = ( { amount, memo, expiry = 600 , servicePubkey, chanId, cltvExpiryDelta, feeBaseMsat, feeProportionalMillionths, preimage} : IAddInvoiceBlixtLspArgs ) => {
237
+ export const addInvoiceBlixtLsp = ( {
238
+ amount,
239
+ memo,
240
+ expiry = 600 ,
241
+ servicePubkey,
242
+ chanId,
243
+ cltvExpiryDelta,
244
+ feeBaseMsat,
245
+ feeProportionalMillionths,
246
+ preimage,
247
+ } : IAddInvoiceBlixtLspArgs ) => {
211
248
return addInvoice ( amount , memo , expiry ) ;
212
- }
249
+ } ;
213
250
214
251
//
215
252
// export const lookupInvoice = async (rHash: string): Promise<lnrpc.Invoice> => {
@@ -224,12 +261,16 @@ export const addInvoiceBlixtLsp = ({amount, memo, expiry = 600, servicePubkey, c
224
261
// return response;
225
262
// };
226
263
227
- export const queryRoutes = async ( pubKey : string , amount ?: Long , routeHints ?: lnrpc . IRouteHint [ ] ) : Promise < lnrpc . QueryRoutesResponse > => {
264
+ export const queryRoutes = async (
265
+ pubKey : string ,
266
+ amount ?: Long ,
267
+ routeHints ?: lnrpc . IRouteHint [ ] ,
268
+ ) : Promise < lnrpc . QueryRoutesResponse > => {
228
269
return lnrpc . QueryRoutesResponse . create ( {
229
270
routes : [ ] ,
230
271
successProb : 0.5 ,
231
272
} ) ;
232
- }
273
+ } ;
233
274
234
275
// TODO test
235
276
export const decodePayReq = async ( bolt11 : string ) : Promise < lnrpc . PayReq > => {
@@ -250,30 +291,30 @@ export const decodePayReq = async (bolt11: string): Promise<lnrpc.PayReq> => {
250
291
/**
251
292
* @throws
252
293
*/
253
- export const getRecoveryInfo = async ( ) : Promise < lnrpc . GetRecoveryInfoResponse > => {
294
+ export const getRecoveryInfo = async ( ) : Promise < lnrpc . GetRecoveryInfoResponse > => {
254
295
const response = lnrpc . GetRecoveryInfoResponse . create ( {
255
296
progress : 1 ,
256
297
recoveryFinished : false ,
257
298
recoveryMode : false ,
258
- } )
299
+ } ) ;
259
300
return response ;
260
301
} ;
261
302
262
303
/**
263
304
* @throws
264
305
*/
265
- export const listUnspent = async ( ) : Promise < lnrpc . ListUnspentResponse > => {
306
+ export const listUnspent = async ( ) : Promise < lnrpc . ListUnspentResponse > => {
266
307
const response = lnrpc . ListUnspentResponse . create ( {
267
- utxos : [ ]
268
- } )
308
+ utxos : [ ] ,
309
+ } ) ;
269
310
return response ;
270
311
} ;
271
312
272
313
/**
273
314
* @throws
274
315
*/
275
- export const resetMissionControl = async ( ) : Promise < routerrpc . ResetMissionControlResponse > => {
276
- const response = routerrpc . ResetMissionControlResponse . create ( { } )
316
+ export const resetMissionControl = async ( ) : Promise < routerrpc . ResetMissionControlResponse > => {
317
+ const response = routerrpc . ResetMissionControlResponse . create ( { } ) ;
277
318
return response ;
278
319
} ;
279
320
0 commit comments