You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
750 B

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