MCPcopy
hub / github.com/canopy-network/canopy / TestGetRandom

Function TestGetRandom

p2p/book_test.go:9–22  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestGetRandom(t *testing.T) {
10 n1, n2 := newTestP2PNode(t), newTestP2PNode(t)
11 require.Nil(t, n1.book.GetRandom())
12 require.Nil(t, n1.book.GetRandom())
13 n1.book.Add(&BookPeer{Address: &lib.PeerAddress{
14 PublicKey: n2.pub,
15 NetAddress: "",
16 PeerMeta: &lib.PeerMeta{ChainId: 1},
17 }})
18 got := n1.book.GetRandom()
19 require.Equal(t, got.Address.PublicKey, n2.pub)
20 got = n1.book.GetRandom()
21 require.Equal(t, got.Address.PublicKey, n2.pub)
22}
23
24func TestGetAll(t *testing.T) {
25 n1, n2, n3 := newTestP2PNode(t), newTestP2PNode(t), newTestP2PNode(t)

Callers

nothing calls this directly

Calls 4

newTestP2PNodeFunction · 0.85
GetRandomMethod · 0.80
EqualMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected