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.

42 lines
798 B

  1. package tmhash_test
  2. import (
  3. "crypto/sha256"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tendermint/tendermint/crypto/tmhash"
  7. )
  8. func TestHash(t *testing.T) {
  9. testVector := []byte("abc")
  10. hasher := tmhash.New()
  11. hasher.Write(testVector)
  12. bz := hasher.Sum(nil)
  13. bz2 := tmhash.Sum(testVector)
  14. hasher = sha256.New()
  15. hasher.Write(testVector)
  16. bz3 := hasher.Sum(nil)
  17. assert.Equal(t, bz, bz2)
  18. assert.Equal(t, bz, bz3)
  19. }
  20. func TestHashTruncated(t *testing.T) {
  21. testVector := []byte("abc")
  22. hasher := tmhash.NewTruncated()
  23. hasher.Write(testVector)
  24. bz := hasher.Sum(nil)
  25. bz2 := tmhash.SumTruncated(testVector)
  26. hasher = sha256.New()
  27. hasher.Write(testVector)
  28. bz3 := hasher.Sum(nil)
  29. bz3 = bz3[:tmhash.TruncatedSize]
  30. assert.Equal(t, bz, bz2)
  31. assert.Equal(t, bz, bz3)
  32. }