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

Function TestPeerSetAddGetDel

p2p/set_test.go:13–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestPeerSetAddGetDel(t *testing.T) {
14 n1, n2 := newTestP2PNode(t), newTestP2PNode(t)
15 require.True(t, len(n1.PeerSet.m) == 0)
16 expected := &lib.PeerInfo{
17 Address: &lib.PeerAddress{
18 PublicKey: n2.pub,
19 NetAddress: "pipe",
20 },
21 IsOutbound: true,
22 IsMustConnect: true,
23 IsTrusted: true,
24 Reputation: 10,
25 }
26 c1, c2 := net.Pipe()
27 defer c2.Close()
28 require.NoError(t, n1.PeerSet.Add(&Peer{PeerInfo: expected, conn: newTestMultiConnMock(t, n2.pub, c1, n1.P2P)}))
29 require.True(t, len(n1.PeerSet.m) == 1)
30 got, err := n1.PeerSet.GetPeerInfo(n2.pub)
31 require.NoError(t, err)
32 require.Equal(t, *expected, *got)
33 err = n1.PeerSet.Remove(n2.pub, 0)
34 require.NoError(t, err)
35 err = n1.PeerSet.Remove(n2.pub, 0)
36 require.Error(t, err)
37 _, err = n1.PeerSet.GetPeerInfo(n2.pub)
38 require.Error(t, err)
39 require.True(t, len(n1.PeerSet.m) == 0)
40}
41
42func TestUpdateMustConnects(t *testing.T) {
43 n1, n2, n3 := newTestP2PNode(t), newTestP2PNode(t), newTestP2PNode(t)

Callers

nothing calls this directly

Calls 8

newTestP2PNodeFunction · 0.85
newTestMultiConnMockFunction · 0.85
GetPeerInfoMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65
AddMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected