mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
autopilot/agent_test: ensure directives use unique keys
This commit ensures that the mock attachment directives use unique keys, ensuring that they aren't skipped due to already having pending connection requests. The tests fail when they're all the same since they collide in the pendingConns map.
This commit is contained in:
parent
7d9483c20d
commit
2b578e06fc
@ -345,6 +345,7 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||||||
// attempt to open a channel.
|
// attempt to open a channel.
|
||||||
var fakeDirective = AttachmentDirective{
|
var fakeDirective = AttachmentDirective{
|
||||||
PeerKey: self,
|
PeerKey: self,
|
||||||
|
NodeID: NewNodeID(self),
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@ -726,9 +727,16 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
// requests attachment directives. We'll generate 5 mock directives so
|
// requests attachment directives. We'll generate 5 mock directives so
|
||||||
// it can progress within its loop.
|
// it can progress within its loop.
|
||||||
directives := make([]AttachmentDirective, numChans)
|
directives := make([]AttachmentDirective, numChans)
|
||||||
|
nodeKeys := make(map[NodeID]struct{})
|
||||||
for i := 0; i < numChans; i++ {
|
for i := 0; i < numChans; i++ {
|
||||||
|
pub, err := randKey()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to generate key: %v", err)
|
||||||
|
}
|
||||||
|
nodeID := NewNodeID(pub)
|
||||||
directives[i] = AttachmentDirective{
|
directives[i] = AttachmentDirective{
|
||||||
PeerKey: self,
|
PeerKey: pub,
|
||||||
|
NodeID: nodeID,
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@ -736,6 +744,7 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
nodeKeys[nodeID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
wg = sync.WaitGroup{}
|
wg = sync.WaitGroup{}
|
||||||
@ -767,11 +776,13 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
t.Fatalf("invalid chan amt: expected %v, got %v",
|
t.Fatalf("invalid chan amt: expected %v, got %v",
|
||||||
btcutil.SatoshiPerBitcoin, openChan.amt)
|
btcutil.SatoshiPerBitcoin, openChan.amt)
|
||||||
}
|
}
|
||||||
if !openChan.target.IsEqual(self) {
|
nodeID := NewNodeID(openChan.target)
|
||||||
t.Fatalf("unexpected key: expected %x, got %x",
|
_, ok := nodeKeys[nodeID]
|
||||||
self.SerializeCompressed(),
|
if !ok {
|
||||||
openChan.target.SerializeCompressed())
|
t.Fatalf("unexpected key: %v, not found",
|
||||||
|
nodeID)
|
||||||
}
|
}
|
||||||
|
delete(nodeKeys, nodeID)
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("channel not opened in time")
|
t.Fatalf("channel not opened in time")
|
||||||
}
|
}
|
||||||
@ -873,8 +884,13 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||||||
// it can progress within its loop.
|
// it can progress within its loop.
|
||||||
directives := make([]AttachmentDirective, numChans)
|
directives := make([]AttachmentDirective, numChans)
|
||||||
for i := 0; i < numChans; i++ {
|
for i := 0; i < numChans; i++ {
|
||||||
|
pub, err := randKey()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to generate key: %v", err)
|
||||||
|
}
|
||||||
directives[i] = AttachmentDirective{
|
directives[i] = AttachmentDirective{
|
||||||
PeerKey: self,
|
PeerKey: pub,
|
||||||
|
NodeID: NewNodeID(pub),
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@ -1015,6 +1031,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
nodeID := NewNodeID(nodeKey)
|
nodeID := NewNodeID(nodeKey)
|
||||||
nodeDirective := AttachmentDirective{
|
nodeDirective := AttachmentDirective{
|
||||||
PeerKey: nodeKey,
|
PeerKey: nodeKey,
|
||||||
|
NodeID: nodeID,
|
||||||
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@ -1073,7 +1090,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
if req.chans[0].Node != nodeID {
|
if req.chans[0].Node != nodeID {
|
||||||
t.Fatalf("wrong node ID: expected %x, got %x",
|
t.Fatalf("wrong node ID: expected %x, got %x",
|
||||||
req.chans[0].Node[:], nodeID)
|
nodeID, req.chans[0].Node[:])
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("need more chans wasn't queried in time")
|
t.Fatalf("need more chans wasn't queried in time")
|
||||||
|
Loading…
Reference in New Issue
Block a user