github.com/decred/dcrlnd@v0.7.6/channeldb/migration_01_to_11/graph_test.go (about)

     1  package migration_01_to_11
     2  
     3  import (
     4  	"encoding/hex"
     5  	"image/color"
     6  	prand "math/rand"
     7  	"net"
     8  	"time"
     9  
    10  	"github.com/decred/dcrd/dcrec/secp256k1/v4"
    11  	"github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
    12  	lnwire "github.com/decred/dcrlnd/channeldb/migration/lnwire21"
    13  )
    14  
    15  func modNScalar(b []byte) *secp256k1.ModNScalar {
    16  	var m secp256k1.ModNScalar
    17  	m.SetByteSlice(b)
    18  	return &m
    19  }
    20  
    21  var (
    22  	testAddr = &net.TCPAddr{IP: (net.IP)([]byte{0xA, 0x0, 0x0, 0x1}),
    23  		Port: 9000}
    24  	anotherAddr, _ = net.ResolveTCPAddr("tcp",
    25  		"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
    26  	testAddrs = []net.Addr{testAddr, anotherAddr}
    27  	rBytes, _ = hex.DecodeString("63724406601629180062774974542967536251589935445068131219452686511677818569431")
    28  	sBytes, _ = hex.DecodeString("18801056069249825825291287104931333862866033135609736119018462340006816851118")
    29  	testSig   = ecdsa.NewSignature(
    30  		modNScalar(rBytes),
    31  		modNScalar(sBytes),
    32  	)
    33  
    34  	testFeatures = lnwire.NewFeatureVector(nil, nil)
    35  )
    36  
    37  func createLightningNode(db *DB, priv *secp256k1.PrivateKey) (*LightningNode, error) {
    38  	updateTime := prand.Int63()
    39  
    40  	pub := priv.PubKey().SerializeCompressed()
    41  	n := &LightningNode{
    42  		HaveNodeAnnouncement: true,
    43  		AuthSigBytes:         testSig.Serialize(),
    44  		LastUpdate:           time.Unix(updateTime, 0),
    45  		Color:                color.RGBA{1, 2, 3, 0},
    46  		Alias:                "kek" + string(pub),
    47  		Features:             testFeatures,
    48  		Addresses:            testAddrs,
    49  		db:                   db,
    50  	}
    51  	copy(n.PubKeyBytes[:], pub)
    52  
    53  	return n, nil
    54  }
    55  
    56  func createTestVertex(db *DB) (*LightningNode, error) {
    57  	priv, err := secp256k1.GeneratePrivateKey()
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  
    62  	return createLightningNode(db, priv)
    63  }