htlcswitch: update createTestChannel to adhere to latest channeldb API's

This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 15:15:19 -08:00
parent 9873d4ece8
commit cb85b2bd26
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 32 additions and 16 deletions

@ -273,6 +273,7 @@ func (s *mockServer) intersect(f messageInterceptor) {
} }
func (s *mockServer) SendMessage(message lnwire.Message) error { func (s *mockServer) SendMessage(message lnwire.Message) error {
select { select {
case s.messages <- message: case s.messages <- message:
case <-s.quit: case <-s.quit:
@ -304,6 +305,7 @@ func (s *mockServer) readHandler(message lnwire.Message) error {
case *lnwire.ChannelReestablish: case *lnwire.ChannelReestablish:
targetChan = msg.ChanID targetChan = msg.ChanID
default: default:
return fmt.Errorf("unknown message type: %T", msg)
} }
// Dispatch the commitment update message to the proper // 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 // Create goroutine for this, in order to be able to properly stop
// the server when handler stacked (server unavailable) // the server when handler stacked (server unavailable)
link.HandleChannelUpdate(message)
return nil return nil
} }
@ -326,6 +329,7 @@ func (s *mockServer) PubKey() [33]byte {
func (s *mockServer) Disconnect(reason error) { func (s *mockServer) Disconnect(reason error) {
fmt.Printf("server %v disconnected due to %v\n", s.name, reason) 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 { func (s *mockServer) WipeChannel(*lnwallet.LightningChannel) error {

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"fmt"
"testing" "testing"
"time" "time"
@ -186,52 +187,63 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
Port: 18556, 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{ aliceChannelState := &channeldb.OpenChannel{
LocalChanCfg: aliceCfg, LocalChanCfg: aliceCfg,
RemoteChanCfg: bobCfg, RemoteChanCfg: bobCfg,
IdentityPub: aliceKeyPub, IdentityPub: aliceKeyPub,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
FeePerKw: feePerKw,
IsInitiator: true, IsInitiator: true,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(bobAmount),
CommitFee: commitFee,
CommitTx: *aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
RemoteCurrentRevocation: bobCommitPoint, RemoteCurrentRevocation: bobCommitPoint,
RevocationProducer: alicePreimageProducer, RevocationProducer: alicePreimageProducer,
RevocationStore: shachain.NewRevocationStore(), RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: aliceCommit,
RemoteCommitment: aliceCommit,
ShortChanID: chanID, ShortChanID: chanID,
Db: dbAlice, Db: dbAlice,
} }
if err := aliceChannelState.SyncPending(bobAddr, broadcastHeight); err != nil {
return nil, nil, nil, nil, err
}
bobChannelState := &channeldb.OpenChannel{ bobChannelState := &channeldb.OpenChannel{
LocalChanCfg: bobCfg, LocalChanCfg: bobCfg,
RemoteChanCfg: aliceCfg, RemoteChanCfg: aliceCfg,
IdentityPub: bobKeyPub, IdentityPub: bobKeyPub,
FeePerKw: feePerKw,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
IsInitiator: false, IsInitiator: false,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: lnwire.NewMSatFromSatoshis(bobAmount),
RemoteBalance: lnwire.NewMSatFromSatoshis(aliceAmount - commitFee),
CommitFee: commitFee,
CommitTx: *bobCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
RemoteCurrentRevocation: aliceCommitPoint, RemoteCurrentRevocation: aliceCommitPoint,
RevocationProducer: bobPreimageProducer, RevocationProducer: bobPreimageProducer,
RevocationStore: shachain.NewRevocationStore(), RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: bobCommit,
RemoteCommitment: bobCommit,
ShortChanID: chanID, ShortChanID: chanID,
Db: dbBob, Db: dbBob,
} }
if err := aliceChannelState.SyncPending(bobAddr, broadcastHeight); err != nil {
return nil, nil, nil, nil, err
}
if err := bobChannelState.SyncPending(aliceAddr, broadcastHeight); err != nil { if err := bobChannelState.SyncPending(aliceAddr, broadcastHeight); err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }