github.com/core-coin/go-core/v2@v2.1.9/consensus/cryptore/algorithm_test.go (about) 1 // Copyright 2017 by the Authors 2 // This file is part of the go-core library. 3 // 4 // The go-core 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-core 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-core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package cryptore 18 19 import ( 20 "bytes" 21 "testing" 22 23 "github.com/core-coin/go-core/v2/common/hexutil" 24 25 "github.com/core-coin/go-randomy" 26 ) 27 28 // Tests whether the randomy lookup works for both light as well as the full 29 // datasets. 30 func TestRandomY(t *testing.T) { 31 // Create a block to verify 32 hash := hexutil.MustDecode("0xc9149cc0386e689d789a1c2f3d5d169a61a6218ed30e74414dc736e442ef3d1f") 33 nonce := uint64(0) 34 35 wantResult := hexutil.MustDecode("0xb620364373923b57353c668dcedcfc636d456e1c0d7da8733586c0e54ada6aa4") 36 vm, mutex := randomy.NewRandomYVMWithKeyAndMutex() 37 defer vm.Close() 38 result, err := randomy.RandomY(vm, mutex, hash, nonce) 39 if err != nil { 40 t.Error(err) 41 } 42 if !bytes.Equal(result, wantResult) { 43 t.Errorf("randomy result mismatch: have %x, want %x", result, wantResult) 44 } 45 }