@@ -25,7 +25,7 @@ import {
25
25
import * as cryptoUtils from '../../src/utils/crypto' ;
26
26
import { InvalidPasswdError } from '../../src/errors' ;
27
27
import Network from '../../src/models/network' ;
28
- import { ILockedUtxo , IUtxo , OutputValueType , WALLET_FLAGS } from '../../src/types' ;
28
+ import { IHistoryTx , ILockedUtxo , IUtxo , IUtxoId , OutputValueType , WALLET_FLAGS } from '../../src/types' ;
29
29
30
30
const DATA_DIR = './testdata.leveldb' ;
31
31
@@ -362,7 +362,7 @@ test('selecting utxos', async () => {
362
362
const options = {
363
363
filter_method : utxo => utxo . txId === wantedTx ,
364
364
} ;
365
- const buf = [ ] ;
365
+ const buf : IUtxo [ ] = [ ] ;
366
366
for await ( const utxo of storage . selectUtxos ( options ) ) {
367
367
buf . push ( utxo ) ;
368
368
}
@@ -379,14 +379,14 @@ test('utxos selected as inputs', async () => {
379
379
storage . utxosSelectedAsInput . set ( 'a-tx-id2:0' , true ) ;
380
380
381
381
// Should check if the utxo is selected as input
382
- await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id1' , index : '0' } ) ) . resolves . toBe ( true ) ;
383
- await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id2' , index : '0' } ) ) . resolves . toBe ( true ) ;
384
- await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id3' , index : '0' } ) ) . resolves . toBe (
382
+ await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id1' , index : 0 } ) ) . resolves . toBe ( true ) ;
383
+ await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id2' , index : 0 } ) ) . resolves . toBe ( true ) ;
384
+ await expect ( storage . isUtxoSelectedAsInput ( { txId : 'a-tx-id3' , index : 0 } ) ) . resolves . toBe (
385
385
false
386
386
) ;
387
387
388
388
// Iterate on all utxos selected as input
389
- const buf = [ ] ;
389
+ const buf : IUtxoId [ ] = [ ] ;
390
390
for await ( const u of storage . utxoSelectedAsInputIter ( ) ) {
391
391
buf . push ( u ) ;
392
392
}
@@ -395,7 +395,10 @@ test('utxos selected as inputs', async () => {
395
395
expect ( buf ) . toContainEqual ( { txId : 'a-tx-id2' , index : 0 } ) ;
396
396
397
397
const tx = { txId : 'a-tx-id3' , outputs : [ { value : 10 , token : '00' , spent_by : null } ] } ;
398
- const getTxSpy = jest . spyOn ( storage , 'getTx' ) . mockImplementation ( async ( ) => tx ) ;
398
+ const getTxSpy = jest . spyOn ( storage , 'getTx' ) . mockImplementation (
399
+ async _txId => {
400
+ return tx as unknown as IHistoryTx ;
401
+ } ) ;
399
402
// no timeout, mark as selected: true
400
403
await storage . utxoSelectAsInput ( { txId : 'a-tx-id3' , index : 0 } , true ) ;
401
404
expect ( storage . utxosSelectedAsInput . get ( 'a-tx-id3:0' ) ) . toBe ( true ) ;
@@ -411,12 +414,27 @@ test('utxos selected as inputs', async () => {
411
414
await storage . utxoSelectAsInput ( { txId : 'a-tx-id4' , index : 0 } , true ) ;
412
415
expect ( storage . utxosSelectedAsInput . get ( 'a-tx-id4:0' ) ) . toBeUndefined ( ) ;
413
416
// Or with a spent output
414
- getTxSpy . mockImplementation ( async ( ) => ( {
415
- txId : 'a-tx-id3' ,
416
- outputs : [ { value : 10 , token : '00' , spent_by : 'a-tx-id5' } ] ,
417
- } ) ) ;
417
+ getTxSpy . mockImplementation ( async _txId => {
418
+ return {
419
+ txId : 'a-tx-id3' ,
420
+ outputs : [ { value : 10 , token : '00' , spent_by : 'a-tx-id5' } ] ,
421
+ } as unknown as IHistoryTx ;
422
+ } ) ;
418
423
await storage . utxoSelectAsInput ( { txId : 'a-tx-id3' , index : 0 } , true ) ;
419
424
expect ( storage . utxosSelectedAsInput . get ( 'a-tx-id3:0' ) ) . toBeUndefined ( ) ;
425
+
426
+ getTxSpy . mockImplementation ( async _txId => {
427
+ return {
428
+ txId : 'a-tx-id4' ,
429
+ outputs : [ { value : 10 , token : '00' , spent_by : null } ] ,
430
+ } as unknown as IHistoryTx ;
431
+ } ) ;
432
+ await storage . utxoSelectAsInput ( { txId : 'a-tx-id4' , index : 0 } , true , 500 ) ;
433
+ expect ( storage . utxosSelectedAsInput . get ( 'a-tx-id4:0' ) ) . toBe ( true ) ;
434
+ await new Promise < void > ( resolve => {
435
+ setTimeout ( resolve , 1000 ) ;
436
+ } ) ;
437
+ expect ( storage . utxosSelectedAsInput . get ( 'a-tx-id4:0' ) ) . not . toBe ( true ) ;
420
438
} ) ;
421
439
422
440
describe ( 'process locked utxos' , ( ) => {
0 commit comments