crypto: add missing tests for hash pkg

This commit is contained in:
Evgenii Stratonikov 2019-11-24 18:06:00 +03:00
parent 2d41450ac9
commit 4d82419776

View file

@ -1,10 +1,12 @@
package hash package hash
import ( import (
"encoding/binary"
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestSha256(t *testing.T) { func TestSha256(t *testing.T) {
@ -47,3 +49,18 @@ func TestHash160(t *testing.T) {
actual := hex.EncodeToString(data.Bytes()) actual := hex.EncodeToString(data.Bytes())
assert.Equal(t, expected, actual) assert.Equal(t, expected, actual)
} }
func TestChecksum(t *testing.T) {
testCases := []struct {
data []byte
sum uint32
}{
{nil, 0xe2e0f65d},
{[]byte{}, 0xe2e0f65d},
{[]byte{1, 2, 3, 4}, 0xe272e48d},
}
for _, tc := range testCases {
require.Equal(t, tc.sum, binary.LittleEndian.Uint32(Checksum(tc.data)))
}
}