@@ -42,7 +42,8 @@ func TestGetStaticAddressLoopInSwapsByStates(t *testing.T) {
4242
4343 loopingDepositID := newID ()
4444 loopedInDepositID := newID ()
45- d1 , d2 := & deposit.Deposit {
45+ failedDepositID := newID ()
46+ d1 , d2 , d3 := & deposit.Deposit {
4647 ID : loopingDepositID ,
4748 OutPoint : wire.OutPoint {
4849 Hash : chainhash.Hash {0x1a , 0x2b , 0x3c , 0x4d },
@@ -63,29 +64,48 @@ func TestGetStaticAddressLoopInSwapsByStates(t *testing.T) {
6364 TimeOutSweepPkScript : []byte {
6465 0x00 , 0x14 , 0x1a , 0x2b , 0x3c , 0x4d ,
6566 },
67+ },
68+ & deposit.Deposit {
69+ ID : failedDepositID ,
70+ OutPoint : wire.OutPoint {
71+ Hash : chainhash.Hash {0x3a , 0x2b , 0x3c , 0x4e },
72+ Index : 2 ,
73+ },
74+ Value : btcutil .Amount (300_000 ),
75+ TimeOutSweepPkScript : []byte {
76+ 0x00 , 0x14 , 0x1a , 0x2b , 0x3c , 0x4f ,
77+ },
6678 }
6779
6880 err := depositStore .CreateDeposit (ctxb , d1 )
6981 require .NoError (t , err )
7082 err = depositStore .CreateDeposit (ctxb , d2 )
7183 require .NoError (t , err )
84+ err = depositStore .CreateDeposit (ctxb , d3 )
85+ require .NoError (t , err )
7286
7387 // Add two updates per deposit, expect the last to be retrieved.
7488 d1 .SetState (deposit .Deposited )
7589 d2 .SetState (deposit .Deposited )
90+ d3 .SetState (deposit .Deposited )
7691
7792 err = depositStore .UpdateDeposit (ctxb , d1 )
7893 require .NoError (t , err )
7994 err = depositStore .UpdateDeposit (ctxb , d2 )
8095 require .NoError (t , err )
96+ err = depositStore .UpdateDeposit (ctxb , d3 )
97+ require .NoError (t , err )
8198
8299 d1 .SetState (deposit .LoopingIn )
83100 d2 .SetState (deposit .LoopedIn )
101+ d3 .SetState (deposit .Deposited )
84102
85103 err = depositStore .UpdateDeposit (ctxb , d1 )
86104 require .NoError (t , err )
87105 err = depositStore .UpdateDeposit (ctxb , d2 )
88106 require .NoError (t , err )
107+ err = depositStore .UpdateDeposit (ctxb , d3 )
108+ require .NoError (t , err )
89109
90110 _ , clientPubKey := test .CreateKey (1 )
91111 _ , serverPubKey := test .CreateKey (2 )
@@ -124,6 +144,23 @@ func TestGetStaticAddressLoopInSwapsByStates(t *testing.T) {
124144 err = swapStore .CreateLoopIn (ctxb , & swapSucceeded )
125145 require .NoError (t , err )
126146
147+ // Create failed swap. Failed is the last final state, so this
148+ // exercises the state-list query boundary.
149+ swapHashFailed := lntypes.Hash {0x3 , 0x2 , 0x3 , 0x5 }
150+ swapFailed := StaticAddressLoopIn {
151+ SwapHash : swapHashFailed ,
152+ SwapPreimage : lntypes.Preimage {0x3 , 0x2 , 0x3 , 0x5 },
153+ DepositOutpoints : []string {d3 .OutPoint .String ()},
154+ Deposits : []* deposit.Deposit {d3 },
155+ ClientPubkey : clientPubKey ,
156+ ServerPubkey : serverPubKey ,
157+ HtlcTimeoutSweepAddress : addr ,
158+ }
159+ swapFailed .SetState (Failed )
160+
161+ err = swapStore .CreateLoopIn (ctxb , & swapFailed )
162+ require .NoError (t , err )
163+
127164 pendingSwaps , err := swapStore .GetStaticAddressLoopInSwapsByStates (ctxb , PendingStates )
128165 require .NoError (t , err )
129166
@@ -142,10 +179,12 @@ func TestGetStaticAddressLoopInSwapsByStates(t *testing.T) {
142179 finalizedSwaps , err := swapStore .GetStaticAddressLoopInSwapsByStates (ctxb , FinalStates )
143180 require .NoError (t , err )
144181
145- require .Len (t , finalizedSwaps , 1 )
182+ require .Len (t , finalizedSwaps , 2 )
146183 require .Equal (t , swapHashSucceeded , finalizedSwaps [0 ].SwapHash )
147184 require .Equal (t , []string {d2 .OutPoint .String ()}, finalizedSwaps [0 ].DepositOutpoints )
148185 require .Equal (t , Succeeded , finalizedSwaps [0 ].GetState ())
186+ require .Equal (t , swapHashFailed , finalizedSwaps [1 ].SwapHash )
187+ require .Equal (t , Failed , finalizedSwaps [1 ].GetState ())
149188
150189 finalizedDeposits := finalizedSwaps [0 ].Deposits
151190 require .Len (t , finalizedDeposits , 1 )
0 commit comments