aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisper_test.go
blob: b29e34a5e32846e2b928af50f16af181e32de057 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package whisper

import (
    "fmt"
    "testing"
    "time"
)

func TestEvent(t *testing.T) {
    res := make(chan *Message, 1)
    whisper := New()
    id := whisper.NewIdentity()
    whisper.Watch(Filter{
        To: &id.PublicKey,
        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.Wrap(DefaultProofOfWork, Options{
        TTL:  DefaultTimeToLive,
        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")
    }
}