fix up advertise

(cherry picked from commit 8195c97590)
This commit is contained in:
tycho garen
2022-06-14 16:49:44 -04:00
parent ca1237667f
commit 8adc97e631
2 changed files with 13 additions and 5 deletions
+1 -1
View File
@@ -905,7 +905,7 @@ OUTER:
return addresses
}
return addresses[:limit-1]
return addresses[:limit]
}
// Subscribe subscribes to peer updates. The caller must consume the peer
+12 -4
View File
@@ -1779,10 +1779,18 @@ func TestPeerManager_Advertise(t *testing.T) {
// Asking for 0 addresses should return, well, 0.
require.Empty(t, peerManager.Advertise(aID, 0))
// Asking for 2 addresses should get the highest-rated ones, i.e. a.
require.ElementsMatch(t, []p2p.NodeAddress{
aTCP, aMem,
}, peerManager.Advertise(dID, 2))
// Asking for 2 addresses should get two addresses
// the content of the list when there are two
addrs := peerManager.Advertise(dID, 2)
require.Len(t, addrs, 2)
for _, addr := range addrs {
if dID == addr.NodeID {
t.Fatal("never advertise self")
}
if cID == addr.NodeID {
t.Fatal("should not have returned the lowest ranked peer")
}
}
}
func TestPeerManager_Advertise_Self(t *testing.T) {