fundingmanager test: check reservation canceled after tx broadcast

This commit is contained in:
Johan T. Halseth 2018-07-26 15:48:09 +02:00
parent 2a77b57788
commit b885e8d288
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -249,7 +249,6 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
wc := &mockWalletController{ wc := &mockWalletController{
rootKey: alicePrivKey, rootKey: alicePrivKey,
publishedTransactions: publTxChan,
} }
signer := &mockSigner{ signer := &mockSigner{
key: alicePrivKey, key: alicePrivKey,
@ -349,6 +348,10 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
ReportShortChanID: func(wire.OutPoint) error { ReportShortChanID: func(wire.OutPoint) error {
return nil return nil
}, },
PublishTransaction: func(txn *wire.MsgTx) error {
publTxChan <- txn
return nil
},
ZombieSweeperInterval: 1 * time.Hour, ZombieSweeperInterval: 1 * time.Hour,
ReservationTimeout: 1 * time.Nanosecond, ReservationTimeout: 1 * time.Nanosecond,
}) })
@ -565,6 +568,11 @@ func openChannel(t *testing.T, alice, bob *testNode, localFundingAmt,
t, bob.msgChan, "AcceptChannel", t, bob.msgChan, "AcceptChannel",
).(*lnwire.AcceptChannel) ).(*lnwire.AcceptChannel)
// They now should both have pending reservations for this channel
// active.
assertNumPendingReservations(t, alice, bobPubKey, 1)
assertNumPendingReservations(t, bob, alicePubKey, 1)
// Forward the response to Alice. // Forward the response to Alice.
alice.fundingMgr.processFundingAccept(acceptChannelResponse, bob) alice.fundingMgr.processFundingAccept(acceptChannelResponse, bob)
@ -611,6 +619,12 @@ func openChannel(t *testing.T, alice, bob *testNode, localFundingAmt,
Hash: publ.TxHash(), Hash: publ.TxHash(),
Index: 0, Index: 0,
} }
// Finally, make sure neither have active reservation for the channel
// now pending open in the database.
assertNumPendingReservations(t, alice, bobPubKey, 0)
assertNumPendingReservations(t, bob, alicePubKey, 0)
return fundingOutPoint return fundingOutPoint
} }
@ -947,19 +961,10 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan, fundingOutPoint := openChannel(t, alice, bob, 500000, 0, 1, updateChan,
true) true)
// Make sure both reservations time out and then run both zombie sweepers.
time.Sleep(1 * time.Millisecond)
go alice.fundingMgr.pruneZombieReservations()
go bob.fundingMgr.pruneZombieReservations()
// Check that neither Alice nor Bob sent an error message. // Check that neither Alice nor Bob sent an error message.
assertErrorNotSent(t, alice.msgChan) assertErrorNotSent(t, alice.msgChan)
assertErrorNotSent(t, bob.msgChan) assertErrorNotSent(t, bob.msgChan)
// Check that neither reservation has been pruned.
assertNumPendingReservations(t, alice, bobPubKey, 1)
assertNumPendingReservations(t, bob, alicePubKey, 1)
// Notify that transaction was mined. // Notify that transaction was mined.
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{} alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
bob.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{} bob.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{}
@ -2087,39 +2092,6 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
t, alice.msgChan, "FundingCreated", t, alice.msgChan, "FundingCreated",
).(*lnwire.FundingCreated) ).(*lnwire.FundingCreated)
// Give the message to Bob.
bob.fundingMgr.processFundingCreated(fundingCreated, alice)
// Finally, Bob should send the FundingSigned message.
fundingSigned := assertFundingMsgSent(
t, bob.msgChan, "FundingSigned",
).(*lnwire.FundingSigned)
// Forward the signature to Alice.
alice.fundingMgr.processFundingSigned(fundingSigned, bob)
// After Alice processes the singleFundingSignComplete message, she will
// broadcast the funding transaction to the network. We expect to get a
// channel update saying the channel is pending.
var pendingUpdate *lnrpc.OpenStatusUpdate
select {
case pendingUpdate = <-updateChan:
case <-time.After(time.Second * 5):
t.Fatalf("alice did not send OpenStatusUpdate_ChanPending")
}
_, ok = pendingUpdate.Update.(*lnrpc.OpenStatusUpdate_ChanPending)
if !ok {
t.Fatal("OpenStatusUpdate was not OpenStatusUpdate_ChanPending")
}
// Wait for Alice to published the funding tx to the network.
select {
case <-alice.publTxChan:
case <-time.After(time.Second * 5):
t.Fatalf("alice did not publish funding tx")
}
// Helper method for checking the CSV delay stored for a reservation. // Helper method for checking the CSV delay stored for a reservation.
assertDelay := func(resCtx *reservationWithCtx, assertDelay := func(resCtx *reservationWithCtx,
ourDelay, theirDelay uint16) error { ourDelay, theirDelay uint16) error {
@ -2189,4 +2161,37 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
if err := assertMinHtlc(resCtx, minHtlc, 5); err != nil { if err := assertMinHtlc(resCtx, minHtlc, 5); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Give the message to Bob.
bob.fundingMgr.processFundingCreated(fundingCreated, alice)
// Finally, Bob should send the FundingSigned message.
fundingSigned := assertFundingMsgSent(
t, bob.msgChan, "FundingSigned",
).(*lnwire.FundingSigned)
// Forward the signature to Alice.
alice.fundingMgr.processFundingSigned(fundingSigned, bob)
// After Alice processes the singleFundingSignComplete message, she will
// broadcast the funding transaction to the network. We expect to get a
// channel update saying the channel is pending.
var pendingUpdate *lnrpc.OpenStatusUpdate
select {
case pendingUpdate = <-updateChan:
case <-time.After(time.Second * 5):
t.Fatalf("alice did not send OpenStatusUpdate_ChanPending")
}
_, ok = pendingUpdate.Update.(*lnrpc.OpenStatusUpdate_ChanPending)
if !ok {
t.Fatal("OpenStatusUpdate was not OpenStatusUpdate_ChanPending")
}
// Wait for Alice to published the funding tx to the network.
select {
case <-alice.publTxChan:
case <-time.After(time.Second * 5):
t.Fatalf("alice did not publish funding tx")
}
} }