aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisper_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-14 17:12:47 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-14 17:12:47 +0800
commit5205b2f19b9173580f9a9e727d74e202b8dd0f67 (patch)
treea43057307d4fb8c704953c6a82507bc5f473aaf1 /whisper/whisper_test.go
parent4af7743663fa3e444668b90878f64d0df4316deb (diff)
downloaddexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar.gz
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar.bz2
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar.lz
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar.xz
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.tar.zst
dexon-5205b2f19b9173580f9a9e727d74e202b8dd0f67.zip
whisper: fix anonymous broadcast drop, add broadcast tests
Diffstat (limited to 'whisper/whisper_test.go')
-rw-r--r--whisper/whisper_test.go70
1 files changed, 63 insertions, 7 deletions
diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go
index 5c29956cf..3f903a9dc 100644
--- a/whisper/whisper_test.go
+++ b/whisper/whisper_test.go
@@ -7,7 +7,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/nat"
)
@@ -83,7 +82,7 @@ func TestSelfMessage(t *testing.T) {
},
})
// Send a dummy message to oneself
- msg := NewMessage([]byte("hello whisper"))
+ msg := NewMessage([]byte("self whisper"))
envelope, err := msg.Wrap(DefaultProofOfWork, Options{
From: self,
To: &self.PublicKey,
@@ -104,9 +103,6 @@ func TestSelfMessage(t *testing.T) {
}
func TestDirectMessage(t *testing.T) {
- glog.SetV(6)
- glog.SetToStderr(true)
-
// Start the sender-recipient cluster
cluster, err := startNodes(2)
if err != nil {
@@ -129,7 +125,7 @@ func TestDirectMessage(t *testing.T) {
},
})
// Send a dummy message from the sender
- msg := NewMessage([]byte("hello whisper"))
+ msg := NewMessage([]byte("direct whisper"))
envelope, err := msg.Wrap(DefaultProofOfWork, Options{
From: senderId,
To: &recipientId.PublicKey,
@@ -139,7 +135,7 @@ func TestDirectMessage(t *testing.T) {
t.Fatalf("failed to wrap message: %v", err)
}
if err := sender.Send(envelope); err != nil {
- t.Fatalf("failed to send direct message: %v", err)
+ t.Fatalf("failed to send direct message: %v", err)
}
// Wait for an arrival or a timeout
select {
@@ -148,3 +144,63 @@ func TestDirectMessage(t *testing.T) {
t.Fatalf("direct message receive timeout")
}
}
+
+func TestAnonymousBroadcast(t *testing.T) {
+ testBroadcast(true, t)
+}
+
+func TestIdentifiedBroadcast(t *testing.T) {
+ testBroadcast(false, t)
+}
+
+func testBroadcast(anonymous bool, t *testing.T) {
+ // Start the single sender multi recipient cluster
+ cluster, err := startNodes(3)
+ if err != nil {
+ t.Fatalf("failed to boot test cluster: %v", err)
+ }
+ defer stopNodes(cluster)
+
+ sender := cluster[0].client
+ targets := make([]*Whisper, len(cluster)-1)
+ for i, node := range cluster[1:] {
+ targets[i] = node.client
+ if !anonymous {
+ targets[i].NewIdentity()
+ }
+ }
+ // Watch for arriving messages on the recipients
+ dones := make([]chan struct{}, len(targets))
+ for i := 0; i < len(targets); i++ {
+ done := make(chan struct{}) // need for the closure
+ dones[i] = done
+
+ targets[i].Watch(Filter{
+ Topics: NewTopicsFromStrings("broadcast topic"),
+ Fn: func(msg *Message) {
+ close(done)
+ },
+ })
+ }
+ // Send a dummy message from the sender
+ msg := NewMessage([]byte("broadcast whisper"))
+ envelope, err := msg.Wrap(DefaultProofOfWork, Options{
+ Topics: NewTopicsFromStrings("broadcast topic"),
+ TTL: DefaultTimeToLive,
+ })
+ if err != nil {
+ t.Fatalf("failed to wrap message: %v", err)
+ }
+ if err := sender.Send(envelope); err != nil {
+ t.Fatalf("failed to send broadcast message: %v", err)
+ }
+ // Wait for an arrival on each recipient, or timeouts
+ timeout := time.After(time.Second)
+ for _, done := range dones {
+ select {
+ case <-done:
+ case <-timeout:
+ t.Fatalf("broadcast message receive timeout")
+ }
+ }
+}