channeldb: update tests to reflect latest OpenChannel/HTLC API changes
This commit is contained in:
parent
5854ffb644
commit
5ad6c23848
@ -3,11 +3,11 @@ package channeldb
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/chaincfg"
|
"github.com/roasbeef/btcd/chaincfg"
|
||||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||||
"github.com/roasbeef/btcd/txscript"
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
"github.com/roasbeef/btcd/wire"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
_ "github.com/roasbeef/btcwallet/walletdb/bdb"
|
_ "github.com/roasbeef/btcwallet/walletdb/bdb"
|
||||||
@ -109,23 +108,13 @@ func makeTestDB() (*DB, func(), error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
||||||
addr, err := btcutil.NewAddressPubKey(pubKey.SerializeCompressed(), netParams)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
script, err := txscript.MultiSigScript([]*btcutil.AddressPubKey{addr, addr}, 2)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate 1000 channel updates.
|
// Simulate 1000 channel updates.
|
||||||
producer, err := shachain.NewRevocationProducerFromBytes(key[:])
|
producer, err := shachain.NewRevocationProducerFromBytes(key[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
store := shachain.NewRevocationStore()
|
store := shachain.NewRevocationStore()
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1; i++ {
|
||||||
preImage, err := producer.AtIndex(uint64(i))
|
preImage, err := producer.AtIndex(uint64(i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -139,41 +128,63 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
var obsfucator [6]byte
|
var obsfucator [6]byte
|
||||||
copy(obsfucator[:], key[:])
|
copy(obsfucator[:], key[:])
|
||||||
|
|
||||||
|
localCfg := ChannelConfig{
|
||||||
|
ChannelConstraints: ChannelConstraints{
|
||||||
|
DustLimit: btcutil.Amount(rand.Int63()),
|
||||||
|
MaxPendingAmount: btcutil.Amount(rand.Int63()),
|
||||||
|
ChanReserve: btcutil.Amount(rand.Int63()),
|
||||||
|
MinHTLC: btcutil.Amount(rand.Int63()),
|
||||||
|
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
||||||
|
},
|
||||||
|
CsvDelay: uint16(rand.Int31()),
|
||||||
|
MultiSigKey: privKey.PubKey(),
|
||||||
|
RevocationBasePoint: privKey.PubKey(),
|
||||||
|
PaymentBasePoint: privKey.PubKey(),
|
||||||
|
DelayBasePoint: privKey.PubKey(),
|
||||||
|
}
|
||||||
|
remoteCfg := ChannelConfig{
|
||||||
|
ChannelConstraints: ChannelConstraints{
|
||||||
|
DustLimit: btcutil.Amount(rand.Int63()),
|
||||||
|
MaxPendingAmount: btcutil.Amount(rand.Int63()),
|
||||||
|
ChanReserve: btcutil.Amount(rand.Int63()),
|
||||||
|
MinHTLC: btcutil.Amount(rand.Int63()),
|
||||||
|
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
||||||
|
},
|
||||||
|
CsvDelay: uint16(rand.Int31()),
|
||||||
|
MultiSigKey: privKey.PubKey(),
|
||||||
|
RevocationBasePoint: privKey.PubKey(),
|
||||||
|
PaymentBasePoint: privKey.PubKey(),
|
||||||
|
DelayBasePoint: privKey.PubKey(),
|
||||||
|
}
|
||||||
|
|
||||||
|
chanID := lnwire.NewShortChanIDFromInt(uint64(rand.Int63()))
|
||||||
|
|
||||||
return &OpenChannel{
|
return &OpenChannel{
|
||||||
IsInitiator: true,
|
ChanType: SingleFunder,
|
||||||
IsPending: true,
|
ChainHash: key,
|
||||||
ChanType: SingleFunder,
|
FundingOutpoint: *testOutpoint,
|
||||||
IdentityPub: pubKey,
|
ShortChanID: chanID,
|
||||||
ChanID: id,
|
IsInitiator: true,
|
||||||
FeePerKw: btcutil.Amount(5000),
|
IsPending: true,
|
||||||
TheirDustLimit: btcutil.Amount(200),
|
IdentityPub: pubKey,
|
||||||
OurDustLimit: btcutil.Amount(200),
|
LocalChanCfg: localCfg,
|
||||||
OurCommitKey: privKey.PubKey(),
|
RemoteChanCfg: remoteCfg,
|
||||||
TheirCommitKey: pubKey,
|
CommitFee: btcutil.Amount(rand.Int63()),
|
||||||
Capacity: btcutil.Amount(10000),
|
FeePerKw: btcutil.Amount(5000),
|
||||||
OurBalance: btcutil.Amount(3000),
|
Capacity: btcutil.Amount(10000),
|
||||||
TheirBalance: btcutil.Amount(9000),
|
LocalBalance: btcutil.Amount(3000),
|
||||||
OurCommitTx: testTx,
|
RemoteBalance: btcutil.Amount(9000),
|
||||||
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
CommitTx: *testTx,
|
||||||
RevocationProducer: producer,
|
CommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
RevocationStore: store,
|
NumConfsRequired: 4,
|
||||||
StateHintObsfucator: obsfucator,
|
RemoteCurrentRevocation: privKey.PubKey(),
|
||||||
FundingOutpoint: testOutpoint,
|
RemoteNextRevocation: privKey.PubKey(),
|
||||||
OurMultiSigKey: privKey.PubKey(),
|
RevocationProducer: producer,
|
||||||
TheirMultiSigKey: privKey.PubKey(),
|
RevocationStore: store,
|
||||||
FundingWitnessScript: script,
|
NumUpdates: 0,
|
||||||
NumConfsRequired: 4,
|
TotalSatoshisSent: 8,
|
||||||
TheirCurrentRevocation: privKey.PubKey(),
|
TotalSatoshisReceived: 2,
|
||||||
TheirCurrentRevocationHash: key,
|
Db: cdb,
|
||||||
OurDeliveryScript: script,
|
|
||||||
TheirDeliveryScript: script,
|
|
||||||
LocalCsvDelay: 5,
|
|
||||||
RemoteCsvDelay: 9,
|
|
||||||
NumUpdates: 0,
|
|
||||||
TotalSatoshisSent: 8,
|
|
||||||
TotalSatoshisReceived: 2,
|
|
||||||
CreationTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
|
||||||
Db: cdb,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +205,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
state.Htlcs = []*HTLC{
|
state.Htlcs = []*HTLC{
|
||||||
{
|
{
|
||||||
|
Signature: testSig.Serialize(),
|
||||||
Incoming: true,
|
Incoming: true,
|
||||||
Amt: 10,
|
Amt: 10,
|
||||||
RHash: key,
|
RHash: key,
|
||||||
@ -214,161 +226,58 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
|
|
||||||
// The decoded channel state should be identical to what we stored
|
// The decoded channel state should be identical to what we stored
|
||||||
// above.
|
// above.
|
||||||
if !state.IdentityPub.IsEqual(newState.IdentityPub) {
|
if !reflect.DeepEqual(state, newState) {
|
||||||
t.Fatal("their id doesn't match")
|
state.LocalChanCfg.MultiSigKey.Curve = nil
|
||||||
}
|
state.LocalChanCfg.RevocationBasePoint.Curve = nil
|
||||||
if !reflect.DeepEqual(state.ChanID, newState.ChanID) {
|
state.LocalChanCfg.PaymentBasePoint.Curve = nil
|
||||||
t.Fatal("chan id's don't match")
|
state.LocalChanCfg.DelayBasePoint.Curve = nil
|
||||||
}
|
|
||||||
if state.FeePerKw != newState.FeePerKw {
|
state.RemoteChanCfg.MultiSigKey.Curve = nil
|
||||||
t.Fatal("fee/kb doesn't match")
|
state.RemoteChanCfg.RevocationBasePoint.Curve = nil
|
||||||
}
|
state.RemoteChanCfg.PaymentBasePoint.Curve = nil
|
||||||
if state.TheirDustLimit != newState.TheirDustLimit {
|
state.RemoteChanCfg.DelayBasePoint.Curve = nil
|
||||||
t.Fatal("their dust limit doesn't match")
|
|
||||||
}
|
state.IdentityPub.Curve = nil
|
||||||
if state.OurDustLimit != newState.OurDustLimit {
|
state.RemoteNextRevocation.Curve = nil
|
||||||
t.Fatal("our dust limit doesn't match")
|
state.RemoteCurrentRevocation.Curve = nil
|
||||||
}
|
|
||||||
if state.IsInitiator != newState.IsInitiator {
|
newState.LocalChanCfg.MultiSigKey.Curve = nil
|
||||||
t.Fatal("initiator status doesn't match")
|
newState.LocalChanCfg.RevocationBasePoint.Curve = nil
|
||||||
}
|
newState.LocalChanCfg.PaymentBasePoint.Curve = nil
|
||||||
if state.ChanType != newState.ChanType {
|
newState.LocalChanCfg.DelayBasePoint.Curve = nil
|
||||||
t.Fatal("channel type doesn't match")
|
|
||||||
|
newState.RemoteChanCfg.MultiSigKey.Curve = nil
|
||||||
|
newState.RemoteChanCfg.RevocationBasePoint.Curve = nil
|
||||||
|
newState.RemoteChanCfg.PaymentBasePoint.Curve = nil
|
||||||
|
newState.RemoteChanCfg.DelayBasePoint.Curve = nil
|
||||||
|
|
||||||
|
newState.IdentityPub.Curve = nil
|
||||||
|
newState.RemoteCurrentRevocation.Curve = nil
|
||||||
|
newState.RemoteNextRevocation.Curve = nil
|
||||||
|
t.Fatalf("channel state doesn't match:: %v vs %v",
|
||||||
|
spew.Sdump(state), spew.Sdump(newState))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(state.OurCommitKey.SerializeCompressed(),
|
// We'll also test that the channel is properly able to hot swap the
|
||||||
newState.OurCommitKey.SerializeCompressed()) {
|
// next revocation for the state machine. This tests the initial
|
||||||
t.Fatal("our commit key doesn't match")
|
// post-funding revocation exchange.
|
||||||
}
|
nextRevKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||||
if !bytes.Equal(state.TheirCommitKey.SerializeCompressed(),
|
|
||||||
newState.TheirCommitKey.SerializeCompressed()) {
|
|
||||||
t.Fatal("their commit key doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
if state.Capacity != newState.Capacity {
|
|
||||||
t.Fatalf("capacity doesn't match: %v vs %v", state.Capacity,
|
|
||||||
newState.Capacity)
|
|
||||||
}
|
|
||||||
if state.OurBalance != newState.OurBalance {
|
|
||||||
t.Fatal("our balance doesn't match")
|
|
||||||
}
|
|
||||||
if state.TheirBalance != newState.TheirBalance {
|
|
||||||
t.Fatal("their balance doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
var b1, b2 bytes.Buffer
|
|
||||||
if err := state.OurCommitTx.Serialize(&b1); err != nil {
|
|
||||||
t.Fatal("unable to serialize transaction")
|
|
||||||
}
|
|
||||||
if err := newState.OurCommitTx.Serialize(&b2); err != nil {
|
|
||||||
t.Fatal("unable to serialize transaction")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
|
||||||
t.Fatal("ourCommitTx doesn't match")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(newState.OurCommitSig, state.OurCommitSig) {
|
|
||||||
t.Fatal("commit sigs don't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(roasbeef): replace with a single equal?
|
|
||||||
if !reflect.DeepEqual(state.FundingOutpoint, newState.FundingOutpoint) {
|
|
||||||
t.Fatal("funding outpoint doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Equal(state.OurMultiSigKey.SerializeCompressed(),
|
|
||||||
newState.OurMultiSigKey.SerializeCompressed()) {
|
|
||||||
t.Fatal("our multisig key doesn't match")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(state.TheirMultiSigKey.SerializeCompressed(),
|
|
||||||
newState.TheirMultiSigKey.SerializeCompressed()) {
|
|
||||||
t.Fatal("their multisig key doesn't match")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(state.FundingWitnessScript, newState.FundingWitnessScript) {
|
|
||||||
t.Fatal("redeem script doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
// The local and remote delivery scripts should be identical.
|
|
||||||
if !bytes.Equal(state.OurDeliveryScript, newState.OurDeliveryScript) {
|
|
||||||
t.Fatal("our delivery address doesn't match")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(state.TheirDeliveryScript, newState.TheirDeliveryScript) {
|
|
||||||
t.Fatal("their delivery address doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
if state.NumUpdates != newState.NumUpdates {
|
|
||||||
t.Fatalf("num updates doesn't match: %v vs %v",
|
|
||||||
state.NumUpdates, newState.NumUpdates)
|
|
||||||
}
|
|
||||||
if state.RemoteCsvDelay != newState.RemoteCsvDelay {
|
|
||||||
t.Fatalf("csv delay doesn't match: %v vs %v",
|
|
||||||
state.RemoteCsvDelay, newState.RemoteCsvDelay)
|
|
||||||
}
|
|
||||||
if state.LocalCsvDelay != newState.LocalCsvDelay {
|
|
||||||
t.Fatalf("csv delay doesn't match: %v vs %v",
|
|
||||||
state.LocalCsvDelay, newState.LocalCsvDelay)
|
|
||||||
}
|
|
||||||
if state.TotalSatoshisSent != newState.TotalSatoshisSent {
|
|
||||||
t.Fatalf("satoshis sent doesn't match: %v vs %v",
|
|
||||||
state.TotalSatoshisSent, newState.TotalSatoshisSent)
|
|
||||||
}
|
|
||||||
if state.TotalSatoshisReceived != newState.TotalSatoshisReceived {
|
|
||||||
t.Fatal("satoshis received doesn't match")
|
|
||||||
}
|
|
||||||
if state.NumConfsRequired != newState.NumConfsRequired {
|
|
||||||
t.Fatalf("num confs required doesn't match: %v, vs. %v",
|
|
||||||
state.NumConfsRequired, newState.NumConfsRequired)
|
|
||||||
}
|
|
||||||
|
|
||||||
if state.CreationTime.Unix() != newState.CreationTime.Unix() {
|
|
||||||
t.Fatal("creation time doesn't match")
|
|
||||||
}
|
|
||||||
|
|
||||||
// The local and remote producers should be identical.
|
|
||||||
var old bytes.Buffer
|
|
||||||
err = state.RevocationProducer.Encode(&old)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't convert old revocation producer to bytes: %v",
|
t.Fatalf("unable to create new private key: %v", err)
|
||||||
err)
|
}
|
||||||
|
if err := state.InsertNextRevocation(nextRevKey.PubKey()); err != nil {
|
||||||
|
t.Fatalf("unable to update revocation: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var new bytes.Buffer
|
openChannels, err = cdb.FetchOpenChannels(state.IdentityPub)
|
||||||
err = newState.RevocationProducer.Encode(&new)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't convert new revocation producer to bytes: %v",
|
t.Fatalf("unable to fetch open channel: %v", err)
|
||||||
err)
|
|
||||||
}
|
}
|
||||||
|
updatedChan := openChannels[0]
|
||||||
|
|
||||||
if !bytes.Equal(old.Bytes(), new.Bytes()) {
|
// Ensure that the revocation was set properly.
|
||||||
t.Fatal("local producer don't match")
|
if !nextRevKey.PubKey().IsEqual(updatedChan.RemoteNextRevocation) {
|
||||||
}
|
t.Fatalf("next revocation wasn't updated")
|
||||||
|
|
||||||
old.Reset()
|
|
||||||
new.Reset()
|
|
||||||
|
|
||||||
err = state.RevocationStore.Encode(&old)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to serialize old remote store: %v", err)
|
|
||||||
}
|
|
||||||
err = newState.RevocationStore.Encode(&new)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to serialize new remote store: %v", err)
|
|
||||||
}
|
|
||||||
if !bytes.Equal(old.Bytes(), new.Bytes()) {
|
|
||||||
t.Fatal("remote store don't match")
|
|
||||||
}
|
|
||||||
if !newState.TheirCurrentRevocation.IsEqual(state.TheirCurrentRevocation) {
|
|
||||||
t.Fatal("revocation keys don't match")
|
|
||||||
}
|
|
||||||
if !bytes.Equal(newState.TheirCurrentRevocationHash[:], state.TheirCurrentRevocationHash[:]) {
|
|
||||||
t.Fatal("revocation hashes don't match")
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(state.Htlcs[0], newState.Htlcs[0]) {
|
|
||||||
t.Fatalf("htlcs don't match: %v vs %v", spew.Sdump(state.Htlcs[0]),
|
|
||||||
spew.Sdump(newState.Htlcs[0]))
|
|
||||||
}
|
|
||||||
if !bytes.Equal(state.StateHintObsfucator[:],
|
|
||||||
newState.StateHintObsfucator[:]) {
|
|
||||||
t.Fatal("obsfuctators don't match")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally to wrap up the test, delete the state of the channel within
|
// Finally to wrap up the test, delete the state of the channel within
|
||||||
@ -376,7 +285,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
// written state, and creates a small "summary" elsewhere within the
|
// written state, and creates a small "summary" elsewhere within the
|
||||||
// database.
|
// database.
|
||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *state.ChanID,
|
ChanPoint: state.FundingOutpoint,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
SettledBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
TimeLockedBalance: btcutil.Amount(10000),
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
@ -439,12 +348,13 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
incoming = true
|
incoming = true
|
||||||
}
|
}
|
||||||
htlc := &HTLC{
|
htlc := &HTLC{
|
||||||
|
Signature: testSig.Serialize(),
|
||||||
Incoming: incoming,
|
Incoming: incoming,
|
||||||
Amt: 10,
|
Amt: 10,
|
||||||
RHash: key,
|
RHash: key,
|
||||||
RefundTimeout: i,
|
RefundTimeout: i,
|
||||||
RevocationDelay: i + 2,
|
RevocationDelay: i + 2,
|
||||||
OutputIndex: uint16(i * 3),
|
OutputIndex: int32(i * 3),
|
||||||
}
|
}
|
||||||
htlcs = append(htlcs, htlc)
|
htlcs = append(htlcs, htlc)
|
||||||
htlcAmt += htlc.Amt
|
htlcAmt += htlc.Amt
|
||||||
@ -455,7 +365,7 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
// Additionally, modify the signature and commitment transaction.
|
// Additionally, modify the signature and commitment transaction.
|
||||||
newSequence := uint32(129498)
|
newSequence := uint32(129498)
|
||||||
newSig := bytes.Repeat([]byte{3}, 71)
|
newSig := bytes.Repeat([]byte{3}, 71)
|
||||||
newTx := channel.OurCommitTx.Copy()
|
newTx := channel.CommitTx.Copy()
|
||||||
newTx.TxIn[0].Sequence = newSequence
|
newTx.TxIn[0].Sequence = newSequence
|
||||||
delta := &ChannelDelta{
|
delta := &ChannelDelta{
|
||||||
LocalBalance: btcutil.Amount(1e8),
|
LocalBalance: btcutil.Amount(1e8),
|
||||||
@ -476,21 +386,21 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch updated channel: %v", err)
|
t.Fatalf("unable to fetch updated channel: %v", err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(updatedChannel[0].OurCommitSig, newSig) {
|
if !bytes.Equal(updatedChannel[0].CommitSig, newSig) {
|
||||||
t.Fatalf("sigs don't match %x vs %x",
|
t.Fatalf("sigs don't match %x vs %x",
|
||||||
updatedChannel[0].OurCommitSig, newSig)
|
updatedChannel[0].CommitSig, newSig)
|
||||||
}
|
}
|
||||||
if updatedChannel[0].OurCommitTx.TxIn[0].Sequence != newSequence {
|
if updatedChannel[0].CommitTx.TxIn[0].Sequence != newSequence {
|
||||||
t.Fatalf("sequence numbers don't match: %v vs %v",
|
t.Fatalf("sequence numbers don't match: %v vs %v",
|
||||||
updatedChannel[0].OurCommitTx.TxIn[0].Sequence, newSequence)
|
updatedChannel[0].CommitTx.TxIn[0].Sequence, newSequence)
|
||||||
}
|
}
|
||||||
if updatedChannel[0].OurBalance != delta.LocalBalance {
|
if updatedChannel[0].LocalBalance != delta.LocalBalance {
|
||||||
t.Fatalf("local balances don't match: %v vs %v",
|
t.Fatalf("local balances don't match: %v vs %v",
|
||||||
updatedChannel[0].OurBalance, delta.LocalBalance)
|
updatedChannel[0].LocalBalance, delta.LocalBalance)
|
||||||
}
|
}
|
||||||
if updatedChannel[0].TheirBalance != delta.RemoteBalance {
|
if updatedChannel[0].RemoteBalance != delta.RemoteBalance {
|
||||||
t.Fatalf("remote balances don't match: %v vs %v",
|
t.Fatalf("remote balances don't match: %v vs %v",
|
||||||
updatedChannel[0].TheirBalance, delta.RemoteBalance)
|
updatedChannel[0].RemoteBalance, delta.RemoteBalance)
|
||||||
}
|
}
|
||||||
if updatedChannel[0].NumUpdates != uint64(delta.UpdateNum) {
|
if updatedChannel[0].NumUpdates != uint64(delta.UpdateNum) {
|
||||||
t.Fatalf("update # doesn't match: %v vs %v",
|
t.Fatalf("update # doesn't match: %v vs %v",
|
||||||
@ -518,8 +428,12 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
// needed to rectify any fishy behavior by the remote party. Modify the
|
// needed to rectify any fishy behavior by the remote party. Modify the
|
||||||
// current uncollapsed revocation state to simulate a state transition
|
// current uncollapsed revocation state to simulate a state transition
|
||||||
// by the remote party.
|
// by the remote party.
|
||||||
newRevocation := bytes.Repeat([]byte{9}, 32)
|
channel.RemoteCurrentRevocation = channel.RemoteNextRevocation
|
||||||
copy(channel.TheirCurrentRevocationHash[:], newRevocation)
|
newPriv, err := btcec.NewPrivateKey(btcec.S256())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to generate key: %v", err)
|
||||||
|
}
|
||||||
|
channel.RemoteNextRevocation = newPriv.PubKey()
|
||||||
if err := channel.AppendToRevocationLog(delta); err != nil {
|
if err := channel.AppendToRevocationLog(delta); err != nil {
|
||||||
t.Fatalf("unable to append to revocation log: %v", err)
|
t.Fatalf("unable to append to revocation log: %v", err)
|
||||||
}
|
}
|
||||||
@ -604,14 +518,16 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch updated channel: %v", err)
|
t.Fatalf("unable to fetch updated channel: %v", err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(updatedChannel[0].TheirCurrentRevocationHash[:],
|
if !channel.RemoteCurrentRevocation.IsEqual(updatedChannel[0].RemoteCurrentRevocation) {
|
||||||
newRevocation) {
|
t.Fatalf("revocation state was not synced")
|
||||||
t.Fatal("revocation state wasn't synced!")
|
}
|
||||||
|
if !channel.RemoteNextRevocation.IsEqual(updatedChannel[0].RemoteNextRevocation) {
|
||||||
|
t.Fatalf("revocation state was not synced")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now attempt to delete the channel from the database.
|
// Now attempt to delete the channel from the database.
|
||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *channel.ChanID,
|
ChanPoint: channel.FundingOutpoint,
|
||||||
RemotePub: channel.IdentityPub,
|
RemotePub: channel.IdentityPub,
|
||||||
SettledBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
TimeLockedBalance: btcutil.Amount(10000),
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
@ -689,7 +605,7 @@ func TestFetchPendingChannels(t *testing.T) {
|
|||||||
TxIndex: 10,
|
TxIndex: 10,
|
||||||
TxPosition: 15,
|
TxPosition: 15,
|
||||||
}
|
}
|
||||||
err = cdb.MarkChannelAsOpen(pendingChannels[0].ChanID, chanOpenLoc)
|
err = cdb.MarkChannelAsOpen(&pendingChannels[0].FundingOutpoint, 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)
|
||||||
}
|
}
|
||||||
@ -756,19 +672,20 @@ func TestFetchClosedChannels(t *testing.T) {
|
|||||||
TxIndex: 10,
|
TxIndex: 10,
|
||||||
TxPosition: 15,
|
TxPosition: 15,
|
||||||
}
|
}
|
||||||
if err := cdb.MarkChannelAsOpen(state.ChanID, chanOpenLoc); err != nil {
|
err = cdb.MarkChannelAsOpen(&state.FundingOutpoint, chanOpenLoc)
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("unable to mark channel as open: %v", err)
|
t.Fatalf("unable to mark channel as open: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, close the channel by including a close channel summary in the
|
// Next, close the channel by including a close channel summary in the
|
||||||
// database.
|
// database.
|
||||||
summary := &ChannelCloseSummary{
|
summary := &ChannelCloseSummary{
|
||||||
ChanPoint: *state.ChanID,
|
ChanPoint: state.FundingOutpoint,
|
||||||
ClosingTXID: rev,
|
ClosingTXID: rev,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
SettledBalance: state.OurBalance,
|
SettledBalance: state.LocalBalance,
|
||||||
TimeLockedBalance: state.OurBalance + 10000,
|
TimeLockedBalance: state.LocalBalance + 10000,
|
||||||
CloseType: ForceClose,
|
CloseType: ForceClose,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
}
|
}
|
||||||
@ -805,7 +722,8 @@ func TestFetchClosedChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark the channel as fully closed
|
// Mark the channel as fully closed
|
||||||
if err := cdb.MarkChanFullyClosed(state.ChanID); err != nil {
|
err = cdb.MarkChanFullyClosed(&state.FundingOutpoint)
|
||||||
|
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