aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisper_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-13 05:23:42 +0800
committerobscuren <geffobscura@gmail.com>2014-12-13 05:23:42 +0800
commita17a1f9208f858601f6660dbd7f1b77dd9a3f3d9 (patch)
tree6f6f61cfd2dd41cc20d1bcae9604c1f09e07e42d /whisper/whisper_test.go
parented1538248f2e7a44680d22a052a234a31b736624 (diff)
downloaddexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.gz
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.bz2
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.lz
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.xz
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.zst
dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.zip
Implemented watching using filter package
* Added filters / watches * Removed event dep
Diffstat (limited to 'whisper/whisper_test.go')
-rw-r--r--whisper/whisper_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go
new file mode 100644
index 000000000..107cb8c97
--- /dev/null
+++ b/whisper/whisper_test.go
@@ -0,0 +1,47 @@
+package whisper
+
+import (
+ "fmt"
+ "testing"
+ "time"
+)
+
+func TestKeyManagement(t *testing.T) {
+ whisper := New()
+
+ key := whisper.NewIdentity()
+ if !whisper.HasIdentity(key) {
+ t.Error("expected whisper to have identify")
+ }
+}
+
+func TestEvent(t *testing.T) {
+ res := make(chan *Message, 1)
+ whisper := New()
+ id := whisper.NewIdentity()
+ whisper.Watch(Filter{
+ To: id,
+ Fn: func(msg *Message) {
+ res <- msg
+ },
+ })
+
+ msg := NewMessage([]byte(fmt.Sprintf("Hello world. This is whisper-go. Incase you're wondering; the time is %v", time.Now())))
+ envelope, err := msg.Seal(DefaultPow, Opts{
+ Ttl: DefaultTtl,
+ From: id,
+ To: &id.PublicKey,
+ })
+ if err != nil {
+ fmt.Println(err)
+ t.FailNow()
+ }
+
+ tick := time.NewTicker(time.Second)
+ whisper.postEvent(envelope)
+ select {
+ case <-res:
+ case <-tick.C:
+ t.Error("did not receive message")
+ }
+}