routing/pathfind_test: allow custom node features
This commit allows custom node features to be populated in specific test instances. For consistency, we auto-populate an empty feature vector for nodes that have nil feature vectors before writing them to the database.
This commit is contained in:
parent
618810394c
commit
bd66c0d34e
@ -318,6 +318,7 @@ type testChannelPolicy struct {
|
|||||||
LastUpdate time.Time
|
LastUpdate time.Time
|
||||||
Disabled bool
|
Disabled bool
|
||||||
Direction bool
|
Direction bool
|
||||||
|
Features *lnwire.FeatureVector
|
||||||
}
|
}
|
||||||
|
|
||||||
type testChannelEnd struct {
|
type testChannelEnd struct {
|
||||||
@ -409,7 +410,9 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
|||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
|
|
||||||
nodeIndex := byte(0)
|
nodeIndex := byte(0)
|
||||||
addNodeWithAlias := func(alias string) (*channeldb.LightningNode, error) {
|
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
||||||
|
*channeldb.LightningNode, error) {
|
||||||
|
|
||||||
keyBytes := make([]byte, 32)
|
keyBytes := make([]byte, 32)
|
||||||
keyBytes = []byte{
|
keyBytes = []byte{
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -421,13 +424,17 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
|||||||
privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(),
|
privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(),
|
||||||
keyBytes)
|
keyBytes)
|
||||||
|
|
||||||
|
if features == nil {
|
||||||
|
features = lnwire.EmptyFeatureVector()
|
||||||
|
}
|
||||||
|
|
||||||
dbNode := &channeldb.LightningNode{
|
dbNode := &channeldb.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
Features: testFeatures,
|
Features: features,
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
||||||
@ -447,7 +454,7 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the source node.
|
// Add the source node.
|
||||||
dbNode, err := addNodeWithAlias(source)
|
dbNode, err := addNodeWithAlias(source, lnwire.EmptyFeatureVector())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -461,12 +468,19 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
|||||||
nextUnassignedChannelID := uint64(100000)
|
nextUnassignedChannelID := uint64(100000)
|
||||||
|
|
||||||
for _, testChannel := range testChannels {
|
for _, testChannel := range testChannels {
|
||||||
for _, alias := range []string{
|
for _, node := range []*testChannelEnd{
|
||||||
testChannel.Node1.Alias, testChannel.Node2.Alias} {
|
testChannel.Node1, testChannel.Node2} {
|
||||||
|
|
||||||
_, exists := aliasMap[alias]
|
_, exists := aliasMap[node.Alias]
|
||||||
if !exists {
|
if !exists {
|
||||||
_, err := addNodeWithAlias(alias)
|
var features *lnwire.FeatureVector
|
||||||
|
if node.testChannelPolicy != nil {
|
||||||
|
features =
|
||||||
|
node.testChannelPolicy.Features
|
||||||
|
}
|
||||||
|
_, err := addNodeWithAlias(
|
||||||
|
node.Alias, features,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user