diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 02:06:24 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 02:06:24 +0800 |
commit | bab78bbeb691d95bdd0222435af0c11cb3485a79 (patch) | |
tree | 804c9689546ce362a2862b00bb4e76160052f5d6 /whisper/whisper_test.go | |
parent | 7a79428278412ab1f73708af51bce063b000b7a7 (diff) | |
parent | 1360f027d9e365242466ca346b2b56f421729d91 (diff) | |
download | go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar.gz go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar.bz2 go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar.lz go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar.xz go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.tar.zst go-tangerine-bab78bbeb691d95bdd0222435af0c11cb3485a79.zip |
Merge branch 'tests' of github.com:ethereum/go-ethereum into tests
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") + } +} |