channeldb: update tests to respect new API's

This commit is contained in:
Olaoluwa Osuntokun 2017-11-09 20:56:04 -08:00
parent 0178920cba
commit da7a5f7c4e
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -7,6 +7,7 @@ import (
"net"
"os"
"reflect"
"runtime"
"testing"
"github.com/davecgh/go-spew/spew"
@ -164,23 +165,34 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
IsInitiator: true,
IsPending: true,
IdentityPub: pubKey,
Capacity: btcutil.Amount(10000),
LocalChanCfg: localCfg,
RemoteChanCfg: remoteCfg,
TotalMSatSent: 8,
TotalMSatReceived: 2,
LocalCommitment: ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.MilliSatoshi(9000),
RemoteBalance: lnwire.MilliSatoshi(3000),
CommitFee: btcutil.Amount(rand.Int63()),
FeePerKw: btcutil.Amount(5000),
Capacity: btcutil.Amount(10000),
CommitTx: testTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
},
RemoteCommitment: ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.MilliSatoshi(3000),
RemoteBalance: lnwire.MilliSatoshi(9000),
CommitTx: *testTx,
CommitFee: btcutil.Amount(rand.Int63()),
FeePerKw: btcutil.Amount(5000),
CommitTx: testTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
},
NumConfsRequired: 4,
RemoteCurrentRevocation: privKey.PubKey(),
RemoteNextRevocation: privKey.PubKey(),
RevocationProducer: producer,
RevocationStore: store,
NumUpdates: 0,
TotalMSatSent: 8,
TotalMSatReceived: 2,
Db: cdb,
}, nil
}
@ -200,7 +212,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
if err != nil {
t.Fatalf("unable to create channel state: %v", err)
}
state.Htlcs = []*HTLC{
state.LocalCommitment.Htlcs = []HTLC{
{
Signature: testSig.Serialize(),
Incoming: true,
@ -210,6 +222,16 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
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 {
t.Fatalf("unable to save and serialize channel state: %v", err)
}
@ -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) {
t.Parallel()
@ -603,7 +633,7 @@ func TestFetchPendingChannels(t *testing.T) {
TxIndex: 10,
TxPosition: 15,
}
err = cdb.MarkChannelAsOpen(&pendingChannels[0].FundingOutpoint, chanOpenLoc)
err = pendingChannels[0].MarkAsOpen(chanOpenLoc)
if err != nil {
t.Fatalf("unable to mark channel as open: %v", err)
}
@ -670,7 +700,7 @@ func TestFetchClosedChannels(t *testing.T) {
TxIndex: 10,
TxPosition: 15,
}
err = cdb.MarkChannelAsOpen(&state.FundingOutpoint, chanOpenLoc)
err = state.MarkAsOpen(chanOpenLoc)
if err != nil {
t.Fatalf("unable to mark channel as open: %v", err)
}
@ -682,8 +712,8 @@ func TestFetchClosedChannels(t *testing.T) {
ClosingTXID: rev,
RemotePub: state.IdentityPub,
Capacity: state.Capacity,
SettledBalance: state.LocalBalance.ToSatoshis(),
TimeLockedBalance: state.LocalBalance.ToSatoshis() + 10000,
SettledBalance: state.LocalCommitment.LocalBalance.ToSatoshis(),
TimeLockedBalance: state.RemoteCommitment.LocalBalance.ToSatoshis() + 10000,
CloseType: ForceClose,
IsPending: true,
}
@ -719,7 +749,7 @@ func TestFetchClosedChannels(t *testing.T) {
spew.Sdump(summary), spew.Sdump(closed[0]))
}
// Mark the channel as fully closed
// Mark the channel as fully closed.
err = cdb.MarkChanFullyClosed(&state.FundingOutpoint)
if err != nil {
t.Fatalf("failed fully closing channel: %v", err)