github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/consensus/scrypt/algorithm_test.go (about) 1 // Copyright (c) 2019 SimpleChain 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Lesser General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Lesser General Public License for more details. 12 // 13 // You should have received a copy of the GNU Lesser General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package scrypt 17 18 import ( 19 "bytes" 20 "testing" 21 22 "github.com/bigzoro/my_simplechain/common/hexutil" 23 ) 24 25 // Tests whether the ScryptHash lookup works 26 func TestScryptHash(t *testing.T) { 27 // Create a block to verify 28 hash := hexutil.MustDecode("0x885c778d7eedb68876b1377e216ed1d2c2417b0fca06b66ca4facae79ae5330d") 29 nonce := uint64(3249874452068615500) 30 31 wantDigest := hexutil.MustDecode("0xa926c4799edcb96b973634888e610fa9f0ca66b4d170903f80fe99487785414e") 32 wantResult := hexutil.MustDecode("0xec9aa0657969e59514b6546d36c706f5aa1625b1f471950a9e6a009452308297") 33 34 digest, result := ScryptHash(hash, nonce) 35 if !bytes.Equal(digest, wantDigest) { 36 t.Errorf("ScryptHash digest mismatch: have %x, want %x", digest, wantDigest) 37 } 38 if !bytes.Equal(result, wantResult) { 39 t.Errorf("ScryptHash result mismatch: have %x, want %x", result, wantResult) 40 } 41 42 } 43 44 // Benchmarks the verification performance 45 func BenchmarkScryptHash(b *testing.B) { 46 hash := hexutil.MustDecode("0x885c778d7eedb68876b1377e216ed1d2c2417b0fca06b66ca4facae79ae5330d") 47 b.ResetTimer() 48 for i := 0; i < b.N; i++ { 49 ScryptHash(hash, 0) 50 } 51 }