2015-04-20 11:56:38 +00:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2015-04-21 08:43:11 +00:00
|
|
|
"time"
|
2015-04-20 11:56:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEnvelopeOpen(t *testing.T) {
|
|
|
|
payload := []byte("hello world")
|
|
|
|
message := NewMessage(payload)
|
|
|
|
|
|
|
|
envelope, err := message.Wrap(DefaultPoW, Options{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to wrap message: %v", err)
|
|
|
|
}
|
|
|
|
opened, err := envelope.Open(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to open envelope: %v.", err)
|
|
|
|
}
|
|
|
|
if opened.Flags != message.Flags {
|
|
|
|
t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags)
|
|
|
|
}
|
|
|
|
if bytes.Compare(opened.Signature, message.Signature) != 0 {
|
|
|
|
t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature)
|
|
|
|
}
|
|
|
|
if bytes.Compare(opened.Payload, message.Payload) != 0 {
|
|
|
|
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload)
|
|
|
|
}
|
2015-04-21 08:43:11 +00:00
|
|
|
if opened.Sent.Unix() != message.Sent.Unix() {
|
2015-04-20 11:56:38 +00:00
|
|
|
t.Fatalf("send time mismatch: have %d, want %d", opened.Sent, message.Sent)
|
|
|
|
}
|
2015-04-21 08:43:11 +00:00
|
|
|
if opened.TTL/time.Second != DefaultTTL/time.Second {
|
|
|
|
t.Fatalf("message TTL mismatch: have %v, want %v", opened.TTL, DefaultTTL)
|
|
|
|
}
|
2015-04-20 11:56:38 +00:00
|
|
|
|
|
|
|
if opened.Hash != envelope.Hash() {
|
|
|
|
t.Fatalf("message hash mismatch: have 0x%x, want 0x%x", opened.Hash, envelope.Hash())
|
|
|
|
}
|
|
|
|
}
|