routing: add private key attribute in router test

This commit is contained in:
bluetegu
2018-12-10 07:32:21 -05:00
committed by yyforyongyu
parent 9062ab1671
commit fc113c7508
3 changed files with 50 additions and 13 deletions

View File

@@ -118,11 +118,14 @@ type testGraph struct {
// testNode represents a node within the test graph above. We skip certain
// information such as the node's IP address as that information isn't needed
// for our tests.
// for our tests. Private keys are optional. If set, they should be consistent
// with the public key. The private key is used to sign error messages
// sent from the node.
type testNode struct {
Source bool `json:"source"`
PubKey string `json:"pubkey"`
Alias string `json:"alias"`
Source bool `json:"source"`
PubKey string `json:"pubkey"`
PrivKey string `json:"privkey"`
Alias string `json:"alias"`
}
// testChan represents the JSON version of a payment channel. This struct
@@ -200,6 +203,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
}
aliasMap := make(map[string]route.Vertex)
privKeyMap := make(map[string]*btcec.PrivateKey)
var source *channeldb.LightningNode
// First we insert all the nodes within the graph as vertexes.
@@ -230,6 +234,33 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
// alias map for easy lookup.
aliasMap[node.Alias] = dbNode.PubKeyBytes
// private keys are needed for signing error messages. If set
// check the consistency with the public key.
privBytes, err := hex.DecodeString(node.PrivKey)
if err != nil {
return nil, err
}
if len(privBytes) > 0 {
key, derivedPub := btcec.PrivKeyFromBytes(
btcec.S256(), privBytes,
)
if !bytes.Equal(
pubBytes, derivedPub.SerializeCompressed(),
) {
return nil, fmt.Errorf("%s public key and "+
"private key are inconsistent\n"+
"got %x\nwant %x\n",
node.Alias,
derivedPub.SerializeCompressed(),
pubBytes,
)
}
privKeyMap[node.Alias] = key
}
// If the node is tagged as the source, then we create a
// pointer to is so we can mark the source in the graph
// properly.
@@ -240,7 +271,8 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
// node can be the source in the graph.
if source != nil {
return nil, errors.New("JSON is invalid " +
"multiple nodes are tagged as the source")
"multiple nodes are tagged as the " +
"source")
}
source = dbNode
@@ -327,9 +359,10 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
}
return &testGraphInstance{
graph: graph,
cleanUp: cleanUp,
aliasMap: aliasMap,
graph: graph,
cleanUp: cleanUp,
aliasMap: aliasMap,
privKeyMap: privKeyMap,
}, nil
}