From cb85b2bd26ff42375996e4a09463aec407ec4185 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 10 Nov 2017 15:15:19 -0800 Subject: [PATCH] htlcswitch: update createTestChannel to adhere to latest channeldb API's --- htlcswitch/mock.go | 4 ++++ htlcswitch/test_utils.go | 44 +++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index da598618..48d47128 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -273,6 +273,7 @@ func (s *mockServer) intersect(f messageInterceptor) { } func (s *mockServer) SendMessage(message lnwire.Message) error { + select { case s.messages <- message: case <-s.quit: @@ -304,6 +305,7 @@ func (s *mockServer) readHandler(message lnwire.Message) error { case *lnwire.ChannelReestablish: targetChan = msg.ChanID default: + return fmt.Errorf("unknown message type: %T", msg) } // Dispatch the commitment update message to the proper @@ -315,6 +317,7 @@ func (s *mockServer) readHandler(message lnwire.Message) error { // Create goroutine for this, in order to be able to properly stop // the server when handler stacked (server unavailable) + link.HandleChannelUpdate(message) return nil } @@ -326,6 +329,7 @@ func (s *mockServer) PubKey() [33]byte { func (s *mockServer) Disconnect(reason error) { fmt.Printf("server %v disconnected due to %v\n", s.name, reason) + s.t.Fatalf("server %v was disconnected: %v", s.name, reason) } func (s *mockServer) WipeChannel(*lnwallet.LightningChannel) error { diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 134581e6..6eb61e7a 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/rand" "crypto/sha256" + "fmt" "testing" "time" @@ -186,52 +187,63 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, Port: 18556, } + aliceCommit := channeldb.ChannelCommitment{ + CommitHeight: 0, + LocalBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee), + RemoteBalance: lnwire.NewMSatFromSatoshis(bobAmount), + CommitFee: commitFee, + FeePerKw: feePerKw, + CommitTx: aliceCommitTx, + CommitSig: bytes.Repeat([]byte{1}, 71), + } + bobCommit := channeldb.ChannelCommitment{ + CommitHeight: 0, + LocalBalance: lnwire.NewMSatFromSatoshis(bobAmount), + RemoteBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee), + CommitFee: commitFee, + FeePerKw: feePerKw, + CommitTx: bobCommitTx, + CommitSig: bytes.Repeat([]byte{1}, 71), + } + aliceChannelState := &channeldb.OpenChannel{ LocalChanCfg: aliceCfg, RemoteChanCfg: bobCfg, IdentityPub: aliceKeyPub, FundingOutpoint: *prevOut, ChanType: channeldb.SingleFunder, - FeePerKw: feePerKw, IsInitiator: true, Capacity: channelCapacity, - LocalBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee), - RemoteBalance: lnwire.NewMSatFromSatoshis(bobAmount), - CommitFee: commitFee, - CommitTx: *aliceCommitTx, - CommitSig: bytes.Repeat([]byte{1}, 71), RemoteCurrentRevocation: bobCommitPoint, RevocationProducer: alicePreimageProducer, RevocationStore: shachain.NewRevocationStore(), + LocalCommitment: aliceCommit, + RemoteCommitment: aliceCommit, ShortChanID: chanID, Db: dbAlice, } - if err := aliceChannelState.SyncPending(bobAddr, broadcastHeight); err != nil { - return nil, nil, nil, nil, err - } - bobChannelState := &channeldb.OpenChannel{ LocalChanCfg: bobCfg, RemoteChanCfg: aliceCfg, IdentityPub: bobKeyPub, - FeePerKw: feePerKw, FundingOutpoint: *prevOut, ChanType: channeldb.SingleFunder, IsInitiator: false, Capacity: channelCapacity, - LocalBalance: lnwire.NewMSatFromSatoshis(bobAmount), - RemoteBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee), - CommitFee: commitFee, - CommitTx: *bobCommitTx, - CommitSig: bytes.Repeat([]byte{1}, 71), RemoteCurrentRevocation: aliceCommitPoint, RevocationProducer: bobPreimageProducer, RevocationStore: shachain.NewRevocationStore(), + LocalCommitment: bobCommit, + RemoteCommitment: bobCommit, ShortChanID: chanID, Db: dbBob, } + if err := aliceChannelState.SyncPending(bobAddr, broadcastHeight); err != nil { + return nil, nil, nil, nil, err + } + if err := bobChannelState.SyncPending(aliceAddr, broadcastHeight); err != nil { return nil, nil, nil, nil, err }