2014-12-12 15:23:42 -06:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEvent(t *testing.T) {
|
|
|
|
res := make(chan *Message, 1)
|
|
|
|
whisper := New()
|
|
|
|
id := whisper.NewIdentity()
|
|
|
|
whisper.Watch(Filter{
|
2015-02-05 17:00:59 -06:00
|
|
|
To: &id.PublicKey,
|
2014-12-12 15:23:42 -06:00
|
|
|
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())))
|
2015-04-10 08:52:01 -05:00
|
|
|
envelope, err := msg.Wrap(DefaultProofOfWork, Options{
|
2015-04-10 07:53:21 -05:00
|
|
|
TTL: DefaultTimeToLive,
|
2014-12-12 15:23:42 -06:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|