@@ -14,6 +14,7 @@ const {coinbaseInput, dummyInput} = primutils;
14
14
/** @typedef {import('../lib/wallet/wallet') } Wallet */
15
15
/** @typedef {import('../lib/covenants/rules').types } covenantTypes */
16
16
/** @typedef {import('../lib/primitives/output') } Output */
17
+ /** @typedef {import('../lib/primitives/tx') } TX */
17
18
18
19
// Use main instead of regtest because (deprecated)
19
20
// CoinSelector.MAX_FEE was network agnostic
@@ -238,42 +239,6 @@ describe('Wallet Coin Selection', function() {
238
239
}
239
240
} ) ;
240
241
241
- it ( 'should index disconnect tx output (spent)' , async ( ) => {
242
- await fundWallet ( wallet , TX_OPTIONS , false ) ;
243
- const currentBlock = curBlock ( wdb ) ;
244
-
245
- const spendAll = await wallet . createTX ( {
246
- hardFee : 0 ,
247
- outputs : [ { value : TOTAL_FUNDS , address : primutils . randomP2PKAddress ( ) } ]
248
- } ) ;
249
-
250
- await wdb . addTX ( spendAll . toTX ( ) ) ;
251
-
252
- let iter = wallet . getAccountCreditIterByValue ( 0 ) ;
253
- let creditsByValue = await collectIter ( iter ) ;
254
- assert . strictEqual ( creditsByValue . length , TOTAL_COINS ) ;
255
- assert ( isSortedByValue ( creditsByValue ) , 'Credits not sorted.' ) ;
256
-
257
- for ( const credit of creditsByValue ) {
258
- assert . strictEqual ( credit . coin . height , currentBlock . height ) ;
259
- assert . strictEqual ( credit . spent , true ) ;
260
- }
261
-
262
- // disconnect last block.
263
- await wdb . removeBlock ( currentBlock ) ;
264
-
265
- // Only thing that must change is the HEIGHT.
266
- iter = wallet . getAccountCreditIterByValue ( 0 ) ;
267
- creditsByValue = await collectIter ( iter ) ;
268
- assert . strictEqual ( creditsByValue . length , TOTAL_COINS ) ;
269
- assert ( isSortedByValue ( creditsByValue ) , 'Credits not sorted.' ) ;
270
-
271
- for ( const credit of creditsByValue ) {
272
- assert . strictEqual ( credit . coin . height , - 1 ) ;
273
- assert . strictEqual ( credit . spent , true ) ;
274
- }
275
- } ) ;
276
-
277
242
it ( 'should index disconnect tx input' , async ( ) => {
278
243
await fundWallet ( wallet , TX_OPTIONS , false ) ;
279
244
const createCoinHeight = curBlock ( wdb ) . height ;
@@ -361,6 +326,32 @@ describe('Wallet Coin Selection', function() {
361
326
creditsByValue = await collectIter ( iter ) ;
362
327
assert . strictEqual ( creditsByValue . length , 0 ) ;
363
328
} ) ;
329
+
330
+ it ( 'should index erase (block) tx output' , async ( ) => {
331
+ const txOptions = [ ...TX_OPTIONS ] ;
332
+ txOptions [ 0 ] . coinbase = true ;
333
+ const txs = await fundWallet ( wallet , txOptions , false ) ;
334
+ assert ( txs [ 0 ] . isCoinbase ( ) ) ;
335
+ assert . strictEqual ( txs . length , 1 ) ;
336
+
337
+ const currentBlock = curBlock ( wdb ) ;
338
+
339
+ let iter = wallet . getAccountCreditIterByValue ( 0 ) ;
340
+ let creditsByValue = await collectIter ( iter ) ;
341
+ assert . strictEqual ( creditsByValue . length , TOTAL_COINS ) ;
342
+ assert ( isSortedByValue ( creditsByValue ) , 'Credits not sorted.' ) ;
343
+
344
+ for ( const credit of creditsByValue ) {
345
+ assert . strictEqual ( credit . coin . height , currentBlock . height ) ;
346
+ assert . strictEqual ( credit . spent , false ) ;
347
+ }
348
+
349
+ await wdb . removeBlock ( currentBlock ) ;
350
+
351
+ iter = wallet . getAccountCreditIterByValue ( 0 ) ;
352
+ creditsByValue = await collectIter ( iter ) ;
353
+ assert . strictEqual ( creditsByValue . length , 0 ) ;
354
+ } ) ;
364
355
} ) ;
365
356
366
357
describe ( 'Selection types' , function ( ) {
@@ -437,7 +428,7 @@ describe('Wallet Coin Selection', function() {
437
428
} ) ;
438
429
} ) ;
439
430
440
- describe ( 'Fees' , function ( ) {
431
+ describe ( 'Fees' , function ( ) {
441
432
before ( beforeFn ) ;
442
433
after ( afterFn ) ;
443
434
@@ -613,7 +604,7 @@ async function createInboundTXs(wallet, outputInfos, txPerOutput = true) {
613
604
if ( info . coinbase && ! hadCoinbase ) {
614
605
hadCoinbase = true ;
615
606
mtx . addInput ( coinbaseInput ( ) ) ;
616
- } else {
607
+ } else if ( ! hadCoinbase ) {
617
608
mtx . addInput ( dummyInput ( ) ) ;
618
609
}
619
610
0 commit comments