@@ -2399,27 +2399,17 @@ func TestUpdateSweeperInputs(t *testing.T) {
2399
2399
require .Equal (expectedInputs , s .pendingInputs )
2400
2400
}
2401
2401
2402
- // TestAttachAvailableRBFInfo checks that the RBF info is attached to the
2403
- // pending input, along with the state being marked as published, when this
2404
- // input can be found both in mempool and the sweeper store.
2405
- func TestAttachAvailableRBFInfo (t * testing.T ) {
2402
+ // TestDecideStateAndRBFInfo checks that the expected state and RBFInfo are
2403
+ // returned based on whether this input can be found both in mempool and the
2404
+ // sweeper store.
2405
+ func TestDecideStateAndRBFInfo (t * testing.T ) {
2406
2406
t .Parallel ()
2407
2407
2408
2408
require := require .New (t )
2409
2409
2410
2410
// Create a test outpoint.
2411
2411
op := wire.OutPoint {Index : 1 }
2412
2412
2413
- // Create a mock input.
2414
- testInput := & input.MockInput {}
2415
- defer testInput .AssertExpectations (t )
2416
-
2417
- testInput .On ("OutPoint" ).Return (& op )
2418
- pi := & pendingInput {
2419
- Input : testInput ,
2420
- state : StateInit ,
2421
- }
2422
-
2423
2413
// Create a mock mempool watcher and a mock sweeper store.
2424
2414
mockMempool := chainntnfs .NewMockMempoolWatcher ()
2425
2415
defer mockMempool .AssertExpectations (t )
@@ -2436,11 +2426,11 @@ func TestAttachAvailableRBFInfo(t *testing.T) {
2436
2426
mockMempool .On ("LookupInputMempoolSpend" , op ).Return (
2437
2427
fn .None [wire.MsgTx ]()).Once ()
2438
2428
2439
- // Since the mempool lookup failed, we exepect the original pending
2440
- // input to stay unchanged .
2441
- result := s .attachAvailableRBFInfo ( pi )
2442
- require .True (result . rbf .IsNone ())
2443
- require .Equal (StateInit , result . state )
2429
+ // Since the mempool lookup failed, we exepect state Init and no
2430
+ // RBFInfo .
2431
+ state , rbf := s .decideStateAndRBFInfo ( op )
2432
+ require .True (rbf .IsNone ())
2433
+ require .Equal (StateInit , state )
2444
2434
2445
2435
// Mock the mempool lookup to return a tx three times as we are calling
2446
2436
// attachAvailableRBFInfo three times.
@@ -2451,21 +2441,19 @@ func TestAttachAvailableRBFInfo(t *testing.T) {
2451
2441
// Mock the store to return an error saying the tx cannot be found.
2452
2442
mockStore .On ("GetTx" , tx .TxHash ()).Return (nil , ErrTxNotFound ).Once ()
2453
2443
2454
- // Although the db lookup failed, the pending input should have been
2455
- // marked as published without attaching any RBF info.
2456
- result = s .attachAvailableRBFInfo (pi )
2457
- require .True (result .rbf .IsNone ())
2458
- require .Equal (StatePublished , result .state )
2444
+ // Although the db lookup failed, we expect the state to be Published.
2445
+ state , rbf = s .decideStateAndRBFInfo (op )
2446
+ require .True (rbf .IsNone ())
2447
+ require .Equal (StatePublished , state )
2459
2448
2460
2449
// Mock the store to return a db error.
2461
2450
dummyErr := errors .New ("dummy error" )
2462
2451
mockStore .On ("GetTx" , tx .TxHash ()).Return (nil , dummyErr ).Once ()
2463
2452
2464
- // Although the db lookup failed, the pending input should have been
2465
- // marked as published without attaching any RBF info.
2466
- result = s .attachAvailableRBFInfo (pi )
2467
- require .True (result .rbf .IsNone ())
2468
- require .Equal (StatePublished , result .state )
2453
+ // Although the db lookup failed, we expect the state to be Published.
2454
+ state , rbf = s .decideStateAndRBFInfo (op )
2455
+ require .True (rbf .IsNone ())
2456
+ require .Equal (StatePublished , state )
2469
2457
2470
2458
// Mock the store to return a record.
2471
2459
tr := & TxRecord {
@@ -2475,18 +2463,18 @@ func TestAttachAvailableRBFInfo(t *testing.T) {
2475
2463
mockStore .On ("GetTx" , tx .TxHash ()).Return (tr , nil ).Once ()
2476
2464
2477
2465
// Call the method again.
2478
- result = s .attachAvailableRBFInfo ( pi )
2466
+ state , rbf = s .decideStateAndRBFInfo ( op )
2479
2467
2480
- // Assert that the RBF info is attached to the pending input .
2468
+ // Assert that the RBF info is returned .
2481
2469
rbfInfo := fn .Some (RBFInfo {
2482
2470
Txid : tx .TxHash (),
2483
2471
Fee : btcutil .Amount (tr .Fee ),
2484
2472
FeeRate : chainfee .SatPerKWeight (tr .FeeRate ),
2485
2473
})
2486
- require .Equal (rbfInfo , result . rbf )
2474
+ require .Equal (rbfInfo , rbf )
2487
2475
2488
2476
// Assert the state is updated.
2489
- require .Equal (StatePublished , result . state )
2477
+ require .Equal (StatePublished , state )
2490
2478
}
2491
2479
2492
2480
// TestMarkInputFailed checks that the input is marked as failed as expected.
0 commit comments