lnwallet: update createTestChannels to adhere to new channeldb API's

This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 14:26:38 -08:00
parent 7f667e2dbc
commit 097e1c0f5c
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -7,6 +7,8 @@ import (
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
"reflect"
"runtime"
"testing" "testing"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
@ -290,42 +292,54 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
estimator := &StaticFeeEstimator{24, 6} estimator := &StaticFeeEstimator{24, 6}
feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000) feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000)
commitFee := calcStaticFee(0) commitFee := calcStaticFee(0)
aliceCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
CommitFee: commitFee,
FeePerKw: feePerKw,
CommitTx: aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
}
bobCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - 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,
CommitFee: commitFee,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
FeePerKw: feePerKw,
IsInitiator: true, IsInitiator: true,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
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,
Db: dbAlice, Db: dbAlice,
} }
bobChannelState := &channeldb.OpenChannel{ bobChannelState := &channeldb.OpenChannel{
LocalChanCfg: bobCfg, LocalChanCfg: bobCfg,
RemoteChanCfg: aliceCfg, RemoteChanCfg: aliceCfg,
IdentityPub: bobKeyPub, IdentityPub: bobKeyPub,
FeePerKw: feePerKw,
CommitFee: commitFee,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
IsInitiator: false, IsInitiator: false,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - 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,
Db: dbBob, Db: dbBob,
} }
@ -345,6 +359,13 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
return nil, nil, nil, err return nil, nil, nil, err
} }
if err := channelAlice.channelState.FullSync(); err != nil {
return nil, nil, nil, err
}
if err := channelBob.channelState.FullSync(); err != nil {
return nil, nil, nil, err
}
cleanUpFunc := func() { cleanUpFunc := func() {
os.RemoveAll(bobPath) os.RemoveAll(bobPath)
os.RemoveAll(alicePath) os.RemoveAll(alicePath)