-
Notifications
You must be signed in to change notification settings - Fork 53
/
reader_test.go
132 lines (116 loc) · 3.85 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
package elcontracts_test
import (
"context"
"math/big"
"testing"
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20"
"github.com/Layr-Labs/eigensdk-go/testutils"
"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/assert"
)
func TestChainReader(t *testing.T) {
clients, anvilHttpEndpoint := testclients.BuildTestClients(t)
ctx := context.Background()
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)
operator := types.Operator{
Address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
}
t.Run("is operator registered", func(t *testing.T) {
isOperator, err := clients.ElChainReader.IsOperatorRegistered(ctx, operator)
assert.NoError(t, err)
assert.Equal(t, isOperator, true)
})
t.Run("get operator details", func(t *testing.T) {
operatorDetails, err := clients.ElChainReader.GetOperatorDetails(ctx, operator)
assert.NoError(t, err)
assert.NotNil(t, operatorDetails)
assert.Equal(t, operator.Address, operatorDetails.Address)
})
t.Run("get strategy and underlying token", func(t *testing.T) {
strategyAddr := contractAddrs.Erc20MockStrategy
strategy, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken(
ctx,
strategyAddr,
)
assert.NoError(t, err)
assert.NotNil(t, strategy)
assert.NotEqual(t, common.Address{}, underlyingTokenAddr)
erc20Token, err := erc20.NewContractIERC20(underlyingTokenAddr, clients.EthHttpClient)
assert.NoError(t, err)
tokenName, err := erc20Token.Name(&bind.CallOpts{})
assert.NoError(t, err)
assert.NotEmpty(t, tokenName)
})
t.Run("get strategy and underlying ERC20 token", func(t *testing.T) {
strategyAddr := contractAddrs.Erc20MockStrategy
strategy, contractUnderlyingToken, underlyingTokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingERC20Token(
ctx,
strategyAddr,
)
assert.NoError(t, err)
assert.NotNil(t, strategy)
assert.NotEqual(t, common.Address{}, underlyingTokenAddr)
assert.NotNil(t, contractUnderlyingToken)
tokenName, err := contractUnderlyingToken.Name(&bind.CallOpts{})
assert.NoError(t, err)
assert.NotEmpty(t, tokenName)
})
t.Run("service manager can slash operator until block", func(t *testing.T) {
_, err := clients.ElChainReader.ServiceManagerCanSlashOperatorUntilBlock(
ctx,
common.HexToAddress(operator.Address),
contractAddrs.ServiceManager,
)
assert.NoError(t, err)
})
t.Run("operator is frozen", func(t *testing.T) {
isFrozen, err := clients.ElChainReader.OperatorIsFrozen(
ctx,
common.HexToAddress(operator.Address),
)
assert.NoError(t, err)
assert.Equal(t, isFrozen, false)
})
t.Run("get operator shares in strategy", func(t *testing.T) {
shares, err := clients.ElChainReader.GetOperatorSharesInStrategy(
ctx,
common.HexToAddress(operator.Address),
contractAddrs.Erc20MockStrategy,
)
assert.NoError(t, err)
assert.NotZero(t, shares)
})
t.Run("calculate delegation approval digest hash", func(t *testing.T) {
staker := common.Address{0x0}
delegationApprover := common.Address{0x0}
approverSalt := [32]byte{}
expiry := big.NewInt(0)
digest, err := clients.ElChainReader.CalculateDelegationApprovalDigestHash(
ctx,
staker,
common.HexToAddress(operator.Address),
delegationApprover,
approverSalt,
expiry,
)
assert.NoError(t, err)
assert.NotEmpty(t, digest)
})
t.Run("calculate operator AVS registration digest hash", func(t *testing.T) {
avs := common.Address{0x0}
salt := [32]byte{}
expiry := big.NewInt(0)
digest, err := clients.ElChainReader.CalculateOperatorAVSRegistrationDigestHash(
ctx,
common.HexToAddress(operator.Address),
avs,
salt,
expiry,
)
assert.NoError(t, err)
assert.NotEmpty(t, digest)
})
}