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.

41 lines
1.1 KiB

5 years ago
  1. package merkletree
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestGetSetBitmap(t *testing.T) {
  7. var v Hash
  8. setbitmap(v[:], 7)
  9. setbitmap(v[:], 8)
  10. setbitmap(v[:], 255)
  11. expected := "0x8000000000000000000000000000000000000000000000000000000000000180"
  12. assert.Equal(t, expected, v.Hex())
  13. assert.Equal(t, false, testbitmap(v[:], 6))
  14. assert.Equal(t, true, testbitmap(v[:], 7))
  15. assert.Equal(t, true, testbitmap(v[:], 8))
  16. assert.Equal(t, false, testbitmap(v[:], 9))
  17. assert.Equal(t, true, testbitmap(v[:], 255))
  18. }
  19. func TestHashBytes(t *testing.T) {
  20. h := HashBytes([]byte("test")).Hex()
  21. assert.Equal(t, "0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658", h)
  22. h = HashBytes([]byte("authorizeksign")).Hex()
  23. assert.Equal(t, "0x353f867ef725411de05e3d4b0a01c37cf7ad24bcc213141a05ed7726d7932a1f", h)
  24. }
  25. func TestUint32ToBytes(t *testing.T) {
  26. b := Uint32ToBytes(999)
  27. assert.Equal(t, []byte{0xe7, 0x3, 0x0, 0x0}, b)
  28. }
  29. func TestBytesToUint32(t *testing.T) {
  30. u := BytesToUint32([]byte{0xe7, 0x3, 0x0, 0x0})
  31. assert.Equal(t, uint32(999), u)
  32. }