forked from Layr-Labs/eigensdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_test.go
138 lines (117 loc) · 4.64 KB
/
reader_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package avsregistry_test
import (
"context"
"math/big"
"testing"
"github.com/Layr-Labs/eigensdk-go/testutils/testclients"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func TestReaderMethods(t *testing.T) {
clients, _ := testclients.BuildTestClients(t)
chainReader := clients.ReadClients.AvsRegistryChainReader
quorumNumbers := types.QuorumNums{0}
t.Run("get quorum state", func(t *testing.T) {
count, err := chainReader.GetQuorumCount(&bind.CallOpts{})
require.NoError(t, err)
require.NotNil(t, count)
})
t.Run("get operator stake in quorums at current block", func(t *testing.T) {
stake, err := chainReader.GetOperatorsStakeInQuorumsAtCurrentBlock(&bind.CallOpts{}, quorumNumbers)
require.NoError(t, err)
require.NotNil(t, stake)
})
t.Run("get operator stake in quorums at block", func(t *testing.T) {
stake, err := chainReader.GetOperatorsStakeInQuorumsAtBlock(&bind.CallOpts{}, quorumNumbers, 100)
require.NoError(t, err)
require.NotNil(t, stake)
})
t.Run("get operator address in quorums at current block", func(t *testing.T) {
addresses, err := chainReader.GetOperatorAddrsInQuorumsAtCurrentBlock(&bind.CallOpts{}, quorumNumbers)
require.NoError(t, err)
require.NotNil(t, addresses)
})
t.Run(
"get operators stake in quorums of operator at block returns error for non-registered operator",
func(t *testing.T) {
operatorAddress := common.Address{0x1}
operatorId, err := chainReader.GetOperatorId(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
_, _, err = chainReader.GetOperatorsStakeInQuorumsOfOperatorAtBlock(&bind.CallOpts{}, operatorId, 100)
require.Error(t, err)
require.Contains(t, err.Error(), "Failed to get operators state")
})
t.Run(
"get single operator stake in quorums of operator at current block returns error for non-registered operator",
func(t *testing.T) {
operatorAddress := common.Address{0x1}
operatorId, err := chainReader.GetOperatorId(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
stakes, err := chainReader.GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(&bind.CallOpts{}, operatorId)
require.NoError(t, err)
require.Equal(t, 0, len(stakes))
})
t.Run("get check signatures indices returns error for non-registered operator", func(t *testing.T) {
operatorAddress := common.Address{0x1}
operatorId, err := chainReader.GetOperatorId(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
_, err = chainReader.GetCheckSignaturesIndices(
&bind.CallOpts{},
100,
quorumNumbers,
[]types.OperatorId{operatorId},
)
require.Contains(t, err.Error(), "Failed to get check signatures indices")
})
t.Run("get operator id", func(t *testing.T) {
operatorAddress := common.Address{0x1}
operatorId, err := chainReader.GetOperatorId(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
require.NotNil(t, operatorId)
})
t.Run("get operator from id returns zero address for non-registered operator", func(t *testing.T) {
operatorAddress := common.HexToAddress("0x1234567890123456789012345678901234567890")
operatorId, err := chainReader.GetOperatorId(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
retrievedAddress, err := chainReader.GetOperatorFromId(&bind.CallOpts{}, operatorId)
require.NoError(t, err)
require.Equal(t, retrievedAddress, common.Address{0x0})
})
t.Run("query registration detail", func(t *testing.T) {
operatorAddress := common.HexToAddress("0x1234567890123456789012345678901234567890")
quorums, err := chainReader.QueryRegistrationDetail(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
require.Equal(t, 1, len(quorums))
})
t.Run("is operator registered", func(t *testing.T) {
operatorAddress := common.HexToAddress("0x1234567890123456789012345678901234567890")
isRegistered, err := chainReader.IsOperatorRegistered(&bind.CallOpts{}, operatorAddress)
require.NoError(t, err)
require.False(t, isRegistered)
})
t.Run(
"query existing registered operator pub keys", func(t *testing.T) {
addresses, pubKeys, err := chainReader.QueryExistingRegisteredOperatorPubKeys(
context.Background(),
big.NewInt(0),
nil,
nil,
)
require.NoError(t, err)
require.Equal(t, 0, len(pubKeys))
require.Equal(t, 0, len(addresses))
})
t.Run(
"query existing registered operator sockets", func(t *testing.T) {
address_to_sockets, err := chainReader.QueryExistingRegisteredOperatorSockets(
context.Background(),
big.NewInt(0),
nil,
nil,
)
require.NoError(t, err)
require.Equal(t, 0, len(address_to_sockets))
})
}