channeldb: update tests to respect new API's
This commit is contained in:
parent
0178920cba
commit
da7a5f7c4e
@ -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"
|
||||||
@ -164,23 +165,34 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
IdentityPub: pubKey,
|
IdentityPub: pubKey,
|
||||||
|
Capacity: btcutil.Amount(10000),
|
||||||
LocalChanCfg: localCfg,
|
LocalChanCfg: localCfg,
|
||||||
RemoteChanCfg: remoteCfg,
|
RemoteChanCfg: remoteCfg,
|
||||||
|
TotalMSatSent: 8,
|
||||||
|
TotalMSatReceived: 2,
|
||||||
|
LocalCommitment: ChannelCommitment{
|
||||||
|
CommitHeight: 0,
|
||||||
|
LocalBalance: lnwire.MilliSatoshi(9000),
|
||||||
|
RemoteBalance: lnwire.MilliSatoshi(3000),
|
||||||
CommitFee: btcutil.Amount(rand.Int63()),
|
CommitFee: btcutil.Amount(rand.Int63()),
|
||||||
FeePerKw: btcutil.Amount(5000),
|
FeePerKw: btcutil.Amount(5000),
|
||||||
Capacity: btcutil.Amount(10000),
|
CommitTx: testTx,
|
||||||
|
CommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
|
},
|
||||||
|
RemoteCommitment: ChannelCommitment{
|
||||||
|
CommitHeight: 0,
|
||||||
LocalBalance: lnwire.MilliSatoshi(3000),
|
LocalBalance: lnwire.MilliSatoshi(3000),
|
||||||
RemoteBalance: lnwire.MilliSatoshi(9000),
|
RemoteBalance: lnwire.MilliSatoshi(9000),
|
||||||
CommitTx: *testTx,
|
CommitFee: btcutil.Amount(rand.Int63()),
|
||||||
|
FeePerKw: btcutil.Amount(5000),
|
||||||
|
CommitTx: testTx,
|
||||||
CommitSig: bytes.Repeat([]byte{1}, 71),
|
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,7 +212,7 @@ 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,
|
||||||
@ -210,6 +222,16 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
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 {
|
||||||
t.Fatalf("unable to save and serialize channel state: %v", err)
|
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) {
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user