forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcrypto_test.go
55 lines (45 loc) · 1.57 KB
/
crypto_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package utils_test
import (
"testing"
"github.com/ledgerwatch/erigon/cl/utils"
)
func TestKeccak256(t *testing.T) {
data := []byte("test data")
extras := [][]byte{
[]byte("extra1"),
[]byte("extra2"),
}
expectedHash := utils.Sha256(data, extras...)
hashFunc := utils.OptimizedSha256NotThreadSafe()
expectedOptimizedHash := hashFunc(data, extras...)
// Test Keccak256 function
hash := utils.Sha256(data, extras...)
if hash != expectedHash {
t.Errorf("Keccak256 returned an incorrect hash. Expected: %x, Got: %x", expectedHash, hash)
}
// Test OptimizedKeccak256 function
optimizedHash := hashFunc(data, extras...)
if optimizedHash != expectedOptimizedHash {
t.Errorf("OptimizedKeccak256 returned an incorrect hash. Expected: %x, Got: %x", expectedOptimizedHash, optimizedHash)
}
}
func TestOptimizedKeccak256NotThreadSafe(t *testing.T) {
data := []byte("test data")
extras := [][]byte{
[]byte("extra1"),
[]byte("extra2"),
}
expectedHash := utils.Sha256(data, extras...)
hashFunc := utils.OptimizedSha256NotThreadSafe()
expectedOptimizedHash := hashFunc(data, extras...)
// Test OptimizedKeccak256NotThreadSafe function
hash := utils.Sha256(data, extras...)
if hash != expectedHash {
t.Errorf("Keccak256 returned an incorrect hash. Expected: %x, Got: %x", expectedHash, hash)
}
// Test OptimizedKeccak256NotThreadSafe function
optimizedHash := hashFunc(data, extras...)
if optimizedHash != expectedOptimizedHash {
t.Errorf("OptimizedKeccak256NotThreadSafe returned an incorrect hash. Expected: %x, Got: %x", expectedOptimizedHash, optimizedHash)
}
}