github.com/prysmaticlabs/prysm@v1.4.4/shared/htrutils/hashers_test.go (about)

     1  package htrutils_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prysmaticlabs/prysm/shared/hashutil"
     7  	"github.com/prysmaticlabs/prysm/shared/htrutils"
     8  	"github.com/prysmaticlabs/prysm/shared/testutil/assert"
     9  )
    10  
    11  func TestHash(t *testing.T) {
    12  	byteSlice := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
    13  	hasher := htrutils.NewHasherFunc(hashutil.CustomSHA256Hasher())
    14  	expected := [32]byte{71, 228, 238, 127, 33, 31, 115, 38, 93, 209, 118, 88, 246, 226, 28, 19, 24, 189, 108, 129, 243, 117, 152, 226, 10, 39, 86, 41, 149, 66, 239, 207}
    15  	result := hasher.Hash(byteSlice)
    16  	assert.Equal(t, expected, result)
    17  }
    18  
    19  func TestCombi(t *testing.T) {
    20  	byteSlice1 := [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
    21  	byteSlice2 := [32]byte{32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
    22  	hasher := htrutils.NewHasherFunc(hashutil.CustomSHA256Hasher())
    23  	expected := [32]byte{203, 73, 0, 148, 142, 9, 145, 147, 186, 232, 143, 117, 95, 44, 38, 46, 102, 69, 101, 74, 50, 37, 87, 189, 40, 196, 203, 140, 19, 233, 161, 225}
    24  	result := hasher.Combi(byteSlice1, byteSlice2)
    25  	assert.Equal(t, expected, result)
    26  }
    27  
    28  func TestMixIn(t *testing.T) {
    29  	byteSlice := [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
    30  	intToAdd := uint64(33)
    31  	hasher := htrutils.NewHasherFunc(hashutil.CustomSHA256Hasher())
    32  	expected := [32]byte{170, 90, 0, 249, 34, 60, 140, 68, 77, 51, 218, 139, 54, 119, 179, 238, 80, 72, 13, 20, 212, 218, 124, 215, 68, 122, 214, 157, 178, 85, 225, 213}
    33  	result := hasher.MixIn(byteSlice, intToAdd)
    34  	assert.Equal(t, expected, result)
    35  }