github.com/theQRL/go-zond@v0.1.1/internal/blocktest/test_hash.go (about) 1 // Copyright 2023 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package utesting provides a standalone replacement for package testing. 18 // 19 // This package exists because package testing cannot easily be embedded into a 20 // standalone go program. It provides an API that mirrors the standard library 21 // testing API. 22 23 package blocktest 24 25 import ( 26 "hash" 27 28 "github.com/theQRL/go-zond/common" 29 "golang.org/x/crypto/sha3" 30 ) 31 32 // testHasher is the helper tool for transaction/receipt list hashing. 33 // The original hasher is trie, in order to get rid of import cycle, 34 // use the testing hasher instead. 35 type testHasher struct { 36 hasher hash.Hash 37 } 38 39 // NewHasher returns a new testHasher instance. 40 func NewHasher() *testHasher { 41 return &testHasher{hasher: sha3.NewLegacyKeccak256()} 42 } 43 44 // Reset resets the hash state. 45 func (h *testHasher) Reset() { 46 h.hasher.Reset() 47 } 48 49 // Update updates the hash state with the given key and value. 50 func (h *testHasher) Update(key, val []byte) error { 51 h.hasher.Write(key) 52 h.hasher.Write(val) 53 return nil 54 } 55 56 // Hash returns the hash value. 57 func (h *testHasher) Hash() common.Hash { 58 return common.BytesToHash(h.hasher.Sum(nil)) 59 }