aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv6/peer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/whisperv6/peer_test.go')
-rw-r--r--whisper/whisperv6/peer_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/whisper/whisperv6/peer_test.go b/whisper/whisperv6/peer_test.go
index 0c9b38090..fe31922cb 100644
--- a/whisper/whisperv6/peer_test.go
+++ b/whisper/whisperv6/peer_test.go
@@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/nat"
+ "github.com/ethereum/go-ethereum/rlp"
)
var keys = []string{
@@ -507,3 +508,63 @@ func waitForServersToStart(t *testing.T) {
}
t.Fatalf("Failed to start all the servers, running: %d", started)
}
+
+//two generic whisper node handshake
+func TestPeerHandshakeWithTwoFullNode(t *testing.T) {
+ w1 := Whisper{}
+ p1 := newPeer(&w1, p2p.NewPeer(discover.NodeID{}, "test", []p2p.Cap{}), &rwStub{[]interface{}{ProtocolVersion, uint64(123), make([]byte, BloomFilterSize), false}})
+ err := p1.handshake()
+ if err != nil {
+ t.Fatal()
+ }
+}
+
+//two generic whisper node handshake. one don't send light flag
+func TestHandshakeWithOldVersionWithoutLightModeFlag(t *testing.T) {
+ w1 := Whisper{}
+ p1 := newPeer(&w1, p2p.NewPeer(discover.NodeID{}, "test", []p2p.Cap{}), &rwStub{[]interface{}{ProtocolVersion, uint64(123), make([]byte, BloomFilterSize)}})
+ err := p1.handshake()
+ if err != nil {
+ t.Fatal()
+ }
+}
+
+//two light nodes handshake. restriction disabled
+func TestTwoLightPeerHandshakeRestrictionOff(t *testing.T) {
+ w1 := Whisper{}
+ w1.settings.Store(restrictConnectionBetweenLightClientsIdx, false)
+ w1.SetLightClientMode(true)
+ p1 := newPeer(&w1, p2p.NewPeer(discover.NodeID{}, "test", []p2p.Cap{}), &rwStub{[]interface{}{ProtocolVersion, uint64(123), make([]byte, BloomFilterSize), true}})
+ err := p1.handshake()
+ if err != nil {
+ t.FailNow()
+ }
+}
+
+//two light nodes handshake. restriction enabled
+func TestTwoLightPeerHandshakeError(t *testing.T) {
+ w1 := Whisper{}
+ w1.settings.Store(restrictConnectionBetweenLightClientsIdx, true)
+ w1.SetLightClientMode(true)
+ p1 := newPeer(&w1, p2p.NewPeer(discover.NodeID{}, "test", []p2p.Cap{}), &rwStub{[]interface{}{ProtocolVersion, uint64(123), make([]byte, BloomFilterSize), true}})
+ err := p1.handshake()
+ if err == nil {
+ t.FailNow()
+ }
+}
+
+type rwStub struct {
+ payload []interface{}
+}
+
+func (stub *rwStub) ReadMsg() (p2p.Msg, error) {
+ size, r, err := rlp.EncodeToReader(stub.payload)
+ if err != nil {
+ return p2p.Msg{}, err
+ }
+ return p2p.Msg{Code: statusCode, Size: uint32(size), Payload: r}, nil
+}
+
+func (stub *rwStub) WriteMsg(m p2p.Msg) error {
+ return nil
+}