github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/xxhash/xxhash_test.go (about) 1 // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls 2 // 3 // Copyright 2020 Stafi Protocol 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package xxhash_test 18 19 import ( 20 "testing" 21 22 "github.com/stafiprotocol/go-substrate-rpc-client/xxhash" 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func Test64(t *testing.T) { 27 h := xxhash.New64([]byte("abc")) 28 assert.Equal(t, []byte{0x99, 0x09, 0x77, 0xad, 0xf5, 0x2c, 0xbc, 0x44}, h.Sum(nil)) 29 } 30 31 func Test64Concat(t *testing.T) { 32 h := xxhash.New64Concat([]byte("abc")) 33 assert.Equal(t, []byte{0x99, 0x09, 0x77, 0xad, 0xf5, 0x2c, 0xbc, 0x44, 0x61, 0x62, 0x63}, h.Sum(nil)) 34 } 35 36 func Test128(t *testing.T) { 37 h := xxhash.New128([]byte("abc")) 38 assert.Equal(t, []byte{ 39 0x99, 0x09, 0x77, 0xad, 0xf5, 0x2c, 0xbc, 0x44, 0x08, 0x89, 0x32, 0x99, 0x81, 0xca, 0xa9, 0xbe, 40 }, h.Sum(nil)) 41 } 42 43 func Test256(t *testing.T) { 44 h := xxhash.New256([]byte("abc")) 45 assert.Equal(t, []byte{ 46 0x99, 0x09, 0x77, 0xad, 0xf5, 0x2c, 0xbc, 0x44, 0x08, 0x89, 0x32, 0x99, 0x81, 0xca, 0xa9, 0xbe, 47 0xf7, 0xda, 0x57, 0x70, 0xb2, 0xb8, 0xa0, 0x53, 0x03, 0xb7, 0x5d, 0x95, 0x36, 0x0d, 0xd6, 0x2b, 48 }, h.Sum(nil)) 49 } 50 51 func Test64OtherMethods(t *testing.T) { 52 h := xxhash.New64(nil) 53 54 assert.Equal(t, 8, h.Size()) 55 assert.Equal(t, []byte{0x99, 0xe9, 0xd8, 0x51, 0x37, 0xdb, 0x46, 0xef}, h.Sum(nil)) 56 57 n, err := h.Write([]byte("ab")) 58 assert.NoError(t, err) 59 assert.Equal(t, 2, n) 60 61 assert.Equal(t, []byte{0x61, 0x4a, 0xd0, 0x92, 0xca, 0x8, 0xf7, 0x65}, h.Sum(nil)) 62 63 n, err = h.Write([]byte("c")) 64 assert.NoError(t, err) 65 assert.Equal(t, 1, n) 66 67 assert.Equal(t, 8, h.Size()) 68 assert.Equal(t, []byte{0x99, 0x09, 0x77, 0xad, 0xf5, 0x2c, 0xbc, 0x44}, h.Sum(nil)) 69 assert.Equal(t, 64, h.BlockSize()) 70 71 h.Reset() 72 assert.Equal(t, 64, h.BlockSize()) 73 assert.Equal(t, 8, h.Size()) 74 assert.Equal(t, []byte{0x99, 0xe9, 0xd8, 0x51, 0x37, 0xdb, 0x46, 0xef}, h.Sum(nil)) 75 }