plugeth/whisper/whisper_test.go
Péter Szilágyi 7d8ce53eca whisper: polish the messages, fix some bugs, tests
Bugs fixed:
  - Use randomly generated flags as the spec required.
  - During envelope opening check the first bit only for signature.
2015-04-10 15:53:21 +03:00

39 lines
702 B
Go

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(DefaultPow, 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")
}
}