aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/envelope_test.go
blob: ed1f08365187ef4be0cae0e52a39c865ab92da29 (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
package whisper

import (
    "bytes"
    "testing"
)

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)
    }
    if opened.Sent != message.Sent {
        t.Fatalf("send time mismatch: have %d, want %d", opened.Sent, message.Sent)
    }

    if opened.Hash != envelope.Hash() {
        t.Fatalf("message hash mismatch: have 0x%x, want 0x%x", opened.Hash, envelope.Hash())
    }
}