keccak256-circom/go-keccak256-bits-impl/keccak_test.go
go-keccak256-bits-impl/keccak_test.goRaw
1package keccak
2
3import (
4 "encoding/hex"
5 "testing"
6
7 "github.com/ethereum/go-ethereum/crypto"
8 qt "github.com/frankban/quicktest"
9)
10
11func TestKeccak(t *testing.T) {
12 testKeccak(t, []byte("test"), "9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658")
13 testKeccak(t, make([]byte, 32), "290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563")
14 testKeccak(t, make([]byte, 100), "913fb9e1f6f1c6d910fd574a5cad8857aa43bfba24e401ada4f56090d4d997a7")
15}
16
17func testKeccak(t *testing.T, input []byte, expectedHex string) {
18 expected := crypto.Keccak256(input)
19
20 hBits := ComputeKeccak(bytesToBits(input))
21 h := bitsToBytes(hBits)
22
23 qt.Assert(t, h, qt.DeepEquals, expected)
24 qt.Assert(t, hex.EncodeToString(h), qt.Equals, expectedHex)
25}