channeldb: update tests to respect new API's

This commit is contained in:
Olaoluwa Osuntokun committed 2017-11-10 19:50:49 -08:00
1 parent 0178920cba
commit da7a5f7c4e
1 file changed
+56 -26
+56 -26
View File
@@ -7,6 +7,7 @@ import (
"net" "net"
"os" "os"
"reflect" "reflect"
"runtime"
"testing" "testing"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
@@ -157,30 +158,41 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63())) chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63()))
return &OpenChannel{ return &OpenChannel{
ChanType: SingleFunder, ChanType: SingleFunder,
ChainHash: key, ChainHash: key,
FundingOutpoint: *testOutpoint, FundingOutpoint: *testOutpoint,
ShortChanID: chanID, ShortChanID: chanID,
IsInitiator: true, IsInitiator: true,
IsPending: true, IsPending: true,
IdentityPub: pubKey, IdentityPub: pubKey,
LocalChanCfg: localCfg, Capacity: btcutil.Amount(10000),
RemoteChanCfg: remoteCfg, LocalChanCfg: localCfg,
CommitFee: btcutil.Amount(rand.Int63()), RemoteChanCfg: remoteCfg,
FeePerKw: btcutil.Amount(5000), TotalMSatSent: 8,
Capacity: btcutil.Amount(10000), TotalMSatReceived: 2,
LocalBalance: lnwire.MilliSatoshi(3000), LocalCommitment: ChannelCommitment{
RemoteBalance: lnwire.MilliSatoshi(9000), CommitHeight: 0,
CommitTx: *testTx, LocalBalance: lnwire.MilliSatoshi(9000),
CommitSig: bytes.Repeat([]byte{1}, 71), RemoteBalance: lnwire.MilliSatoshi(3000),
CommitFee: btcutil.Amount(rand.Int63()),
FeePerKw: btcutil.Amount(5000),
CommitTx: testTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
},
RemoteCommitment: ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.MilliSatoshi(3000),
RemoteBalance: lnwire.MilliSatoshi(9000),
CommitFee: btcutil.Amount(rand.Int63()),
FeePerKw: btcutil.Amount(5000),
CommitTx: testTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
},
NumConfsRequired: 4, NumConfsRequired: 4,
RemoteCurrentRevocation: privKey.PubKey(), RemoteCurrentRevocation: privKey.PubKey(),
RemoteNextRevocation: privKey.PubKey(), RemoteNextRevocation: privKey.PubKey(),
RevocationProducer: producer, RevocationProducer: producer,
RevocationStore: store, RevocationStore: store,
NumUpdates: 0,
TotalMSatSent: 8,
TotalMSatReceived: 2,
Db: cdb, Db: cdb,
}, nil }, nil
} }
@@ -200,14 +212,24 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to create channel state: %v", err) t.Fatalf("unable to create channel state: %v", err)
} }
state.Htlcs = []*HTLC{ state.LocalCommitment.Htlcs = []HTLC{
{ {
Signature: testSig.Serialize(), Signature: testSig.Serialize(),
Incoming: true, Incoming: true,
Amt: 10, Amt: 10,
RHash: key, RHash: key,
RefundTimeout: 1, RefundTimeout: 1,
OnionBlob: []byte("onionblob"), OnionBlob: []byte("onionblob"),
},
}
state.RemoteCommitment.Htlcs = []HTLC{
{
Signature: testSig.Serialize(),
Incoming: false,
Amt: 10,
RHash: key,
RefundTimeout: 1,
OnionBlob: []byte("onionblob"),
}, },
} }
if err := state.FullSync(); err != nil { if err := state.FullSync(); err != nil {
@@ -314,6 +336,14 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
} }
} }
func assertCommitmentEqual(t *testing.T, a, b *ChannelCommitment) {
if !reflect.DeepEqual(a, b) {
_, _, line, _ := runtime.Caller(1)
t.Fatalf("line %v: commitments don't match: %v vs %v",
line, spew.Sdump(a), spew.Sdump(b))
}
}
func TestChannelStateTransition(t *testing.T) { func TestChannelStateTransition(t *testing.T) {
t.Parallel() t.Parallel()
@@ -603,7 +633,7 @@ func TestFetchPendingChannels(t *testing.T) {
TxIndex: 10, TxIndex: 10,
TxPosition: 15, TxPosition: 15,
} }
err = cdb.MarkChannelAsOpen(&pendingChannels[0].FundingOutpoint, chanOpenLoc) err = pendingChannels[0].MarkAsOpen(chanOpenLoc)
if err != nil { if err != nil {
t.Fatalf("unable to mark channel as open: %v", err) t.Fatalf("unable to mark channel as open: %v", err)
} }
@@ -670,7 +700,7 @@ func TestFetchClosedChannels(t *testing.T) {
TxIndex: 10, TxIndex: 10,
TxPosition: 15, TxPosition: 15,
} }
err = cdb.MarkChannelAsOpen(&state.FundingOutpoint, chanOpenLoc) err = state.MarkAsOpen(chanOpenLoc)
if err != nil { if err != nil {
t.Fatalf("unable to mark channel as open: %v", err) t.Fatalf("unable to mark channel as open: %v", err)
} }
@@ -682,8 +712,8 @@ func TestFetchClosedChannels(t *testing.T) {
ClosingTXID: rev, ClosingTXID: rev,
RemotePub: state.IdentityPub, RemotePub: state.IdentityPub,
Capacity: state.Capacity, Capacity: state.Capacity,
SettledBalance: state.LocalBalance.ToSatoshis(), SettledBalance: state.LocalCommitment.LocalBalance.ToSatoshis(),
TimeLockedBalance: state.LocalBalance.ToSatoshis() + 10000, TimeLockedBalance: state.RemoteCommitment.LocalBalance.ToSatoshis() + 10000,
CloseType: ForceClose, CloseType: ForceClose,
IsPending: true, IsPending: true,
} }
@@ -719,7 +749,7 @@ func TestFetchClosedChannels(t *testing.T) {
spew.Sdump(summary), spew.Sdump(closed[0])) spew.Sdump(summary), spew.Sdump(closed[0]))
} }
// Mark the channel as fully closed // Mark the channel as fully closed.
err = cdb.MarkChanFullyClosed(&state.FundingOutpoint) err = cdb.MarkChanFullyClosed(&state.FundingOutpoint)
if err != nil { if err != nil {
t.Fatalf("failed fully closing channel: %v", err) t.Fatalf("failed fully closing channel: %v", err)