mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
Update peer_test.go
This commit is contained in:
parent
3765f28a1b
commit
d27ab3ee4d
1 changed files with 17 additions and 0 deletions
|
|
@ -266,6 +266,23 @@ func TestNewPeer(t *testing.T) {
|
||||||
p.Disconnect(DiscAlreadyConnected) // Should not hang
|
p.Disconnect(DiscAlreadyConnected) // Should not hang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCapsReturnsCopy verifies that Caps() returns a copy of the internal slice.
|
||||||
|
func TestCapsReturnsCopy(t *testing.T) {
|
||||||
|
id := randomID()
|
||||||
|
name := "nodename"
|
||||||
|
caps := []Cap{{"a", 1}, {"b", 2}}
|
||||||
|
p := NewPeer(id, name, caps)
|
||||||
|
|
||||||
|
returned := p.Caps()
|
||||||
|
// Modify the returned slice.
|
||||||
|
returned[0] = Cap{"modified", 99}
|
||||||
|
|
||||||
|
// Ensure the internal slice was not affected.
|
||||||
|
if reflect.DeepEqual(returned, p.Caps()) {
|
||||||
|
t.Fatal("Caps() should return a copy, not a reference to the internal slice")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMatchProtocols(t *testing.T) {
|
func TestMatchProtocols(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Remote []Cap
|
Remote []Cap
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue