aboutsummaryrefslogtreecommitdiffstats
path: root/ethcrypto/crypto_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-30 01:35:33 +0800
committerFelix Lange <fjl@twurst.com>2014-10-30 01:35:33 +0800
commit051af604e2f076e131875d558b052a4e4d1bf713 (patch)
treea4e3fe652e568b7eab0e41504f96f27eb2035fb3 /ethcrypto/crypto_test.go
parent5920aa7be6fb973c7cbae34c9d4af03665933c51 (diff)
downloadgo-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar.gz
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar.bz2
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar.lz
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar.xz
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.tar.zst
go-tangerine-051af604e2f076e131875d558b052a4e4d1bf713.zip
ethcrypto: fix the tests
The Sha3 test contained the wrong expected result. Note that the implementation hasn't changed, the test simply contained an outdated expected value that was valid for the previous implementation.
Diffstat (limited to 'ethcrypto/crypto_test.go')
-rw-r--r--ethcrypto/crypto_test.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/ethcrypto/crypto_test.go b/ethcrypto/crypto_test.go
index 689bcecb4..e8db6362f 100644
--- a/ethcrypto/crypto_test.go
+++ b/ethcrypto/crypto_test.go
@@ -2,16 +2,35 @@ package ethcrypto
import (
"bytes"
+ "encoding/hex"
"testing"
-
- "github.com/ethereum/go-ethereum/ethutil"
)
-// FIPS 202 test (reverted back to FIPS 180)
+// These tests are sanity checks.
+// They should ensure that we don't e.g. use Sha3-224 instead of Sha3-256
+// and that the sha3 library uses keccak-f permutation.
+
func TestSha3(t *testing.T) {
- const exp = "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"
- sha3_256 := Sha3Bin([]byte("abc"))
- if bytes.Compare(sha3_256, ethutil.Hex2Bytes(exp)) != 0 {
- t.Errorf("Sha3_256 failed. Incorrect result %x", sha3_256)
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
+ checkhash(t, "Sha3-256", Sha3, msg, exp)
+}
+
+func TestSha256(t *testing.T) {
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
+ checkhash(t, "Sha256", Sha256, msg, exp)
+}
+
+func TestRipemd160(t *testing.T) {
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")
+ checkhash(t, "Ripemd160", Ripemd160, msg, exp)
+}
+
+func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) {
+ sum := f(msg)
+ if bytes.Compare(exp, sum) != 0 {
+ t.Errorf("hash %s returned wrong result.\ngot: %x\nwant: %x", name, sum, exp)
}
}