github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/crypto/x11/x11_test.go (about)

     1  // Use of this source code is governed by an ISC
     2  // license that can be found in the LICENSE file.
     3  
     4  package x11
     5  
     6  import (
     7  	"bytes"
     8  	"encoding/hex"
     9  	"testing"
    10  )
    11  
    12  func TestHash(t *testing.T) {
    13  	hs := New()
    14  	out := [32]byte{}
    15  
    16  	for i := range tsInfo {
    17  		ln := len(tsInfo[i].out)
    18  		dest := make([]byte, ln)
    19  		order := make([]byte,11)
    20  		hs.Hash(tsInfo[i].in[:], out[:],order[:])
    21  		if ln != hex.Encode(dest, out[:]) {
    22  			t.Errorf("%s: invalid length", tsInfo[i])
    23  		}
    24  		if !bytes.Equal(dest[:], tsInfo[i].out[:]) {
    25  			t.Errorf("%s: invalid hash", tsInfo[i].id)
    26  		}
    27  	}
    28  }
    29  
    30  ////////////////
    31  
    32  var tsInfo = []struct {
    33  	id  string
    34  	in  []byte
    35  	out []byte
    36  }{
    37  	{
    38  		"Empty",
    39  		[]byte(""),
    40  		[]byte("51b572209083576ea221c27e62b4e22063257571ccb6cc3dc3cd17eb67584eba"),
    41  	},
    42  	{
    43  		"Dash",
    44  		[]byte("DASH"),
    45  		[]byte("fe809ebca8753d907f6ad32cdcf8e5c4e090d7bece5df35b2147e10b88c12d26"),
    46  	},
    47  	{
    48  		"Fox",
    49  		[]byte("The quick brown fox jumps over the lazy dog"),
    50  		[]byte("534536a4e4f16b32447f02f77200449dc2f23b532e3d9878fe111c9de666bc5c"),
    51  	},
    52  }