aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/messages_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
committerobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
commit3983dd2428137211f84f299f9ce8690c22f50afd (patch)
tree3a2dc53b365e6f377fc82a3514150d1297fe549c /whisper/messages_test.go
parent7daa8c2f6eb25511c6a54ad420709af911fc6748 (diff)
parent0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 (diff)
downloadgo-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.gz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.bz2
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.lz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.xz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.zst
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.zip
Merge branch 'release/v0.7.10'vv0.7.10
Diffstat (limited to 'whisper/messages_test.go')
-rw-r--r--whisper/messages_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/whisper/messages_test.go b/whisper/messages_test.go
new file mode 100644
index 000000000..cba103011
--- /dev/null
+++ b/whisper/messages_test.go
@@ -0,0 +1,51 @@
+package whisper
+
+import (
+ "bytes"
+ "crypto/elliptic"
+ "fmt"
+ "testing"
+
+ "github.com/ethereum/go-ethereum/crypto"
+)
+
+func TestSign(t *testing.T) {
+ prv, _ := crypto.GenerateKey()
+ msg := NewMessage([]byte("hello world"))
+ msg.sign(prv)
+
+ pubKey := msg.Recover()
+ p1 := elliptic.Marshal(crypto.S256(), prv.PublicKey.X, prv.PublicKey.Y)
+ p2 := elliptic.Marshal(crypto.S256(), pubKey.X, pubKey.Y)
+
+ if !bytes.Equal(p1, p2) {
+ t.Error("recovered pub key did not match")
+ }
+}
+
+func TestMessageEncryptDecrypt(t *testing.T) {
+ prv1, _ := crypto.GenerateKey()
+ prv2, _ := crypto.GenerateKey()
+
+ data := []byte("hello world")
+ msg := NewMessage(data)
+ envelope, err := msg.Seal(DefaultPow, Opts{
+ From: prv1,
+ To: &prv2.PublicKey,
+ })
+ if err != nil {
+ fmt.Println(err)
+ t.FailNow()
+ }
+
+ msg1, err := envelope.Open(prv2)
+ if err != nil {
+ fmt.Println(err)
+ t.FailNow()
+ }
+
+ if !bytes.Equal(msg1.Payload, data) {
+ fmt.Println("encryption error. data did not match")
+ t.FailNow()
+ }
+}