From 7e54a9c07f10ff16aabfe8bd3944c9309d4efc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 10 Apr 2015 13:46:08 +0300 Subject: whisper: rename test file according to Go style --- whisper/message_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ whisper/messages_test.go | 50 ------------------------------------------------ 2 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 whisper/message_test.go delete mode 100644 whisper/messages_test.go diff --git a/whisper/message_test.go b/whisper/message_test.go new file mode 100644 index 000000000..93caa31b3 --- /dev/null +++ b/whisper/message_test.go @@ -0,0 +1,50 @@ +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 { + t.Error(err) + t.FailNow() + } + + if !bytes.Equal(msg1.Payload, data) { + t.Error("encryption error. data did not match") + } +} diff --git a/whisper/messages_test.go b/whisper/messages_test.go deleted file mode 100644 index 93caa31b3..000000000 --- a/whisper/messages_test.go +++ /dev/null @@ -1,50 +0,0 @@ -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 { - t.Error(err) - t.FailNow() - } - - if !bytes.Equal(msg1.Payload, data) { - t.Error("encryption error. data did not match") - } -} -- cgit v1.2.3