fundingmanager: Update tests for funding manager persistence

This commit adds the FundingManagerPersistence test to ensure that the
funding process completes as expected when nodes shutdown after the the
funding transaction has been broadcast. Note that the final parts of
several wallet tests have been removed, as functionality has been moved
to the Funding Manager and should now be tested there.
This commit is contained in:
bryanvu
2017-01-30 20:21:52 -08:00
committed by Olaoluwa Osuntokun
parent eb490b8833
commit d911107ec6
4 changed files with 211 additions and 76 deletions

View File

@@ -8,7 +8,6 @@ import (
"net"
"os"
"path/filepath"
"strings"
"testing"
"time"
@@ -470,13 +469,11 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, wallet *lnwallet
if err != nil {
t.Fatalf("bob is unable to sign alice's commit tx: %v", err)
}
if err := chanReservation.CompleteReservation(bobsSigs, commitSig); err != nil {
_, err = chanReservation.CompleteReservation(bobsSigs, commitSig)
if err != nil {
t.Fatalf("unable to complete funding tx: %v", err)
}
// At this point, the channel can be considered "open" when the funding
// txn hits a "comfortable" depth.
// The resulting active channel state should have been persisted to the DB.
fundingSha := fundingTx.TxHash()
channels, err := wallet.ChannelDB.FetchOpenChannels(bobNode.id)
@@ -486,56 +483,6 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, wallet *lnwallet
if !bytes.Equal(channels[0].FundingOutpoint.Hash[:], fundingSha[:]) {
t.Fatalf("channel state not properly saved")
}
// Assert that the channel opens after a single block.
lnChan := make(chan *lnwallet.LightningChannel, 1)
go func() {
openDetails, err := chanReservation.DispatchChan()
if err != nil {
t.Fatalf("unable to finalize reservation: %v", err)
}
lnChan <- openDetails.Channel
}()
lnc := assertChannelOpen(t, miner, uint32(numReqConfs), lnChan)
// Now that the channel is open, execute a cooperative closure of the
// now open channel.
aliceCloseSig, _, err := lnc.InitCooperativeClose()
if err != nil {
t.Fatalf("unable to init cooperative closure: %v", err)
}
aliceCloseSig = append(aliceCloseSig, byte(txscript.SigHashAll))
chanInfo := lnc.StateSnapshot()
// Obtain bob's signature for the closure transaction.
witnessScript := lnc.FundingWitnessScript
fundingOut := lnc.ChannelPoint()
fundingTxIn := wire.NewTxIn(fundingOut, nil, nil)
bobCloseTx := lnwallet.CreateCooperativeCloseTx(fundingTxIn,
chanInfo.RemoteBalance, chanInfo.LocalBalance,
lnc.RemoteDeliveryScript, lnc.LocalDeliveryScript,
true)
bobSig, err := bobNode.signCommitTx(bobCloseTx, witnessScript, int64(lnc.Capacity))
if err != nil {
t.Fatalf("unable to generate bob's signature for closing tx: %v", err)
}
// Broadcast the transaction to the network. This transaction should
// be accepted, and found in the next mined block.
ourKey := chanReservation.OurContribution().MultiSigKey.SerializeCompressed()
theirKey := chanReservation.TheirContribution().MultiSigKey.SerializeCompressed()
witness := lnwallet.SpendMultiSig(witnessScript, ourKey, aliceCloseSig,
theirKey, bobSig)
bobCloseTx.TxIn[0].Witness = witness
if err := wallet.PublishTransaction(bobCloseTx); err != nil {
t.Fatalf("broadcast of close tx rejected: %v", err)
}
// Now that the reservation has conclued, ensure that the wallet has
// cleaned up the state allocated to the reservation.
assertReservationDeleted(chanReservation, t)
}
func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
@@ -746,7 +693,7 @@ func testSingleFunderReservationWorkflowInitiator(miner *rpctest.Harness,
if err != nil {
t.Fatalf("bob is unable to sign alice's commit tx: %v", err)
}
if err := chanReservation.CompleteReservation(nil, bobCommitSig); err != nil {
if _, err := chanReservation.CompleteReservation(nil, bobCommitSig); err != nil {
t.Fatalf("unable to complete funding tx: %v", err)
}
@@ -774,17 +721,6 @@ func testSingleFunderReservationWorkflowInitiator(miner *rpctest.Harness,
channeldb.SingleFunder, channels[0].ChanType)
}
lnChan := make(chan *lnwallet.LightningChannel, 1)
go func() {
openDetails, err := chanReservation.DispatchChan()
if err != nil {
t.Fatalf("unable to open channel: %v", err)
}
lnChan <- openDetails.Channel
}()
assertChannelOpen(t, miner, uint32(numReqConfs), lnChan)
assertReservationDeleted(chanReservation, t)
}
@@ -925,7 +861,7 @@ func testSingleFunderReservationWorkflowResponder(miner *rpctest.Harness,
// With this stage complete, Alice can now complete the reservation.
bobRevokeKey := bobContribution.RevocationKey
err = chanReservation.CompleteReservationSingle(bobRevokeKey,
_, err = chanReservation.CompleteReservationSingle(bobRevokeKey,
fundingOutpoint, bobCommitSig, bobObsfucator)
if err != nil {
t.Fatalf("unable to complete reservation: %v", err)
@@ -937,14 +873,6 @@ func testSingleFunderReservationWorkflowResponder(miner *rpctest.Harness,
chanReservation.FundingOutpoint(), fundingOutpoint)
}
// Some period of time later, Bob presents us with an SPV proof
// attesting to an open channel. At this point Alice recognizes the
// channel, saves the state to disk, and creates the channel itself.
_, err = chanReservation.FinalizeReservation()
if err != nil && !strings.Contains(err.Error(), "No information") {
t.Fatalf("unable to finalize reservation: %v", err)
}
// TODO(roasbeef): bob verify alice's sig
assertReservationDeleted(chanReservation, t)
}