discovery: update tests to match latest API+verification changes

This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 23:17:41 -07:00
parent e268658f0e
commit 69b3b96deb
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 21 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package discovery package discovery
import ( import (
"encoding/hex"
"fmt" "fmt"
"net" "net"
"sync" "sync"
@ -158,7 +159,8 @@ func (r *mockGraphSource) ForEachNode(func(node *channeldb.LightningNode) error)
return nil return nil
} }
func (r *mockGraphSource) ForAllOutgoingChannels(cb func(c *channeldb.ChannelEdgePolicy) error) error { func (r *mockGraphSource) ForAllOutgoingChannels(cb func(i *channeldb.ChannelEdgeInfo,
c *channeldb.ChannelEdgePolicy) error) error {
return nil return nil
} }
@ -312,7 +314,11 @@ func createNodeAnnouncement(priv *btcec.PrivateKey) (*lnwire.NodeAnnouncement,
error) { error) {
var err error var err error
alias := lnwire.NewAlias("kek" + string(priv.Serialize())) k := hex.EncodeToString(priv.Serialize())
alias, err := lnwire.NewNodeAlias("kek" + k[:10])
if err != nil {
return nil, err
}
a := &lnwire.NodeAnnouncement{ a := &lnwire.NodeAnnouncement{
Timestamp: uint32(prand.Int31()), Timestamp: uint32(prand.Int31()),
@ -339,7 +345,7 @@ func createUpdateAnnouncement(blockHeight uint32) (*lnwire.ChannelUpdate, error)
}, },
Timestamp: uint32(prand.Int31()), Timestamp: uint32(prand.Int31()),
TimeLockDelta: uint16(prand.Int63()), TimeLockDelta: uint16(prand.Int63()),
HtlcMinimumMsat: uint64(prand.Int63()), HtlcMinimumMsat: lnwire.MilliSatoshi(prand.Int63()),
FeeRate: uint32(prand.Int31()), FeeRate: uint32(prand.Int31()),
BaseFee: uint32(prand.Int31()), BaseFee: uint32(prand.Int31()),
} }
@ -367,6 +373,7 @@ func createRemoteChannelAnnouncement(blockHeight uint32) (*lnwire.ChannelAnnounc
NodeID2: nodeKeyPub2, NodeID2: nodeKeyPub2,
BitcoinKey1: bitcoinKeyPub1, BitcoinKey1: bitcoinKeyPub1,
BitcoinKey2: bitcoinKeyPub2, BitcoinKey2: bitcoinKeyPub2,
Features: testFeatures,
} }
pub := nodeKeyPriv1.PubKey() pub := nodeKeyPriv1.PubKey()
@ -381,15 +388,15 @@ func createRemoteChannelAnnouncement(blockHeight uint32) (*lnwire.ChannelAnnounc
return nil, err return nil, err
} }
hash := chainhash.DoubleHashB(nodeKeyPub1.SerializeCompressed()) pub = bitcoinKeyPriv1.PubKey()
a.BitcoinSig1, err = bitcoinKeyPriv1.Sign(hash) signer = mockSigner{bitcoinKeyPriv1}
if err != nil { if a.BitcoinSig1, err = SignAnnouncement(&signer, pub, a); err != nil {
return nil, err return nil, err
} }
hash = chainhash.DoubleHashB(nodeKeyPub2.SerializeCompressed()) pub = bitcoinKeyPriv2.PubKey()
a.BitcoinSig2, err = bitcoinKeyPriv2.Sign(hash) signer = mockSigner{bitcoinKeyPriv2}
if err != nil { if a.BitcoinSig2, err = SignAnnouncement(&signer, pub, a); err != nil {
return nil, err return nil, err
} }
@ -432,7 +439,7 @@ func createTestCtx(startHeight uint32) (*testCtx, func(), error) {
TrickleDelay: trickleDelay, TrickleDelay: trickleDelay,
ProofMatureDelta: proofMatureDelta, ProofMatureDelta: proofMatureDelta,
DB: db, DB: db,
}) }, nodeKeyPub1)
if err != nil { if err != nil {
cleanUpDb() cleanUpDb()
return nil, nil, fmt.Errorf("unable to create router %v", err) return nil, nil, fmt.Errorf("unable to create router %v", err)
@ -770,7 +777,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
// between two nodes. // between two nodes.
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn, localKey) err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn, localKey)
if err != nil { if err != nil {
t.Fatalf("unable to process :%v", err) t.Fatalf("unable to process: %v", err)
} }
select { select {
@ -781,7 +788,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn, localKey) err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn, localKey)
if err != nil { if err != nil {
t.Fatalf("unable to process :%v", err) t.Fatalf("unable to process: %v", err)
} }
select { select {
case <-ctx.broadcastedMessage: case <-ctx.broadcastedMessage:
@ -791,7 +798,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
err = <-ctx.gossiper.ProcessRemoteAnnouncement(batch.chanUpdAnn, remoteKey) err = <-ctx.gossiper.ProcessRemoteAnnouncement(batch.chanUpdAnn, remoteKey)
if err != nil { if err != nil {
t.Fatalf("unable to process :%v", err) t.Fatalf("unable to process: %v", err)
} }
select { select {
case <-ctx.broadcastedMessage: case <-ctx.broadcastedMessage:
@ -803,7 +810,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
// the channel announcement. // the channel announcement.
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn, localKey) err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn, localKey)
if err != nil { if err != nil {
t.Fatalf("unable to process :%v", err) t.Fatalf("unable to process: %v", err)
} }
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {