aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/rlpx_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/rlpx_test.go')
-rw-r--r--p2p/rlpx_test.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/p2p/rlpx_test.go b/p2p/rlpx_test.go
index 7ae800774..64172217b 100644
--- a/p2p/rlpx_test.go
+++ b/p2p/rlpx_test.go
@@ -18,6 +18,7 @@ package p2p
import (
"bytes"
+ "crypto/ecdsa"
"crypto/rand"
"errors"
"fmt"
@@ -34,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/sha3"
- "github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -80,9 +80,9 @@ func TestEncHandshake(t *testing.T) {
func testEncHandshake(token []byte) error {
type result struct {
- side string
- id discover.NodeID
- err error
+ side string
+ pubkey *ecdsa.PublicKey
+ err error
}
var (
prv0, _ = crypto.GenerateKey()
@@ -97,14 +97,12 @@ func testEncHandshake(token []byte) error {
defer func() { output <- r }()
defer fd0.Close()
- dest := &discover.Node{ID: discover.PubkeyID(&prv1.PublicKey)}
- r.id, r.err = c0.doEncHandshake(prv0, dest)
+ r.pubkey, r.err = c0.doEncHandshake(prv0, &prv1.PublicKey)
if r.err != nil {
return
}
- id1 := discover.PubkeyID(&prv1.PublicKey)
- if r.id != id1 {
- r.err = fmt.Errorf("remote ID mismatch: got %v, want: %v", r.id, id1)
+ if !reflect.DeepEqual(r.pubkey, &prv1.PublicKey) {
+ r.err = fmt.Errorf("remote pubkey mismatch: got %v, want: %v", r.pubkey, &prv1.PublicKey)
}
}()
go func() {
@@ -112,13 +110,12 @@ func testEncHandshake(token []byte) error {
defer func() { output <- r }()
defer fd1.Close()
- r.id, r.err = c1.doEncHandshake(prv1, nil)
+ r.pubkey, r.err = c1.doEncHandshake(prv1, nil)
if r.err != nil {
return
}
- id0 := discover.PubkeyID(&prv0.PublicKey)
- if r.id != id0 {
- r.err = fmt.Errorf("remote ID mismatch: got %v, want: %v", r.id, id0)
+ if !reflect.DeepEqual(r.pubkey, &prv0.PublicKey) {
+ r.err = fmt.Errorf("remote ID mismatch: got %v, want: %v", r.pubkey, &prv0.PublicKey)
}
}()
@@ -150,12 +147,12 @@ func testEncHandshake(token []byte) error {
func TestProtocolHandshake(t *testing.T) {
var (
prv0, _ = crypto.GenerateKey()
- node0 = &discover.Node{ID: discover.PubkeyID(&prv0.PublicKey), IP: net.IP{1, 2, 3, 4}, TCP: 33}
- hs0 = &protoHandshake{Version: 3, ID: node0.ID, Caps: []Cap{{"a", 0}, {"b", 2}}}
+ pub0 = crypto.FromECDSAPub(&prv0.PublicKey)[1:]
+ hs0 = &protoHandshake{Version: 3, ID: pub0, Caps: []Cap{{"a", 0}, {"b", 2}}}
prv1, _ = crypto.GenerateKey()
- node1 = &discover.Node{ID: discover.PubkeyID(&prv1.PublicKey), IP: net.IP{5, 6, 7, 8}, TCP: 44}
- hs1 = &protoHandshake{Version: 3, ID: node1.ID, Caps: []Cap{{"c", 1}, {"d", 3}}}
+ pub1 = crypto.FromECDSAPub(&prv1.PublicKey)[1:]
+ hs1 = &protoHandshake{Version: 3, ID: pub1, Caps: []Cap{{"c", 1}, {"d", 3}}}
wg sync.WaitGroup
)
@@ -170,13 +167,13 @@ func TestProtocolHandshake(t *testing.T) {
defer wg.Done()
defer fd0.Close()
rlpx := newRLPX(fd0)
- remid, err := rlpx.doEncHandshake(prv0, node1)
+ rpubkey, err := rlpx.doEncHandshake(prv0, &prv1.PublicKey)
if err != nil {
t.Errorf("dial side enc handshake failed: %v", err)
return
}
- if remid != node1.ID {
- t.Errorf("dial side remote id mismatch: got %v, want %v", remid, node1.ID)
+ if !reflect.DeepEqual(rpubkey, &prv1.PublicKey) {
+ t.Errorf("dial side remote pubkey mismatch: got %v, want %v", rpubkey, &prv1.PublicKey)
return
}
@@ -196,13 +193,13 @@ func TestProtocolHandshake(t *testing.T) {
defer wg.Done()
defer fd1.Close()
rlpx := newRLPX(fd1)
- remid, err := rlpx.doEncHandshake(prv1, nil)
+ rpubkey, err := rlpx.doEncHandshake(prv1, nil)
if err != nil {
t.Errorf("listen side enc handshake failed: %v", err)
return
}
- if remid != node0.ID {
- t.Errorf("listen side remote id mismatch: got %v, want %v", remid, node0.ID)
+ if !reflect.DeepEqual(rpubkey, &prv0.PublicKey) {
+ t.Errorf("listen side remote pubkey mismatch: got %v, want %v", rpubkey, &prv0.PublicKey)
return
}