From 4d8241977646bb57a189c9b064fd8b6dba0b0d26 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sun, 24 Nov 2019 18:06:00 +0300 Subject: [PATCH] crypto: add missing tests for hash pkg --- pkg/crypto/hash/hash_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/crypto/hash/hash_test.go b/pkg/crypto/hash/hash_test.go index 272b744fd..105bfd4b6 100644 --- a/pkg/crypto/hash/hash_test.go +++ b/pkg/crypto/hash/hash_test.go @@ -1,10 +1,12 @@ package hash import ( + "encoding/binary" "encoding/hex" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSha256(t *testing.T) { @@ -47,3 +49,18 @@ func TestHash160(t *testing.T) { actual := hex.EncodeToString(data.Bytes()) 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))) + } +}