From 097e1c0f5c23de2f078218afc7f8e3058b76bea7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 10 Nov 2017 14:26:38 -0800 Subject: [PATCH] lnwallet: update createTestChannels to adhere to new channeldb API's --- lnwallet/channel_test.go | 45 +++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 958c1362..a568f5f3 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -7,6 +7,8 @@ import ( "io/ioutil" "math/rand" "os" + "reflect" + "runtime" "testing" "github.com/davecgh/go-spew/spew" @@ -290,42 +292,54 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan estimator := &StaticFeeEstimator{24, 6} feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000) 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{ LocalChanCfg: aliceCfg, RemoteChanCfg: bobCfg, IdentityPub: aliceKeyPub, - CommitFee: commitFee, FundingOutpoint: *prevOut, ChanType: channeldb.SingleFunder, - FeePerKw: feePerKw, IsInitiator: true, Capacity: channelCapacity, - LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), - RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal), - CommitTx: *aliceCommitTx, - CommitSig: bytes.Repeat([]byte{1}, 71), RemoteCurrentRevocation: bobCommitPoint, RevocationProducer: alicePreimageProducer, RevocationStore: shachain.NewRevocationStore(), + LocalCommitment: aliceCommit, + RemoteCommitment: aliceCommit, Db: dbAlice, } bobChannelState := &channeldb.OpenChannel{ LocalChanCfg: bobCfg, RemoteChanCfg: aliceCfg, IdentityPub: bobKeyPub, - FeePerKw: feePerKw, - CommitFee: commitFee, FundingOutpoint: *prevOut, ChanType: channeldb.SingleFunder, IsInitiator: false, Capacity: channelCapacity, - LocalBalance: lnwire.NewMSatFromSatoshis(channelBal), - RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee), - CommitTx: *bobCommitTx, - CommitSig: bytes.Repeat([]byte{1}, 71), RemoteCurrentRevocation: aliceCommitPoint, RevocationProducer: bobPreimageProducer, RevocationStore: shachain.NewRevocationStore(), + LocalCommitment: bobCommit, + RemoteCommitment: bobCommit, Db: dbBob, } @@ -345,6 +359,13 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan 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() { os.RemoveAll(bobPath) os.RemoveAll(alicePath)