-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: chainReader
shares and operatorSets functions
#437
Changes from 27 commits
6c67852
7ca1403
561f656
bdcc73b
58f8e49
53e01ea
5955c4b
7f5d030
6c4181e
10f0a98
192d165
9a19a97
203e2ca
407969d
095890b
a965138
b72c6a2
12121e7
e6a0e62
1c97057
f8eaa89
778075b
c3a638a
97500d0
9e24725
53f13fe
aab1903
9d32443
4fbf686
1e9bf2d
ca5f8b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager" | ||
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20" | ||
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator" | ||
"github.com/Layr-Labs/eigensdk-go/crypto/bls" | ||
"github.com/Layr-Labs/eigensdk-go/testutils" | ||
"github.com/Layr-Labs/eigensdk-go/testutils/testclients" | ||
"github.com/Layr-Labs/eigensdk-go/types" | ||
|
@@ -734,3 +735,223 @@ func TestAppointeesFunctions(t *testing.T) { | |
assert.NotEmpty(t, appointeesPermission) | ||
}) | ||
} | ||
|
||
func TestOperatorSetsAndSlashableShares(t *testing.T) { | ||
testConfig := testutils.GetDefaultTestConfig() | ||
anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) | ||
require.NoError(t, err) | ||
|
||
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") | ||
require.NoError(t, err) | ||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
|
||
config := elcontracts.Config{ | ||
DelegationManagerAddress: contractAddrs.DelegationManager, | ||
} | ||
chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) | ||
require.NoError(t, err) | ||
|
||
operatorAddr := common.HexToAddress(testutils.ANVIL_SECOND_ADDRESS) | ||
operatorPrivateKeyHex := testutils.ANVIL_SECOND_PRIVATE_KEY | ||
chainWriter, err := testclients.NewTestChainWriterFromConfig(anvilHttpEndpoint, operatorPrivateKeyHex, config) | ||
require.NoError(t, err) | ||
|
||
avsAdrr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
avsPrivateKeyHex := testutils.ANVIL_FIRST_PRIVATE_KEY | ||
operatorSetId := uint32(1) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: avsAdrr, | ||
Id: operatorSetId, | ||
} | ||
|
||
strategyAddr := contractAddrs.Erc20MockStrategy | ||
strategies := []common.Address{strategyAddr} | ||
|
||
err = createOperatorSet(anvilHttpEndpoint, avsPrivateKeyHex, avsAdrr, operatorSetId, strategyAddr) | ||
require.NoError(t, err) | ||
|
||
keypair, err := bls.NewKeyPairFromString("0x01") | ||
require.NoError(t, err) | ||
|
||
request := elcontracts.RegistrationRequest{ | ||
OperatorAddress: operatorAddr, | ||
AVSAddress: avsAdrr, | ||
OperatorSetIds: []uint32{operatorSetId}, | ||
WaitForReceipt: true, | ||
Socket: "socket", | ||
BlsKeyPair: keypair, | ||
} | ||
|
||
registryCoordinatorAddress := contractAddrs.RegistryCoordinator | ||
receipt, err := chainWriter.RegisterForOperatorSets( | ||
context.Background(), | ||
registryCoordinatorAddress, | ||
request, | ||
) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(1), receipt.Status) | ||
|
||
const allocationDelay = 1 | ||
const allocationMagnitude = 100 | ||
const allocationConfigurationDelay = 1200 | ||
|
||
receipt, err = chainWriter.SetAllocationDelay( | ||
context.Background(), | ||
operatorAddr, | ||
allocationDelay, | ||
true, | ||
) | ||
require.NoError(t, err) | ||
require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) | ||
|
||
testutils.AdvanceChainByNBlocksExecInContainer( | ||
context.Background(), | ||
allocationConfigurationDelay+1, | ||
anvilC, | ||
) | ||
|
||
allocationParams := []allocationmanager.IAllocationManagerTypesAllocateParams{ | ||
{ | ||
OperatorSet: operatorSet, | ||
Strategies: strategies, | ||
NewMagnitudes: []uint64{allocationMagnitude}, | ||
}, | ||
} | ||
|
||
receipt, err = chainWriter.ModifyAllocations( | ||
context.Background(), | ||
operatorAddr, | ||
allocationParams, | ||
true, | ||
) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(1), receipt.Status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This literal can be replaced for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 4fbf686 |
||
|
||
t.Run("get operators and operator sets", func(t *testing.T) { | ||
t.Run("validate strategies for operatorSet", func(t *testing.T) { | ||
strats, err := chainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) | ||
require.NoError(t, err) | ||
require.Len(t, strats, 1) | ||
require.Equal(t, strats[0].Hex(), strategyAddr.Hex()) | ||
}) | ||
|
||
t.Run("get registered sets", func(t *testing.T) { | ||
registeredSets, err := chainReader.GetRegisteredSets(context.Background(), operatorAddr) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, registeredSets) | ||
}) | ||
|
||
t.Run("get operator sets for operator", func(t *testing.T) { | ||
opSets, err := chainReader.GetOperatorSetsForOperator(context.Background(), operatorAddr) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, opSets) | ||
require.Len(t, opSets, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If opSets has len 1 then it is not empty, so one require is redundant in my opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 1e9bf2d |
||
}) | ||
|
||
t.Run("get amount operatorSets for operator", func(t *testing.T) { | ||
opSetsCount, err := chainReader.GetNumOperatorSetsForOperator( | ||
context.Background(), | ||
operatorAddr, | ||
) | ||
require.NoError(t, err) | ||
require.NotZero(t, opSetsCount) | ||
}) | ||
|
||
t.Run("get operator for operatorsets", func(t *testing.T) { | ||
operators, err := chainReader.GetOperatorsForOperatorSet(context.Background(), operatorSet) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, operators) | ||
require.Len(t, operators, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 1e9bf2d |
||
}) | ||
|
||
t.Run("get amount of operators for operatorsets", func(t *testing.T) { | ||
operatorsCount, err := chainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) | ||
require.NoError(t, err) | ||
require.NotZero(t, operatorsCount) | ||
}) | ||
}) | ||
|
||
t.Run("slashable shares tests", func(t *testing.T) { | ||
t.Run("get slashable shares for single operator", func(t *testing.T) { | ||
shares, err := chainReader.GetSlashableShares( | ||
context.Background(), | ||
operatorAddr, | ||
operatorSet, | ||
strategies, | ||
) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, shares) | ||
}) | ||
|
||
t.Run("get slashable shares for multiple operatorSets", func(t *testing.T) { | ||
shares, err := chainReader.GetSlashableSharesForOperatorSets( | ||
context.Background(), | ||
[]allocationmanager.OperatorSet{operatorSet}, | ||
) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, shares) | ||
}) | ||
|
||
t.Run("get slashable shares before specific block", func(t *testing.T) { | ||
shares, err := chainReader.GetSlashableSharesForOperatorSetsBefore( | ||
context.Background(), | ||
[]allocationmanager.OperatorSet{operatorSet}, | ||
2, | ||
) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, shares) | ||
}) | ||
}) | ||
} | ||
|
||
func TestOperatorSetsWithWrongInput(t *testing.T) { | ||
_, anvilHttpEndpoint := testclients.BuildTestClients(t) | ||
ctx := context.Background() | ||
|
||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
operatorAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
|
||
config := elcontracts.Config{} | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: common.HexToAddress(testutils.ANVIL_SECOND_ADDRESS), | ||
Id: 0, | ||
} | ||
|
||
chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) | ||
require.NoError(t, err) | ||
|
||
t.Run("test operator set with invalid id", func(t *testing.T) { | ||
_, err := chainReader.GetOperatorsForOperatorSet(ctx, operatorSet) | ||
require.Error(t, err) | ||
|
||
_, err = chainReader.GetNumOperatorsForOperatorSet(ctx, operatorSet) | ||
require.Error(t, err) | ||
|
||
_, err = chainReader.GetStrategiesForOperatorSet(ctx, operatorSet) | ||
require.Error(t, err) | ||
|
||
strategies := []common.Address{contractAddrs.Erc20MockStrategy} | ||
|
||
_, err = chainReader.GetSlashableShares( | ||
ctx, | ||
operatorAddr, | ||
operatorSet, | ||
strategies, | ||
) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("get slashable shares with invalid operatorSet", func(t *testing.T) { | ||
config := elcontracts.Config{ | ||
DelegationManagerAddress: contractAddrs.DelegationManager, | ||
} | ||
|
||
chainReader, err = testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) | ||
require.NoError(t, err) | ||
|
||
operatorSets := []allocationmanager.OperatorSet{operatorSet} | ||
|
||
_, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 10) | ||
require.Error(t, err) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants should be outside the test or else they can be variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 9d32443