forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iface_test.go
80 lines (64 loc) · 2.05 KB
/
iface_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package preimage
import (
"encoding/binary"
"testing"
"github.com/stretchr/testify/require"
)
func TestPreimageKeyTypes(t *testing.T) {
t.Run("LocalIndexKey", func(t *testing.T) {
actual := LocalIndexKey(0xFFFFFFFF)
// PreimageKey encoding
expected := [32]byte{}
expected[0] = byte(LocalKeyType)
binary.BigEndian.PutUint64(expected[24:], 0xFFFFFFFF)
require.Equal(t, expected, actual.PreimageKey())
})
t.Run("Keccak256Key", func(t *testing.T) {
fauxHash := [32]byte{}
fauxHash[31] = 0xFF
actual := Keccak256Key(fauxHash)
// PreimageKey encoding
expected := [32]byte{}
expected[0] = byte(Keccak256KeyType)
expected[31] = 0xFF
require.Equal(t, expected, actual.PreimageKey())
// String encoding
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000ff", actual.String())
})
t.Run("Sha256Key", func(t *testing.T) {
fauxHash := [32]byte{}
fauxHash[31] = 0xFF
actual := Sha256Key(fauxHash)
// PreimageKey encoding
expected := [32]byte{}
expected[0] = byte(Sha256KeyType)
expected[31] = 0xFF
require.Equal(t, expected, actual.PreimageKey())
// String encoding
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000ff", actual.String())
})
t.Run("BlobKey", func(t *testing.T) {
fauxHash := [32]byte{}
fauxHash[31] = 0xFF
actual := BlobKey(fauxHash)
// PreimageKey encoding
expected := [32]byte{}
expected[0] = byte(BlobKeyType)
expected[31] = 0xFF
require.Equal(t, expected, actual.PreimageKey())
// String encoding
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000ff", actual.String())
})
t.Run("KZGPointEvaluationKey", func(t *testing.T) {
fauxHash := [32]byte{}
fauxHash[31] = 0xFF
actual := PrecompileKey(fauxHash)
// PreimageKey encoding
expected := [32]byte{}
expected[0] = byte(PrecompileKeyType)
expected[31] = 0xFF
require.Equal(t, expected, actual.PreimageKey())
// String encoding
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000ff", actual.String())
})
}