-
Notifications
You must be signed in to change notification settings - Fork 5
/
ssz_test.go
63 lines (58 loc) · 2.09 KB
/
ssz_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
package eth2deposit
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestComputeDepositForkDataRoot(t *testing.T) {
var (
in = [4]byte{0x12, 0x12, 0x12, 0x12}
expected = []byte("\rf`\x8a\xf5W\xf4\xfa\xdb\xfc\xe2H\xac7\xf6\xe7c\x9c\xe3q\x10\x0cC\xd1Z\xad\x05\xcb\x08\xac\x1d\xc2")
)
out, err := ComputeDepositForkDataRoot(in)
assert.Nil(t, err)
assert.Equal(t, expected, out)
}
func TestComputeDepositDomain(t *testing.T) {
var (
in = [4]byte{0x12, 0x12, 0x12, 0x12}
expected = []byte("\x03\x00\x00\x00\rf`\x8a\xf5W\xf4\xfa\xdb\xfc\xe2H\xac7\xf6\xe7c\x9c\xe3q\x10\x0cC\xd1Z\xad\x05\xcb")
)
out, err := ComputeDepositDomain(in)
assert.Nil(t, err)
assert.Equal(t, expected, out)
}
func TestComputeSigningRoot(t *testing.T) {
var (
in = DepositMessage{
Pubkey: [48]byte{0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12},
WithdrawalCredentials: [32]byte{0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12},
Amount: 100,
}
expected = []byte("g\xa33\x0f\xf8{\xdbF\xbb{\x80\xcazd\x1e9\x8dj\xc4\xe8zhVR|\xac\xc8)\xfba\x89o")
)
getDomain := func(length int) []byte {
var out []byte
for i := 0; i < length; i++ {
out = append(out, 0x12)
}
return out
}
t.Run("len(domain)=32", func(t *testing.T) {
domain := getDomain(32)
out, err := ComputeSigningRoot(&in, domain)
assert.Nil(t, err)
assert.Equal(t, expected, out)
})
t.Run("len(domain)=31", func(t *testing.T) {
domain := getDomain(31)
out, err := ComputeSigningRoot(&in, domain)
assert.Nil(t, out)
assert.NotNil(t, err)
})
t.Run("len(domain)=33", func(t *testing.T) {
domain := getDomain(33)
out, err := ComputeSigningRoot(&in, domain)
assert.Nil(t, out)
assert.NotNil(t, err)
})
}