aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-21 01:13:46 +0800
committerobscuren <geffobscura@gmail.com>2015-02-21 01:13:46 +0800
commitbd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca (patch)
tree46ab5943fd5e26198067aeec4a44287452eb2a32 /crypto/crypto_test.go
parent771bfe9e78f9952002a71cccc8d41c8c544fdfcb (diff)
parentd586a633ff005ac01c9f1eb33552d147cf6c883e (diff)
downloaddexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.gz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.bz2
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.lz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.xz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.zst
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.zip
Merge branch 'release/0.9.0'
Diffstat (limited to 'crypto/crypto_test.go')
-rw-r--r--crypto/crypto_test.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go
index af62a02a2..c68856622 100644
--- a/crypto/crypto_test.go
+++ b/crypto/crypto_test.go
@@ -3,7 +3,12 @@ package crypto
import (
"bytes"
"encoding/hex"
+ "fmt"
"testing"
+ "time"
+
+ "github.com/ethereum/go-ethereum/crypto/secp256k1"
+ "github.com/ethereum/go-ethereum/ethutil"
)
// These tests are sanity checks.
@@ -13,7 +18,7 @@ import (
func TestSha3(t *testing.T) {
msg := []byte("abc")
exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
- checkhash(t, "Sha3-256", Sha3, msg, exp)
+ checkhash(t, "Sha3-256", func(in []byte) []byte { return Sha3(in) }, msg, exp)
}
func TestSha256(t *testing.T) {
@@ -34,3 +39,36 @@ func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte
t.Errorf("hash %s returned wrong result.\ngot: %x\nwant: %x", name, sum, exp)
}
}
+
+func BenchmarkSha3(b *testing.B) {
+ a := []byte("hello world")
+ amount := 1000000
+ start := time.Now()
+ for i := 0; i < amount; i++ {
+ Sha3(a)
+ }
+
+ fmt.Println(amount, ":", time.Since(start))
+}
+
+func Test0Key(t *testing.T) {
+ t.Skip()
+ key := ethutil.Hex2Bytes("1111111111111111111111111111111111111111111111111111111111111111")
+
+ p, err := secp256k1.GeneratePubKey(key)
+ addr := Sha3(p[1:])[12:]
+ fmt.Printf("%x\n", p)
+ fmt.Printf("%v %x\n", err, addr)
+}
+
+func TestInvalidSign(t *testing.T) {
+ _, err := Sign(make([]byte, 1), nil)
+ if err == nil {
+ t.Errorf("expected sign with hash 1 byte to error")
+ }
+
+ _, err = Sign(make([]byte, 33), nil)
+ if err == nil {
+ t.Errorf("expected sign with hash 33 byte to error")
+ }
+}