diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-20 09:34:12 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-20 09:34:12 +0800 |
commit | 3983dd2428137211f84f299f9ce8690c22f50afd (patch) | |
tree | 3a2dc53b365e6f377fc82a3514150d1297fe549c /whisper/whisper_test.go | |
parent | 7daa8c2f6eb25511c6a54ad420709af911fc6748 (diff) | |
parent | 0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 (diff) | |
download | dexon-3983dd2428137211f84f299f9ce8690c22f50afd.tar.gz dexon-3983dd2428137211f84f299f9ce8690c22f50afd.tar.zst dexon-3983dd2428137211f84f299f9ce8690c22f50afd.zip |
Merge branch 'release/v0.7.10'
Diffstat (limited to 'whisper/whisper_test.go')
-rw-r--r-- | whisper/whisper_test.go | 47 |
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") + } +} |