From 6c67852af7bdf0d84815a5049ebe3f69e8941090 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 14:16:03 -0300 Subject: [PATCH 01/30] Add code from PR#416 --- chainio/clients/elcontracts/reader_test.go | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index d3d1fdb0..bb4adb9d 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -5,7 +5,10 @@ import ( "math/big" "testing" + "github.com/Layr-Labs/eigensdk-go/chainio/clients" + allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager" erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20" + regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator" "github.com/Layr-Labs/eigensdk-go/testutils" "github.com/Layr-Labs/eigensdk-go/testutils/testclients" "github.com/Layr-Labs/eigensdk-go/types" @@ -112,3 +115,97 @@ func TestChainReader(t *testing.T) { assert.NotEmpty(t, digest) }) } + +func createOperatorSet( + client *clients.Clients, + avsAddress common.Address, + operatorSetId uint32, + erc20MockStrategyAddr common.Address, +) error { + allocationManagerAddress := client.EigenlayerContractBindings.AllocationManagerAddr + allocationManager, err := allocationmanager.NewContractAllocationManager( + allocationManagerAddress, + client.EthHttpClient, + ) + if err != nil { + return err + } + registryCoordinatorAddress := client.AvsRegistryContractBindings.RegistryCoordinatorAddr + registryCoordinator, err := regcoord.NewContractRegistryCoordinator( + registryCoordinatorAddress, + client.EthHttpClient, + ) + if err != nil { + return err + } + + noSendTxOpts, err := client.TxManager.GetNoSendTxOpts() + if err != nil { + return err + } + + tx, err := allocationManager.SetAVSRegistrar(noSendTxOpts, avsAddress, registryCoordinatorAddress) + if err != nil { + return err + } + + waitForReceipt := true + + _, err = client.TxManager.Send(context.Background(), tx, waitForReceipt) + if err != nil { + return err + } + + tx, err = registryCoordinator.EnableOperatorSets(noSendTxOpts) + if err != nil { + return err + } + + _, err = client.TxManager.Send(context.Background(), tx, waitForReceipt) + if err != nil { + return err + } + + operatorSetParam := regcoord.IRegistryCoordinatorOperatorSetParam{ + MaxOperatorCount: 10, + KickBIPsOfOperatorStake: 100, + KickBIPsOfTotalStake: 1000, + } + minimumStake := big.NewInt(0) + + strategyParams := regcoord.IStakeRegistryStrategyParams{ + Strategy: erc20MockStrategyAddr, + Multiplier: big.NewInt(1), + } + strategyParamsArray := []regcoord.IStakeRegistryStrategyParams{strategyParams} + lookAheadPeriod := uint32(0) + tx, err = registryCoordinator.CreateSlashableStakeQuorum( + noSendTxOpts, + operatorSetParam, + minimumStake, + strategyParamsArray, + lookAheadPeriod, + ) + if err != nil { + return err + } + + _, err = client.TxManager.Send(context.Background(), tx, waitForReceipt) + if err != nil { + return err + } + + strategies := []common.Address{erc20MockStrategyAddr} + operatorSetParams := allocationmanager.IAllocationManagerTypesCreateSetParams{ + OperatorSetId: operatorSetId, + Strategies: strategies, + } + operatorSetParamsArray := []allocationmanager.IAllocationManagerTypesCreateSetParams{operatorSetParams} + tx, err = allocationManager.CreateOperatorSets(noSendTxOpts, avsAddress, operatorSetParamsArray) + if err != nil { + return err + } + + _, err = client.TxManager.Send(context.Background(), tx, waitForReceipt) + return err +} From 7ca1403b707603b8a075f32e1f4fa9d4327bbcfc Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 14:19:14 -0300 Subject: [PATCH 02/30] Add test for GetSlashableShares function --- chainio/clients/elcontracts/reader_test.go | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index bb4adb9d..b2f042fe 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestChainReader(t *testing.T) { @@ -116,6 +117,48 @@ func TestChainReader(t *testing.T) { }) } +func TestSlashableSharesFunctions(t *testing.T) { + eigenClients, anvilHttpEndpoint := testclients.BuildTestClients(t) + contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + + avsAddress := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") + operatorAddress := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") + erc20MockStrategyAddr := contractAddrs.Erc20MockStrategy + operatorsSets := []uint32{1, 2} + + t.Run("Create First OperatorSet", func(t *testing.T) { + err := createOperatorSet(eigenClients, avsAddress, operatorsSets[0], erc20MockStrategyAddr) + require.NoError(t, err) + t.Log("First OperatorSet Created") + }) + + t.Run("Create Second OperatorSet", func(t *testing.T) { + err := createOperatorSet(eigenClients, avsAddress, operatorsSets[1], erc20MockStrategyAddr) + require.NoError(t, err) + t.Log("Second OperatorSet Created") + }) + + t.Run("Get Slashable Shares for operatorSet1", func(t *testing.T) { + operatorSet := allocationmanager.OperatorSet{ + Avs: avsAddress, + Id: operatorsSets[0], + } + strategies := []common.Address{erc20MockStrategyAddr} + + shares, err := eigenClients.ElChainReader.GetSlashableShares( + context.Background(), + operatorAddress, + operatorSet, + strategies, + ) + require.NoError(t, err) + require.NotEmpty(t, shares) + for strat, share := range shares { + t.Logf("Strategy: %s, Slashable Share: %s", strat.Hex(), share.String()) + } + }) +} + func createOperatorSet( client *clients.Clients, avsAddress common.Address, From 561f656145ba560493f82d85b725d6c78ee346c9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 14:51:01 -0300 Subject: [PATCH 03/30] Add two fields to RegistrationRequest --- chainio/clients/elcontracts/types.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chainio/clients/elcontracts/types.go b/chainio/clients/elcontracts/types.go index 4414dd07..2c119754 100644 --- a/chainio/clients/elcontracts/types.go +++ b/chainio/clients/elcontracts/types.go @@ -4,6 +4,7 @@ import ( "math/big" allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager" + "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/ethereum/go-ethereum/common" ) @@ -39,6 +40,8 @@ type RegistrationRequest struct { AVSAddress common.Address OperatorSetIds []uint32 WaitForReceipt bool + BlsKeyPair *bls.KeyPair + Socket string } type RemovePermissionRequest struct { From bdcc73bb9afae4bc71a77a81accb113188d96aee Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 14:51:48 -0300 Subject: [PATCH 04/30] Change logic RegisterForOperatorSets() --- chainio/clients/elcontracts/writer.go | 102 +++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index 4cd1d943..d1b58e0e 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -4,15 +4,14 @@ import ( "context" "errors" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "math/big" - gethcommon "github.com/ethereum/go-ethereum/common" - gethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" + chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory" allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager" delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" @@ -20,11 +19,15 @@ import ( rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator" strategy "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IStrategy" permissioncontroller "github.com/Layr-Labs/eigensdk-go/contracts/bindings/PermissionController" + regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" + "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/metrics" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" + gethcommon "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" ) type Reader interface { @@ -579,6 +582,7 @@ func (w *ChainWriter) DeregisterFromOperatorSets( func (w *ChainWriter) RegisterForOperatorSets( ctx context.Context, + registryCoordinatorAddr gethcommon.Address, request RegistrationRequest, ) (*gethtypes.Receipt, error) { if w.allocationManager == nil { @@ -590,12 +594,28 @@ func (w *ChainWriter) RegisterForOperatorSets( return nil, utils.WrapError("failed to get no send tx opts", err) } + pubkeyRegParams, err := getPubkeyRegistrationParams( + w.ethClient, + registryCoordinatorAddr, + request.OperatorAddress, + request.BlsKeyPair, + ) + if err != nil { + return nil, utils.WrapError("failed to get public key registration params", err) + } + + data, err := abiEncodeRegistrationParams(request.Socket, *pubkeyRegParams) + if err != nil { + return nil, utils.WrapError("failed to encode registration params", err) + } + tx, err := w.allocationManager.RegisterForOperatorSets( noSendTxOpts, request.OperatorAddress, allocationmanager.IAllocationManagerTypesRegisterParams{ Avs: request.AVSAddress, OperatorSetIds: request.OperatorSetIds, + Data: data, }) if err != nil { return nil, utils.WrapError("failed to create RegisterForOperatorSets tx", err) @@ -773,3 +793,79 @@ func (w *ChainWriter) RemovePendingAdmin( return w.txMgr.Send(ctx, tx, request.WaitForReceipt) } + +func getPubkeyRegistrationParams( + ethClient bind.ContractBackend, + registryCoordinatorAddr, operatorAddress gethcommon.Address, + blsKeyPair *bls.KeyPair, +) (*regcoord.IBLSApkRegistryPubkeyRegistrationParams, error) { + registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient) + if err != nil { + return nil, utils.WrapError("failed to create registry coordinator", err) + } + // params to register bls pubkey with bls apk registry + g1HashedMsgToSign, err := registryCoordinator.PubkeyRegistrationMessageHash( + &bind.CallOpts{}, + operatorAddress, + ) + if err != nil { + return nil, err + } + signedMsg := chainioutils.ConvertToBN254G1Point( + blsKeyPair.SignHashedToCurveMessage(chainioutils.ConvertBn254GethToGnark(g1HashedMsgToSign)).G1Point, + ) + G1pubkeyBN254 := chainioutils.ConvertToBN254G1Point(blsKeyPair.GetPubKeyG1()) + G2pubkeyBN254 := chainioutils.ConvertToBN254G2Point(blsKeyPair.GetPubKeyG2()) + pubkeyRegParams := regcoord.IBLSApkRegistryPubkeyRegistrationParams{ + PubkeyRegistrationSignature: signedMsg, + PubkeyG1: G1pubkeyBN254, + PubkeyG2: G2pubkeyBN254, + } + return &pubkeyRegParams, nil +} + +func abiEncodeRegistrationParams( + socket string, + pubkeyRegistrationParams regcoord.IBLSApkRegistryPubkeyRegistrationParams, +) ([]byte, error) { + registrationParamsType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{ + {Name: "Socket", Type: "string"}, + {Name: "PubkeyRegParams", Type: "tuple", Components: []abi.ArgumentMarshaling{ + {Name: "PubkeyRegistrationSignature", Type: "tuple", Components: []abi.ArgumentMarshaling{ + {Name: "X", Type: "uint256"}, + {Name: "Y", Type: "uint256"}, + }}, + {Name: "PubkeyG1", Type: "tuple", Components: []abi.ArgumentMarshaling{ + {Name: "X", Type: "uint256"}, + {Name: "Y", Type: "uint256"}, + }}, + {Name: "PubkeyG2", Type: "tuple", Components: []abi.ArgumentMarshaling{ + {Name: "X", Type: "uint256[2]"}, + {Name: "Y", Type: "uint256[2]"}, + }}, + }}, + }) + if err != nil { + return nil, err + } + + registrationParams := struct { + Socket string + PubkeyRegParams regcoord.IBLSApkRegistryPubkeyRegistrationParams + }{ + socket, + pubkeyRegistrationParams, + } + + args := abi.Arguments{ + {Type: registrationParamsType, Name: "registrationParams"}, + } + + data, err := args.Pack(®istrationParams) + if err != nil { + return nil, err + } + // The encoder is prepending 32 bytes to the data as if it was used in a dynamic function parameter. + // This is not used when decoding the bytes directly, so we need to remove it. + return data[32:], nil +} From 58f8e492a5f62590ce6833938277d77a0217bab2 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 14:52:12 -0300 Subject: [PATCH 05/30] Add more test for slashable functions and utils --- chainio/clients/elcontracts/reader_test.go | 87 ++++++++++++++++++++-- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index b2f042fe..841c445c 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -3,17 +3,22 @@ package elcontracts_test import ( "context" "math/big" + "os" "testing" "github.com/Layr-Labs/eigensdk-go/chainio/clients" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AllocationManager" erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20" regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator" + "github.com/Layr-Labs/eigensdk-go/crypto/bls" + "github.com/Layr-Labs/eigensdk-go/logging" "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/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -123,25 +128,48 @@ func TestSlashableSharesFunctions(t *testing.T) { avsAddress := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") operatorAddress := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") + + operatorPrivateKeyHex := "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + operatorClients, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) + require.NoError(t, err) + erc20MockStrategyAddr := contractAddrs.Erc20MockStrategy - operatorsSets := []uint32{1, 2} + operatorSetId := uint32(1) - t.Run("Create First OperatorSet", func(t *testing.T) { - err := createOperatorSet(eigenClients, avsAddress, operatorsSets[0], erc20MockStrategyAddr) + t.Run("create First OperatorSet", func(t *testing.T) { + err := createOperatorSet(eigenClients, avsAddress, operatorSetId, erc20MockStrategyAddr) require.NoError(t, err) t.Log("First OperatorSet Created") }) - t.Run("Create Second OperatorSet", func(t *testing.T) { - err := createOperatorSet(eigenClients, avsAddress, operatorsSets[1], erc20MockStrategyAddr) + t.Run("Register Operator to OperatorSets", func(t *testing.T) { + keypair, err := bls.NewKeyPairFromString("0x01") require.NoError(t, err) - t.Log("Second OperatorSet Created") + + request := elcontracts.RegistrationRequest{ + OperatorAddress: operatorAddress, + AVSAddress: avsAddress, + OperatorSetIds: []uint32{operatorSetId}, + WaitForReceipt: true, + Socket: "socket", + BlsKeyPair: keypair, + } + + registryCoordinatorAddress := contractAddrs.RegistryCoordinator + receipt, err := operatorClients.ElChainWriter.RegisterForOperatorSets( + context.Background(), + registryCoordinatorAddress, + request, + ) + require.NoError(t, err) + require.Equal(t, uint64(1), receipt.Status) + t.Log("Operator Registered to OperatorSets") }) - t.Run("Get Slashable Shares for operatorSet1", func(t *testing.T) { + t.Run("get Slashable Shares for operatorSet1", func(t *testing.T) { operatorSet := allocationmanager.OperatorSet{ Avs: avsAddress, - Id: operatorsSets[0], + Id: operatorSetId, } strategies := []common.Address{erc20MockStrategyAddr} @@ -157,6 +185,21 @@ func TestSlashableSharesFunctions(t *testing.T) { t.Logf("Strategy: %s, Slashable Share: %s", strat.Hex(), share.String()) } }) + + t.Run("get Slashable Shares for Multiple OperatorSets", func(t *testing.T) { + operatorSets := []allocationmanager.OperatorSet{ + {Avs: avsAddress, Id: operatorSetId}, + } + + shares, err := eigenClients.ElChainReader.GetSlashableSharesForOperatorSets( + context.Background(), + operatorSets, + ) + require.NoError(t, err) + require.NotEmpty(t, shares) + require.Len(t, shares, 1) + t.Log("Slashable Shares: ", shares) + }) } func createOperatorSet( @@ -252,3 +295,31 @@ func createOperatorSet( _, err = client.TxManager.Send(context.Background(), tx, waitForReceipt) return err } + +func newTestClients(httpEndpoint string, privateKeyHex string) (*clients.Clients, error) { + contractAddrs := testutils.GetContractAddressesFromContractRegistry(httpEndpoint) + chainioConfig := clients.BuildAllConfig{ + EthHttpUrl: httpEndpoint, + EthWsUrl: httpEndpoint, + RegistryCoordinatorAddr: contractAddrs.RegistryCoordinator.String(), + OperatorStateRetrieverAddr: contractAddrs.OperatorStateRetriever.String(), + AvsName: "exampleAvs", + PromMetricsIpPortAddress: ":9090", + } + privateKey, err := crypto.HexToECDSA(privateKeyHex) + if err != nil { + return nil, err + } + testConfig := testutils.GetDefaultTestConfig() + logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) + + testClients, err := clients.BuildAll( + chainioConfig, + privateKey, + logger, + ) + if err != nil { + return nil, err + } + return testClients, nil +} From 53e01ea18b03e8cf4a0044a1e5a5b1531961f0d9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 15:16:29 -0300 Subject: [PATCH 06/30] Change address to constant values --- chainio/clients/elcontracts/reader_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 841c445c..b1296199 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -23,6 +23,12 @@ import ( "github.com/stretchr/testify/require" ) +const ( + ANVIL_FIRST_ADDRESS = "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + ANVIL_SECOND_ADDRESS = "70997970C51812dc3A010C7d01b50e0d17dc79C8" + ANVIL_SECOND_PRIVATE_KEY = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" +) + func TestChainReader(t *testing.T) { clients, anvilHttpEndpoint := testclients.BuildTestClients(t) ctx := context.Background() @@ -126,10 +132,10 @@ func TestSlashableSharesFunctions(t *testing.T) { eigenClients, anvilHttpEndpoint := testclients.BuildTestClients(t) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - avsAddress := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") - operatorAddress := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") + avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) + operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) - operatorPrivateKeyHex := "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY operatorClients, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) require.NoError(t, err) From 5955c4b15931441fcff2a43b58372f2514b80b16 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 15:17:16 -0300 Subject: [PATCH 07/30] Remove t.Log --- chainio/clients/elcontracts/reader_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index b1296199..b6016eff 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -145,7 +145,6 @@ func TestSlashableSharesFunctions(t *testing.T) { t.Run("create First OperatorSet", func(t *testing.T) { err := createOperatorSet(eigenClients, avsAddress, operatorSetId, erc20MockStrategyAddr) require.NoError(t, err) - t.Log("First OperatorSet Created") }) t.Run("Register Operator to OperatorSets", func(t *testing.T) { @@ -169,7 +168,6 @@ func TestSlashableSharesFunctions(t *testing.T) { ) require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) - t.Log("Operator Registered to OperatorSets") }) t.Run("get Slashable Shares for operatorSet1", func(t *testing.T) { @@ -187,9 +185,6 @@ func TestSlashableSharesFunctions(t *testing.T) { ) require.NoError(t, err) require.NotEmpty(t, shares) - for strat, share := range shares { - t.Logf("Strategy: %s, Slashable Share: %s", strat.Hex(), share.String()) - } }) t.Run("get Slashable Shares for Multiple OperatorSets", func(t *testing.T) { @@ -204,7 +199,6 @@ func TestSlashableSharesFunctions(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, shares) require.Len(t, shares, 1) - t.Log("Slashable Shares: ", shares) }) } From 7f5d030b4bae829b32b4d88ab8ce45461f14d1d9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 15:19:00 -0300 Subject: [PATCH 08/30] Run fmt --- chainio/clients/elcontracts/reader_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index b6016eff..b9139f0a 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -24,9 +24,9 @@ import ( ) const ( - ANVIL_FIRST_ADDRESS = "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - ANVIL_SECOND_ADDRESS = "70997970C51812dc3A010C7d01b50e0d17dc79C8" - ANVIL_SECOND_PRIVATE_KEY = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + ANVIL_FIRST_ADDRESS = "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + ANVIL_SECOND_ADDRESS = "70997970C51812dc3A010C7d01b50e0d17dc79C8" + ANVIL_SECOND_PRIVATE_KEY = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" ) func TestChainReader(t *testing.T) { @@ -133,8 +133,8 @@ func TestSlashableSharesFunctions(t *testing.T) { contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) - operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) + operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY operatorClients, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) require.NoError(t, err) From 6c4181ea86130d65d2983b9e26b4116cbf4bed77 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 16:15:56 -0300 Subject: [PATCH 09/30] Some refactor and add new test cases for getoperatorsets --- chainio/clients/elcontracts/reader_test.go | 77 +++++++++++++++++----- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index b9139f0a..67adf228 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -27,6 +27,8 @@ const ( ANVIL_FIRST_ADDRESS = "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ANVIL_SECOND_ADDRESS = "70997970C51812dc3A010C7d01b50e0d17dc79C8" ANVIL_SECOND_PRIVATE_KEY = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + ANVIL_THIRD_ADDRESS = "3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" + ANVIL_THIRD_PRIVATE_KEY = "5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a" ) func TestChainReader(t *testing.T) { @@ -128,26 +130,33 @@ func TestChainReader(t *testing.T) { }) } -func TestSlashableSharesFunctions(t *testing.T) { - eigenClients, anvilHttpEndpoint := testclients.BuildTestClients(t) +func TestOperatorSetsAndSlashableShares(t *testing.T) { + client, anvilHttpEndpoint := testclients.BuildTestClients(t) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY - operatorClients, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) + operatorClient, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) require.NoError(t, err) erc20MockStrategyAddr := contractAddrs.Erc20MockStrategy operatorSetId := uint32(1) - t.Run("create First OperatorSet", func(t *testing.T) { - err := createOperatorSet(eigenClients, avsAddress, operatorSetId, erc20MockStrategyAddr) - require.NoError(t, err) - }) + operatorSet := allocationmanager.OperatorSet{ + Avs: avsAddress, + Id: operatorSetId, + } + + operatorSets := []allocationmanager.OperatorSet{ + {Avs: avsAddress, Id: operatorSetId}, + } + + err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) + require.NoError(t, err) - t.Run("Register Operator to OperatorSets", func(t *testing.T) { + t.Run("register operator to operatorsets", func(t *testing.T) { keypair, err := bls.NewKeyPairFromString("0x01") require.NoError(t, err) @@ -161,7 +170,7 @@ func TestSlashableSharesFunctions(t *testing.T) { } registryCoordinatorAddress := contractAddrs.RegistryCoordinator - receipt, err := operatorClients.ElChainWriter.RegisterForOperatorSets( + receipt, err := operatorClient.ElChainWriter.RegisterForOperatorSets( context.Background(), registryCoordinatorAddress, request, @@ -170,14 +179,38 @@ func TestSlashableSharesFunctions(t *testing.T) { require.Equal(t, uint64(1), receipt.Status) }) - t.Run("get Slashable Shares for operatorSet1", func(t *testing.T) { + t.Run("validate operator registration", func(t *testing.T) { + operators, err := client.ElChainReader.GetOperatorsForOperatorSet( + context.Background(), + allocationmanager.OperatorSet{Avs: avsAddress, Id: operatorSetId}, + ) + t.Log(operators) + require.NoError(t, err) + require.Len(t, operators, 1) + }) + + t.Run("get number of operator sets for an operator", func(t *testing.T) { + numOperatorSets, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) + require.NoError(t, err) + require.Equal(t, big.NewInt(1), numOperatorSets) + }) + + t.Run("validate strategies for OperatorSet", func(t *testing.T) { + + strategies, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) + require.NoError(t, err) + require.Len(t, strategies, 1) + require.Equal(t, strategies[0].Hex(), erc20MockStrategyAddr.Hex()) + }) + + t.Run("get slashable shares for a single operator", func(t *testing.T) { operatorSet := allocationmanager.OperatorSet{ Avs: avsAddress, Id: operatorSetId, } strategies := []common.Address{erc20MockStrategyAddr} - shares, err := eigenClients.ElChainReader.GetSlashableShares( + shares, err := client.ElChainReader.GetSlashableShares( context.Background(), operatorAddress, operatorSet, @@ -187,12 +220,8 @@ func TestSlashableSharesFunctions(t *testing.T) { require.NotEmpty(t, shares) }) - t.Run("get Slashable Shares for Multiple OperatorSets", func(t *testing.T) { - operatorSets := []allocationmanager.OperatorSet{ - {Avs: avsAddress, Id: operatorSetId}, - } - - shares, err := eigenClients.ElChainReader.GetSlashableSharesForOperatorSets( + t.Run("get slashable shares for multiple operator sets", func(t *testing.T) { + shares, err := client.ElChainReader.GetSlashableSharesForOperatorSets( context.Background(), operatorSets, ) @@ -200,6 +229,20 @@ func TestSlashableSharesFunctions(t *testing.T) { require.NotEmpty(t, shares) require.Len(t, shares, 1) }) + + t.Run("get register operator sets for an operator", func(t *testing.T) { + sets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) + require.NoError(t, err) + require.NotEmpty(t, sets) + require.Len(t, sets, 1) + }) + + t.Run("get slashable shares before a specific block height", func(t *testing.T) { + shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 0) + require.NoError(t, err) + require.NotEmpty(t, shares) + require.Len(t, shares, 1) + }) } func createOperatorSet( From 10f0a9812f9376077f93110cd81fda116cd7c5a2 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 17:16:42 -0300 Subject: [PATCH 10/30] Run fmt --- chainio/clients/elcontracts/writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index d1b58e0e..2c70d3d1 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -615,7 +615,7 @@ func (w *ChainWriter) RegisterForOperatorSets( allocationmanager.IAllocationManagerTypesRegisterParams{ Avs: request.AVSAddress, OperatorSetIds: request.OperatorSetIds, - Data: data, + Data: data, }) if err != nil { return nil, utils.WrapError("failed to create RegisterForOperatorSets tx", err) From 192d1653e713f2cefda30be677634117dfe11ec6 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Tue, 14 Jan 2025 17:28:38 -0300 Subject: [PATCH 11/30] Run make fmt --- chainio/clients/elcontracts/reader_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 67adf228..58144499 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -238,7 +238,11 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { }) t.Run("get slashable shares before a specific block height", func(t *testing.T) { - shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 0) + shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore( + context.Background(), + operatorSets, + 0, + ) require.NoError(t, err) require.NotEmpty(t, shares) require.Len(t, shares, 1) From 9a19a9739ab0d87e8a8359e64dfad2690898f4f9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 10:20:13 -0300 Subject: [PATCH 12/30] Add blocknumber and run make fmt --- chainio/clients/elcontracts/reader_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 58144499..972323c4 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -156,7 +156,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) require.NoError(t, err) - t.Run("register operator to operatorsets", func(t *testing.T) { + t.Run("register operator to operatorsets and validate it", func(t *testing.T) { keypair, err := bls.NewKeyPairFromString("0x01") require.NoError(t, err) @@ -177,9 +177,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { ) require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) - }) - t.Run("validate operator registration", func(t *testing.T) { operators, err := client.ElChainReader.GetOperatorsForOperatorSet( context.Background(), allocationmanager.OperatorSet{Avs: avsAddress, Id: operatorSetId}, @@ -196,7 +194,6 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { }) t.Run("validate strategies for OperatorSet", func(t *testing.T) { - strategies, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) require.Len(t, strategies, 1) @@ -238,10 +235,13 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { }) t.Run("get slashable shares before a specific block height", func(t *testing.T) { + blockNumber, err := client.EthHttpClient.BlockNumber(context.Background()) + require.NoError(t, err) + shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore( context.Background(), operatorSets, - 0, + uint32(blockNumber)+1, ) require.NoError(t, err) require.NotEmpty(t, shares) From 203e2ca861a9daee127a50ef5623f0f6f6de8937 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 11:50:16 -0300 Subject: [PATCH 13/30] Remove t.Log --- chainio/clients/elcontracts/reader_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 972323c4..00495bff 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -182,7 +182,6 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { context.Background(), allocationmanager.OperatorSet{Avs: avsAddress, Id: operatorSetId}, ) - t.Log(operators) require.NoError(t, err) require.Len(t, operators, 1) }) From 407969d6ae7397ee94e8526b084419605bc9b69f Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 15:24:03 -0300 Subject: [PATCH 14/30] Add more test cases --- chainio/clients/elcontracts/reader_test.go | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 00495bff..95bd0771 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -134,7 +134,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { client, anvilHttpEndpoint := testclients.BuildTestClients(t) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) + avsAddress := common.HexToAddress(ANVIL_THIRD_ADDRESS) operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY @@ -184,12 +184,36 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { ) require.NoError(t, err) require.Len(t, operators, 1) + t.Log("Operators: ", operators) + t.Logf("Operator Set: %+v", operatorSet) }) t.Run("get number of operator sets for an operator", func(t *testing.T) { numOperatorSets, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) require.Equal(t, big.NewInt(1), numOperatorSets) + t.Log("Number of operators: ", numOperatorSets) + t.Log("Operator Set: ", operatorSet) + }) + + // ME DA 0 + t.Run("get an operator for an operator set", func(t *testing.T) { + operatorSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) + t.Log("OperatorSets: ", operatorSets) + t.Log("Operator Address: ", operatorAddress) + require.NoError(t, err) + }) + + // ME DA 0 + t.Run("get number of operatorfor an operator set", func(t *testing.T) { + numOperatorSets, err := client.ElChainReader.GetNumOperatorSetsForOperator( + context.Background(), + operatorAddress, + ) + require.NoError(t, err) + // require.Equal(t, big.NewInt(1), numOperators) + t.Log("Number of operatorsSets: ", numOperatorSets) + t.Log("Operator Address: ", operatorAddress) }) t.Run("validate strategies for OperatorSet", func(t *testing.T) { From 095890bec0c772eacf9df62483b7288ce54719e1 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 15:58:39 -0300 Subject: [PATCH 15/30] Add new function that return the anvilC --- chainio/clients/elcontracts/reader_test.go | 48 +++++++++++++++++----- testutils/testclients/testclients.go | 41 ++++++++++++++++++ 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 95bd0771..caea4050 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -2,6 +2,7 @@ package elcontracts_test import ( "context" + "log" "math/big" "os" "testing" @@ -18,6 +19,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -131,10 +133,11 @@ func TestChainReader(t *testing.T) { } func TestOperatorSetsAndSlashableShares(t *testing.T) { - client, anvilHttpEndpoint := testclients.BuildTestClients(t) + client, anvilC, anvilHttpEndpoint := testclients.BuildTestClientsWithAnvilC(t) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + log.Printf("ContractAddress en reader_Test: %+v", contractAddrs) - avsAddress := common.HexToAddress(ANVIL_THIRD_ADDRESS) + avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY @@ -180,12 +183,35 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { operators, err := client.ElChainReader.GetOperatorsForOperatorSet( context.Background(), - allocationmanager.OperatorSet{Avs: avsAddress, Id: operatorSetId}, + operatorSet, ) require.NoError(t, err) require.Len(t, operators, 1) - t.Log("Operators: ", operators) - t.Logf("Operator Set: %+v", operatorSet) + t.Log("Tengo estos operators: ", operators) + t.Logf("Para este Operator Set: %+v", operatorSet) + }) + + t.Run("allocate delay", func(t *testing.T) { + waitForReceipt := true + delay := uint32(1) + // The allocation delay must be initialized before modifying the allocations + receipt, err := operatorClient.ElChainWriter.SetAllocationDelay( + context.Background(), + operatorAddress, + delay, + waitForReceipt, + ) + require.NoError(t, err) + require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) + + allocationConfigurationDelay := 1200 + // Advance the chain by the required number of blocks + // (ALLOCATION_CONFIGURATION_DELAY) to apply the allocation delay + testutils.AdvanceChainByNBlocksExecInContainer(context.Background(), allocationConfigurationDelay+1, anvilC) + + // Retrieve the allocation delay so that the delay is applied + _, err = operatorClient.ElChainReader.GetAllocationDelay(context.Background(), operatorAddress) + require.NoError(t, err) }) t.Run("get number of operator sets for an operator", func(t *testing.T) { @@ -193,19 +219,21 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) require.Equal(t, big.NewInt(1), numOperatorSets) t.Log("Number of operators: ", numOperatorSets) - t.Log("Operator Set: ", operatorSet) + t.Log("Para este Operator Set: ", operatorSet) }) // ME DA 0 - t.Run("get an operator for an operator set", func(t *testing.T) { + t.Run("get an operator set for an operator address", func(t *testing.T) { operatorSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) t.Log("OperatorSets: ", operatorSets) - t.Log("Operator Address: ", operatorAddress) + t.Log("Len of OperatorSets: ", len(operatorSets)) + t.Log("De este Operator Address: ", operatorAddress) require.NoError(t, err) + }) // ME DA 0 - t.Run("get number of operatorfor an operator set", func(t *testing.T) { + t.Run("get number of operator set for an operator address", func(t *testing.T) { numOperatorSets, err := client.ElChainReader.GetNumOperatorSetsForOperator( context.Background(), operatorAddress, @@ -213,7 +241,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) // require.Equal(t, big.NewInt(1), numOperators) t.Log("Number of operatorsSets: ", numOperatorSets) - t.Log("Operator Address: ", operatorAddress) + t.Log("De este Operator Address: ", operatorAddress) }) t.Run("validate strategies for OperatorSet", func(t *testing.T) { diff --git a/testutils/testclients/testclients.go b/testutils/testclients/testclients.go index 336ee8a9..a5eccc82 100644 --- a/testutils/testclients/testclients.go +++ b/testutils/testclients/testclients.go @@ -2,6 +2,7 @@ package testclients import ( "context" + "log" "os" "testing" @@ -10,6 +11,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/testutils" "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" ) // Starts an anvil container and builds the ChainIO Clients for testing. @@ -30,6 +32,7 @@ func BuildTestClients(t *testing.T) (*clients.Clients, string) { require.NoError(t, err) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + log.Printf("ContractAddress en testclients: %+v", contractAddrs) require.NoError(t, err) chainioConfig := clients.BuildAllConfig{ @@ -49,3 +52,41 @@ func BuildTestClients(t *testing.T) (*clients.Clients, string) { require.NoError(t, err) return clients, anvilHttpEndpoint } + +func BuildTestClientsWithAnvilC(t *testing.T) (*clients.Clients, testcontainers.Container, string) { + testConfig := testutils.GetDefaultTestConfig() + anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) + require.NoError(t, err) + + anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") + require.NoError(t, err) + + anvilWsEndpoint, err := anvilC.Endpoint(context.Background(), "ws") + require.NoError(t, err) + logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) + + privateKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" + ecdsaPrivateKey, err := crypto.HexToECDSA(privateKeyHex) + require.NoError(t, err) + + contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + log.Printf("ContractAddress en testclients: %+v", contractAddrs) + require.NoError(t, err) + + chainioConfig := clients.BuildAllConfig{ + EthHttpUrl: anvilHttpEndpoint, + EthWsUrl: anvilWsEndpoint, + RegistryCoordinatorAddr: contractAddrs.RegistryCoordinator.String(), + OperatorStateRetrieverAddr: contractAddrs.OperatorStateRetriever.String(), + AvsName: "exampleAvs", + PromMetricsIpPortAddress: ":9090", + } + + clients, err := clients.BuildAll( + chainioConfig, + ecdsaPrivateKey, + logger, + ) + require.NoError(t, err) + return clients, anvilC, anvilHttpEndpoint +} From a9651386268c4b626f79ca82f7bd1ed921ccd515 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 17:51:29 -0300 Subject: [PATCH 16/30] Remove unnecessary t.Logs --- testutils/testclients/testclients.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/testutils/testclients/testclients.go b/testutils/testclients/testclients.go index a5eccc82..79183fcf 100644 --- a/testutils/testclients/testclients.go +++ b/testutils/testclients/testclients.go @@ -2,7 +2,6 @@ package testclients import ( "context" - "log" "os" "testing" @@ -32,7 +31,6 @@ func BuildTestClients(t *testing.T) (*clients.Clients, string) { require.NoError(t, err) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - log.Printf("ContractAddress en testclients: %+v", contractAddrs) require.NoError(t, err) chainioConfig := clients.BuildAllConfig{ @@ -70,7 +68,6 @@ func BuildTestClientsWithAnvilC(t *testing.T) (*clients.Clients, testcontainers. require.NoError(t, err) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - log.Printf("ContractAddress en testclients: %+v", contractAddrs) require.NoError(t, err) chainioConfig := clients.BuildAllConfig{ From b72c6a2983229f1c70e503dcaaedc959a2688118 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 17:51:59 -0300 Subject: [PATCH 17/30] Finish with the test and refactor --- chainio/clients/elcontracts/reader_test.go | 193 +++++++++------------ 1 file changed, 85 insertions(+), 108 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index caea4050..daa98171 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -2,7 +2,6 @@ package elcontracts_test import ( "context" - "log" "math/big" "os" "testing" @@ -135,10 +134,8 @@ func TestChainReader(t *testing.T) { func TestOperatorSetsAndSlashableShares(t *testing.T) { client, anvilC, anvilHttpEndpoint := testclients.BuildTestClientsWithAnvilC(t) contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - log.Printf("ContractAddress en reader_Test: %+v", contractAddrs) avsAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) - operatorAddress := common.HexToAddress(ANVIL_SECOND_ADDRESS) operatorPrivateKeyHex := ANVIL_SECOND_PRIVATE_KEY operatorClient, err := newTestClients(anvilHttpEndpoint, operatorPrivateKeyHex) @@ -152,99 +149,94 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { Id: operatorSetId, } - operatorSets := []allocationmanager.OperatorSet{ - {Avs: avsAddress, Id: operatorSetId}, - } - - err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) - require.NoError(t, err) - - t.Run("register operator to operatorsets and validate it", func(t *testing.T) { - keypair, err := bls.NewKeyPairFromString("0x01") - require.NoError(t, err) - - request := elcontracts.RegistrationRequest{ - OperatorAddress: operatorAddress, - AVSAddress: avsAddress, - OperatorSetIds: []uint32{operatorSetId}, - WaitForReceipt: true, - Socket: "socket", - BlsKeyPair: keypair, - } - - registryCoordinatorAddress := contractAddrs.RegistryCoordinator - receipt, err := operatorClient.ElChainWriter.RegisterForOperatorSets( - context.Background(), - registryCoordinatorAddress, - request, - ) - require.NoError(t, err) - require.Equal(t, uint64(1), receipt.Status) - - operators, err := client.ElChainReader.GetOperatorsForOperatorSet( - context.Background(), - operatorSet, - ) - require.NoError(t, err) - require.Len(t, operators, 1) - t.Log("Tengo estos operators: ", operators) - t.Logf("Para este Operator Set: %+v", operatorSet) - }) - - t.Run("allocate delay", func(t *testing.T) { - waitForReceipt := true - delay := uint32(1) - // The allocation delay must be initialized before modifying the allocations - receipt, err := operatorClient.ElChainWriter.SetAllocationDelay( - context.Background(), - operatorAddress, - delay, - waitForReceipt, - ) - require.NoError(t, err) - require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) - - allocationConfigurationDelay := 1200 - // Advance the chain by the required number of blocks - // (ALLOCATION_CONFIGURATION_DELAY) to apply the allocation delay - testutils.AdvanceChainByNBlocksExecInContainer(context.Background(), allocationConfigurationDelay+1, anvilC) - - // Retrieve the allocation delay so that the delay is applied - _, err = operatorClient.ElChainReader.GetAllocationDelay(context.Background(), operatorAddress) - require.NoError(t, err) - }) + strategies := []common.Address{erc20MockStrategyAddr} - t.Run("get number of operator sets for an operator", func(t *testing.T) { - numOperatorSets, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) + t.Run("create operator set", func(t *testing.T) { + err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) require.NoError(t, err) - require.Equal(t, big.NewInt(1), numOperatorSets) - t.Log("Number of operators: ", numOperatorSets) - t.Log("Para este Operator Set: ", operatorSet) }) - // ME DA 0 - t.Run("get an operator set for an operator address", func(t *testing.T) { - operatorSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) - t.Log("OperatorSets: ", operatorSets) - t.Log("Len of OperatorSets: ", len(operatorSets)) - t.Log("De este Operator Address: ", operatorAddress) - require.NoError(t, err) - + t.Run("register and allocate stake", func(t *testing.T) { + t.Run("register operator to operator set and verify", func(t *testing.T) { + keypair, err := bls.NewKeyPairFromString("0x01") + require.NoError(t, err) + + request := elcontracts.RegistrationRequest{ + OperatorAddress: operatorAddress, + AVSAddress: avsAddress, + OperatorSetIds: []uint32{operatorSetId}, + WaitForReceipt: true, + Socket: "socket", + BlsKeyPair: keypair, + } + + registryCoordinatorAddress := contractAddrs.RegistryCoordinator + receipt, err := operatorClient.ElChainWriter.RegisterForOperatorSets( + context.Background(), + registryCoordinatorAddress, + request, + ) + require.NoError(t, err) + require.Equal(t, uint64(1), receipt.Status) + + operators, err := client.ElChainReader.GetOperatorsForOperatorSet( + context.Background(), + operatorSet, + ) + require.NoError(t, err) + require.Len(t, operators, 1) + + numOperator, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) + require.NoError(t, err) + require.Equal(t, big.NewInt(1), numOperator) + }) + + t.Run("allocate stake for operator", func(t *testing.T) { + const allocationDelay = 1 + const allocationMagnitude = 100 + const allocationConfigurationDelay = 1200 + + receipt, err := operatorClient.ElChainWriter.SetAllocationDelay( + context.Background(), + operatorAddress, + 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: []common.Address{erc20MockStrategyAddr}, + NewMagnitudes: []uint64{allocationMagnitude}, + }, + } + + receipt, err = operatorClient.ElChainWriter.ModifyAllocations( + context.Background(), + operatorAddress, + allocationParams, + true, + ) + require.NoError(t, err) + require.Equal(t, uint64(1), receipt.Status) + }) + + t.Run("get operator sets for operator after allocation", func(t *testing.T) { + opSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) + require.NoError(t, err) + require.NotEmpty(t, opSets) + + numOpSets, err := client.ElChainReader.GetNumOperatorSetsForOperator(context.Background(), operatorAddress) + require.NoError(t, err) + require.Equal(t, big.NewInt(1), numOpSets) + }) }) - // ME DA 0 - t.Run("get number of operator set for an operator address", func(t *testing.T) { - numOperatorSets, err := client.ElChainReader.GetNumOperatorSetsForOperator( - context.Background(), - operatorAddress, - ) - require.NoError(t, err) - // require.Equal(t, big.NewInt(1), numOperators) - t.Log("Number of operatorsSets: ", numOperatorSets) - t.Log("De este Operator Address: ", operatorAddress) - }) - - t.Run("validate strategies for OperatorSet", func(t *testing.T) { + t.Run("validate strategies for operator set", func(t *testing.T) { strategies, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) require.Len(t, strategies, 1) @@ -252,12 +244,6 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { }) t.Run("get slashable shares for a single operator", func(t *testing.T) { - operatorSet := allocationmanager.OperatorSet{ - Avs: avsAddress, - Id: operatorSetId, - } - strategies := []common.Address{erc20MockStrategyAddr} - shares, err := client.ElChainReader.GetSlashableShares( context.Background(), operatorAddress, @@ -271,32 +257,23 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { t.Run("get slashable shares for multiple operator sets", func(t *testing.T) { shares, err := client.ElChainReader.GetSlashableSharesForOperatorSets( context.Background(), - operatorSets, + []allocationmanager.OperatorSet{operatorSet}, ) require.NoError(t, err) require.NotEmpty(t, shares) - require.Len(t, shares, 1) - }) - - t.Run("get register operator sets for an operator", func(t *testing.T) { - sets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) - require.NoError(t, err) - require.NotEmpty(t, sets) - require.Len(t, sets, 1) }) - t.Run("get slashable shares before a specific block height", func(t *testing.T) { + t.Run("Get slashable shares before a specific block height", func(t *testing.T) { blockNumber, err := client.EthHttpClient.BlockNumber(context.Background()) require.NoError(t, err) shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore( context.Background(), - operatorSets, + []allocationmanager.OperatorSet{operatorSet}, uint32(blockNumber)+1, ) require.NoError(t, err) require.NotEmpty(t, shares) - require.Len(t, shares, 1) }) } From 12121e7f60aa404621b433c470f2f0fb3c3c1884 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Wed, 15 Jan 2025 18:01:02 -0300 Subject: [PATCH 18/30] Add test case for GetRegisteredSets --- chainio/clients/elcontracts/reader_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index daa98171..c857188c 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -179,6 +179,10 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) + registeredSets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) + require.NoError(t, err) + require.NotEmpty(t, registeredSets) + operators, err := client.ElChainReader.GetOperatorsForOperatorSet( context.Background(), operatorSet, From e6a0e62c6cd4bcbf7cd337ce21205e4ecd34ab41 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 16 Jan 2025 15:36:46 -0300 Subject: [PATCH 19/30] Add functions to create readers and writers --- testutils/testclients/testclients.go | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/testutils/testclients/testclients.go b/testutils/testclients/testclients.go index 79183fcf..9f9b4bc2 100644 --- a/testutils/testclients/testclients.go +++ b/testutils/testclients/testclients.go @@ -6,9 +6,17 @@ import ( "testing" "github.com/Layr-Labs/eigensdk-go/chainio/clients" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" + "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/metrics" + "github.com/Layr-Labs/eigensdk-go/signerv2" "github.com/Layr-Labs/eigensdk-go/testutils" + "github.com/Layr-Labs/eigensdk-go/utils" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" ) @@ -51,6 +59,108 @@ func BuildTestClients(t *testing.T) (*clients.Clients, string) { return clients, anvilHttpEndpoint } +// Creates a testing ChainWriter from an httpEndpoint, private key and config. +// This is needed because the existing testclients.BuildTestClients returns a +// ChainReader with a null rewardsCoordinator, which is required for some of the tests. +func NewTestChainReaderFromConfig( + httpEndpoint string, + config elcontracts.Config, +) (*elcontracts.ChainReader, error) { + testConfig := testutils.GetDefaultTestConfig() + logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) + ethHttpClient, err := ethclient.Dial(httpEndpoint) + if err != nil { + return nil, utils.WrapError("Failed to create eth client", err) + } + + testReader, err := elcontracts.NewReaderFromConfig( + config, + ethHttpClient, + logger, + ) + if err != nil { + return nil, utils.WrapError("Failed to create chain reader from config", err) + } + return testReader, nil +} + +// Creates a testing ChainWriter from an httpEndpoint, private key and config. +// This is needed because the existing testclients.BuildTestClients returns a +// ChainWriter with a null rewardsCoordinator, which is required for some of the tests. +func NewTestChainWriterFromConfig( + httpEndpoint string, + privateKeyHex string, + config elcontracts.Config, +) (*elcontracts.ChainWriter, error) { + privateKey, err := crypto.HexToECDSA(privateKeyHex) + if err != nil { + return nil, utils.WrapError("Failed convert hex string to ecdsa private key", err) + } + testConfig := testutils.GetDefaultTestConfig() + logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) + ethHttpClient, err := ethclient.Dial(httpEndpoint) + if err != nil { + return nil, utils.WrapError("Failed to create eth client", err) + } + chainid, err := ethHttpClient.ChainID(context.Background()) + if err != nil { + return nil, utils.WrapError("Failed to get chain id", err) + } + promReg := prometheus.NewRegistry() + eigenMetrics := metrics.NewEigenMetrics("", "", promReg, logger) + signerV2, addr, err := signerv2.SignerFromConfig(signerv2.Config{PrivateKey: privateKey}, chainid) + if err != nil { + return nil, utils.WrapError("Failed to create the signer from the given config", err) + } + + pkWallet, err := wallet.NewPrivateKeyWallet(ethHttpClient, signerV2, addr, logger) + if err != nil { + return nil, utils.WrapError("Failed to create wallet", err) + } + txManager := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr) + testWriter, err := elcontracts.NewWriterFromConfig( + config, + ethHttpClient, + logger, + eigenMetrics, + txManager, + ) + if err != nil { + return nil, err + } + return testWriter, nil +} + +func NewTestTxManager(httpEndpoint string, privateKeyHex string) (*txmgr.SimpleTxManager, error) { + testConfig := testutils.GetDefaultTestConfig() + ethHttpClient, err := ethclient.Dial(httpEndpoint) + if err != nil { + return nil, utils.WrapError("Failed to create eth client", err) + } + + chainid, err := ethHttpClient.ChainID(context.Background()) + if err != nil { + return nil, utils.WrapError("Failed to retrieve chain id", err) + } + privateKey, err := crypto.HexToECDSA(privateKeyHex) + if err != nil { + return nil, utils.WrapError("Failed to convert hex string to private key", err) + } + signerV2, addr, err := signerv2.SignerFromConfig(signerv2.Config{PrivateKey: privateKey}, chainid) + if err != nil { + return nil, utils.WrapError("Failed to create signer", err) + } + + logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) + + pkWallet, err := wallet.NewPrivateKeyWallet(ethHttpClient, signerV2, addr, logger) + if err != nil { + return nil, utils.WrapError("Failed to create wallet", err) + } + + txManager := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr) + return txManager, nil +} func BuildTestClientsWithAnvilC(t *testing.T) (*clients.Clients, testcontainers.Container, string) { testConfig := testutils.GetDefaultTestConfig() anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) From 1c970577e51d7af5c0cc0ea95c655f84a4eb9683 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 16 Jan 2025 15:37:13 -0300 Subject: [PATCH 20/30] Check if allocationmanager address is not null --- chainio/clients/elcontracts/reader.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index fdc608e3..90880a98 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -476,6 +476,10 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( ctx context.Context, operatorAddress gethcommon.Address, ) (*big.Int, error) { + if r.allocationManager == nil { + return nil, errors.New("AllocationManager contract not provided") + } + opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { return nil, err @@ -491,6 +495,10 @@ func (r *ChainReader) GetOperatorSetsForOperator( ) ([]allocationmanager.OperatorSet, error) { // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to // paginate? + if r.allocationManager == nil { + return nil, errors.New("AllocationManager contract not provided") + } + return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) } @@ -623,6 +631,10 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( operatorSets []allocationmanager.OperatorSet, futureBlock uint32, ) ([]OperatorSetStakes, error) { + if r.allocationManager == nil { + return nil, errors.New("AllocationManager contract not provided") + } + operatorSetStakes := make([]OperatorSetStakes, len(operatorSets)) for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) From f8eaa89f081ca8fa0a16a66a63144ea81d1d580e Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 16 Jan 2025 15:38:04 -0300 Subject: [PATCH 21/30] Add test for edge cases and wrong input --- chainio/clients/elcontracts/reader_test.go | 191 +++++++++++++++------ 1 file changed, 138 insertions(+), 53 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index c857188c..2701fe9b 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -151,13 +151,12 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { strategies := []common.Address{erc20MockStrategyAddr} - t.Run("create operator set", func(t *testing.T) { - err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) - require.NoError(t, err) + t.Run("Create and configure OperatorSet", func(t *testing.T) { + require.NoError(t, createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr)) }) - t.Run("register and allocate stake", func(t *testing.T) { - t.Run("register operator to operator set and verify", func(t *testing.T) { + t.Run("Register Operator and Allocate Stake", func(t *testing.T) { + t.Run("Register Operator to OperatorSet", func(t *testing.T) { keypair, err := bls.NewKeyPairFromString("0x01") require.NoError(t, err) @@ -178,24 +177,9 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { ) require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) - - registeredSets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) - require.NoError(t, err) - require.NotEmpty(t, registeredSets) - - operators, err := client.ElChainReader.GetOperatorsForOperatorSet( - context.Background(), - operatorSet, - ) - require.NoError(t, err) - require.Len(t, operators, 1) - - numOperator, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) - require.NoError(t, err) - require.Equal(t, big.NewInt(1), numOperator) }) - t.Run("allocate stake for operator", func(t *testing.T) { + t.Run("Allocate Stake for Operator", func(t *testing.T) { const allocationDelay = 1 const allocationMagnitude = 100 const allocationConfigurationDelay = 1200 @@ -209,12 +193,16 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) - testutils.AdvanceChainByNBlocksExecInContainer(context.Background(), allocationConfigurationDelay+1, anvilC) + testutils.AdvanceChainByNBlocksExecInContainer( + context.Background(), + allocationConfigurationDelay+1, + anvilC, + ) allocationParams := []allocationmanager.IAllocationManagerTypesAllocateParams{ { OperatorSet: operatorSet, - Strategies: []common.Address{erc20MockStrategyAddr}, + Strategies: strategies, NewMagnitudes: []uint64{allocationMagnitude}, }, } @@ -228,56 +216,153 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) }) + }) + + t.Run("Validation Tests", func(t *testing.T) { + t.Run("Get Registered Sets", func(t *testing.T) { + registeredSets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) + require.NoError(t, err) + require.NotEmpty(t, registeredSets) + }) - t.Run("get operator sets for operator after allocation", func(t *testing.T) { + t.Run("Validate Strategies for OperatorSet", func(t *testing.T) { + strats, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) + require.NoError(t, err) + require.Len(t, strats, 1) + require.Equal(t, strats[0].Hex(), erc20MockStrategyAddr.Hex()) + }) + + t.Run("Get OperatorSets for Operator", func(t *testing.T) { opSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) require.NoError(t, err) require.NotEmpty(t, opSets) + }) + + t.Run("Get amount OperatorSets for Operator", func(t *testing.T) { + opSetsCount, err := client.ElChainReader.GetNumOperatorSetsForOperator( + context.Background(), + operatorAddress, + ) + require.NoError(t, err) + require.NotZero(t, opSetsCount) + }) - numOpSets, err := client.ElChainReader.GetNumOperatorSetsForOperator(context.Background(), operatorAddress) + t.Run("get operator for operatorsets", func(t *testing.T) { + operators, err := client.ElChainReader.GetOperatorsForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) - require.Equal(t, big.NewInt(1), numOpSets) + require.NotEmpty(t, operators) + require.Len(t, operators, 1) + }) + + t.Run("get amount of operators for operatorsets", func(t *testing.T) { + operatorsCount, err := client.ElChainReader.GetNumOperatorsForOperatorSet(context.Background(), operatorSet) + require.NoError(t, err) + require.NotZero(t, operatorsCount) }) }) - t.Run("validate strategies for operator set", func(t *testing.T) { - strategies, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) - require.NoError(t, err) - require.Len(t, strategies, 1) - require.Equal(t, strategies[0].Hex(), erc20MockStrategyAddr.Hex()) + t.Run("Slashable Shares Tests", func(t *testing.T) { + t.Run("Get Slashable Shares for Single Operator", func(t *testing.T) { + shares, err := client.ElChainReader.GetSlashableShares( + context.Background(), + operatorAddress, + operatorSet, + strategies, + ) + require.NoError(t, err) + require.NotEmpty(t, shares) + }) + + t.Run("Get Slashable Shares for Multiple OperatorSets", func(t *testing.T) { + shares, err := client.ElChainReader.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) { + blockNumber, err := client.EthHttpClient.BlockNumber(context.Background()) + require.NoError(t, err) + + shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore( + context.Background(), + []allocationmanager.OperatorSet{operatorSet}, + uint32(blockNumber)+1, + ) + require.NoError(t, err) + require.NotEmpty(t, shares) + }) }) +} + +func TestOperatorSetsWithWrongInput(t *testing.T) { + _, anvilHttpEndpoint := testclients.BuildTestClients(t) + ctx := context.Background() - t.Run("get slashable shares for a single operator", func(t *testing.T) { - shares, err := client.ElChainReader.GetSlashableShares( - context.Background(), + contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + operatorAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) + + // Empty addresses + config := elcontracts.Config{} + + // Invalid operatorSet ID + operatorSet := allocationmanager.OperatorSet{ + Avs: common.HexToAddress(ANVIL_SECOND_ADDRESS), + Id: 0, + } + + chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) + require.NoError(t, err) + + t.Run("get operators sets with no allocationManager address", func(t *testing.T) { + _, err = chainReader.GetRegisteredSets(ctx, operatorAddress) + require.Error(t, err) + + _, err = chainReader.GetOperatorSetsForOperator(ctx, operatorAddress) + require.Error(t, err) + + _, err = chainReader.GetNumOperatorSetsForOperator(ctx, operatorAddress) + require.Error(t, err) + + _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), nil, 0) + require.Error(t, err) + }) + + t.Run("test operatorSet with id 0", 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, operatorAddress, operatorSet, strategies, ) - require.NoError(t, err) - require.NotEmpty(t, shares) + require.Error(t, err) }) - t.Run("get slashable shares for multiple operator sets", func(t *testing.T) { - shares, err := client.ElChainReader.GetSlashableSharesForOperatorSets( - context.Background(), - []allocationmanager.OperatorSet{operatorSet}, - ) - require.NoError(t, err) - require.NotEmpty(t, shares) - }) + t.Run("get slashable shares with invalid operatorSet", func(t *testing.T) { + config := elcontracts.Config{ + DelegationManagerAddress: contractAddrs.DelegationManager, + } - t.Run("Get slashable shares before a specific block height", func(t *testing.T) { - blockNumber, err := client.EthHttpClient.BlockNumber(context.Background()) + chainReader, err = testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) require.NoError(t, err) - shares, err := client.ElChainReader.GetSlashableSharesForOperatorSetsBefore( - context.Background(), - []allocationmanager.OperatorSet{operatorSet}, - uint32(blockNumber)+1, - ) - require.NoError(t, err) - require.NotEmpty(t, shares) + operatorSets := []allocationmanager.OperatorSet{operatorSet} + + _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), operatorSets, 10) + require.Error(t, err) }) } From 778075bdc70d86e8fd527d64897303f900d16895 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 16 Jan 2025 15:56:22 -0300 Subject: [PATCH 22/30] Refactor and run make fmt --- chainio/clients/elcontracts/reader_test.go | 144 ++++++++++----------- 1 file changed, 67 insertions(+), 77 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 2701fe9b..cb84d05f 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -151,94 +151,87 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { strategies := []common.Address{erc20MockStrategyAddr} - t.Run("Create and configure OperatorSet", func(t *testing.T) { - require.NoError(t, createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr)) - }) + err = createOperatorSet(client, avsAddress, operatorSetId, erc20MockStrategyAddr) + require.NoError(t, err) - t.Run("Register Operator and Allocate Stake", func(t *testing.T) { - t.Run("Register Operator to OperatorSet", func(t *testing.T) { - keypair, err := bls.NewKeyPairFromString("0x01") - require.NoError(t, err) + keypair, err := bls.NewKeyPairFromString("0x01") + require.NoError(t, err) - request := elcontracts.RegistrationRequest{ - OperatorAddress: operatorAddress, - AVSAddress: avsAddress, - OperatorSetIds: []uint32{operatorSetId}, - WaitForReceipt: true, - Socket: "socket", - BlsKeyPair: keypair, - } - - registryCoordinatorAddress := contractAddrs.RegistryCoordinator - receipt, err := operatorClient.ElChainWriter.RegisterForOperatorSets( - context.Background(), - registryCoordinatorAddress, - request, - ) - require.NoError(t, err) - require.Equal(t, uint64(1), receipt.Status) - }) + request := elcontracts.RegistrationRequest{ + OperatorAddress: operatorAddress, + AVSAddress: avsAddress, + OperatorSetIds: []uint32{operatorSetId}, + WaitForReceipt: true, + Socket: "socket", + BlsKeyPair: keypair, + } - t.Run("Allocate Stake for Operator", func(t *testing.T) { - const allocationDelay = 1 - const allocationMagnitude = 100 - const allocationConfigurationDelay = 1200 + registryCoordinatorAddress := contractAddrs.RegistryCoordinator + receipt, err := operatorClient.ElChainWriter.RegisterForOperatorSets( + context.Background(), + registryCoordinatorAddress, + request, + ) + require.NoError(t, err) + require.Equal(t, uint64(1), receipt.Status) - receipt, err := operatorClient.ElChainWriter.SetAllocationDelay( - context.Background(), - operatorAddress, - allocationDelay, - true, - ) - require.NoError(t, err) - require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) + const allocationDelay = 1 + const allocationMagnitude = 100 + const allocationConfigurationDelay = 1200 - testutils.AdvanceChainByNBlocksExecInContainer( - context.Background(), - allocationConfigurationDelay+1, - anvilC, - ) + receipt, err = operatorClient.ElChainWriter.SetAllocationDelay( + context.Background(), + operatorAddress, + allocationDelay, + true, + ) + require.NoError(t, err) + require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) - allocationParams := []allocationmanager.IAllocationManagerTypesAllocateParams{ - { - OperatorSet: operatorSet, - Strategies: strategies, - NewMagnitudes: []uint64{allocationMagnitude}, - }, - } + testutils.AdvanceChainByNBlocksExecInContainer( + context.Background(), + allocationConfigurationDelay+1, + anvilC, + ) - receipt, err = operatorClient.ElChainWriter.ModifyAllocations( - context.Background(), - operatorAddress, - allocationParams, - true, - ) - require.NoError(t, err) - require.Equal(t, uint64(1), receipt.Status) - }) - }) + allocationParams := []allocationmanager.IAllocationManagerTypesAllocateParams{ + { + OperatorSet: operatorSet, + Strategies: strategies, + NewMagnitudes: []uint64{allocationMagnitude}, + }, + } - t.Run("Validation Tests", func(t *testing.T) { - t.Run("Get Registered Sets", func(t *testing.T) { - registeredSets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) - require.NoError(t, err) - require.NotEmpty(t, registeredSets) - }) + receipt, err = operatorClient.ElChainWriter.ModifyAllocations( + context.Background(), + operatorAddress, + allocationParams, + true, + ) + require.NoError(t, err) + require.Equal(t, uint64(1), receipt.Status) - t.Run("Validate Strategies for OperatorSet", func(t *testing.T) { + t.Run("get operators and operator sets", func(t *testing.T) { + t.Run("validate strategies for operatorSet", func(t *testing.T) { strats, err := client.ElChainReader.GetStrategiesForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) require.Len(t, strats, 1) require.Equal(t, strats[0].Hex(), erc20MockStrategyAddr.Hex()) }) - t.Run("Get OperatorSets for Operator", func(t *testing.T) { + t.Run("get registered sets", func(t *testing.T) { + registeredSets, err := client.ElChainReader.GetRegisteredSets(context.Background(), operatorAddress) + require.NoError(t, err) + require.NotEmpty(t, registeredSets) + }) + + t.Run("get operator sets for operator", func(t *testing.T) { opSets, err := client.ElChainReader.GetOperatorSetsForOperator(context.Background(), operatorAddress) require.NoError(t, err) require.NotEmpty(t, opSets) }) - t.Run("Get amount OperatorSets for Operator", func(t *testing.T) { + t.Run("get amount operatorSets for operator", func(t *testing.T) { opSetsCount, err := client.ElChainReader.GetNumOperatorSetsForOperator( context.Background(), operatorAddress, @@ -261,8 +254,8 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { }) }) - t.Run("Slashable Shares Tests", func(t *testing.T) { - t.Run("Get Slashable Shares for Single Operator", func(t *testing.T) { + t.Run("slashable shares tests", func(t *testing.T) { + t.Run("get slashable shares for single operator", func(t *testing.T) { shares, err := client.ElChainReader.GetSlashableShares( context.Background(), operatorAddress, @@ -273,7 +266,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NotEmpty(t, shares) }) - t.Run("Get Slashable Shares for Multiple OperatorSets", func(t *testing.T) { + t.Run("get slashable shares for multiple operatorSets", func(t *testing.T) { shares, err := client.ElChainReader.GetSlashableSharesForOperatorSets( context.Background(), []allocationmanager.OperatorSet{operatorSet}, @@ -282,7 +275,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NotEmpty(t, shares) }) - t.Run("Get Slashable Shares Before Specific Block", func(t *testing.T) { + t.Run("get slashable shares before specific block", func(t *testing.T) { blockNumber, err := client.EthHttpClient.BlockNumber(context.Background()) require.NoError(t, err) @@ -304,10 +297,7 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) operatorAddress := common.HexToAddress(ANVIL_FIRST_ADDRESS) - // Empty addresses config := elcontracts.Config{} - - // Invalid operatorSet ID operatorSet := allocationmanager.OperatorSet{ Avs: common.HexToAddress(ANVIL_SECOND_ADDRESS), Id: 0, @@ -316,7 +306,7 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) require.NoError(t, err) - t.Run("get operators sets with no allocationManager address", func(t *testing.T) { + t.Run("get operators sets with no allocationManager address", func(t *testing.T) { _, err = chainReader.GetRegisteredSets(ctx, operatorAddress) require.Error(t, err) @@ -330,7 +320,7 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { require.Error(t, err) }) - t.Run("test operatorSet with id 0", func(t *testing.T) { + t.Run("test operator set with invalid id", func(t *testing.T) { _, err := chainReader.GetOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) From c3a638a405ee66fa8193c5f40a3705c7892cf2f9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 16 Jan 2025 16:15:20 -0300 Subject: [PATCH 23/30] Fix typos and remove address check in reader --- chainio/clients/elcontracts/reader.go | 12 ------------ chainio/clients/elcontracts/reader_test.go | 14 -------------- 2 files changed, 26 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 90880a98..fdc608e3 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -476,10 +476,6 @@ func (r *ChainReader) GetNumOperatorSetsForOperator( ctx context.Context, operatorAddress gethcommon.Address, ) (*big.Int, error) { - if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") - } - opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) if err != nil { return nil, err @@ -495,10 +491,6 @@ func (r *ChainReader) GetOperatorSetsForOperator( ) ([]allocationmanager.OperatorSet, error) { // TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to // paginate? - if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") - } - return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress) } @@ -631,10 +623,6 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( operatorSets []allocationmanager.OperatorSet, futureBlock uint32, ) ([]OperatorSetStakes, error) { - if r.allocationManager == nil { - return nil, errors.New("AllocationManager contract not provided") - } - operatorSetStakes := make([]OperatorSetStakes, len(operatorSets)) for i, operatorSet := range operatorSets { operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index cb84d05f..ccf4b951 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -306,20 +306,6 @@ func TestOperatorSetsWithWrongInput(t *testing.T) { chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) require.NoError(t, err) - t.Run("get operators sets with no allocationManager address", func(t *testing.T) { - _, err = chainReader.GetRegisteredSets(ctx, operatorAddress) - require.Error(t, err) - - _, err = chainReader.GetOperatorSetsForOperator(ctx, operatorAddress) - require.Error(t, err) - - _, err = chainReader.GetNumOperatorSetsForOperator(ctx, operatorAddress) - require.Error(t, err) - - _, err = chainReader.GetSlashableSharesForOperatorSetsBefore(context.Background(), nil, 0) - require.Error(t, err) - }) - t.Run("test operator set with invalid id", func(t *testing.T) { _, err := chainReader.GetOperatorsForOperatorSet(ctx, operatorSet) require.Error(t, err) From 9e2472540bd9b41c22a632efb2cbf25f4b5a1031 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Fri, 17 Jan 2025 15:47:43 -0300 Subject: [PATCH 24/30] Remove build client with anvil function --- testutils/testclients/testclients.go | 38 ---------------------------- 1 file changed, 38 deletions(-) diff --git a/testutils/testclients/testclients.go b/testutils/testclients/testclients.go index 4373b74f..28e1b48e 100644 --- a/testutils/testclients/testclients.go +++ b/testutils/testclients/testclients.go @@ -18,7 +18,6 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" ) // Starts an anvil container and builds the ChainIO Clients for testing. @@ -194,40 +193,3 @@ func NewTestTxManager(httpEndpoint string, privateKeyHex string) (*txmgr.SimpleT txManager := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr) return txManager, nil } - -func BuildTestClientsWithAnvilC(t *testing.T) (*clients.Clients, testcontainers.Container, string) { - testConfig := testutils.GetDefaultTestConfig() - anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) - require.NoError(t, err) - - anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") - require.NoError(t, err) - - anvilWsEndpoint, err := anvilC.Endpoint(context.Background(), "ws") - require.NoError(t, err) - logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: testConfig.LogLevel}) - - privateKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" - ecdsaPrivateKey, err := crypto.HexToECDSA(privateKeyHex) - require.NoError(t, err) - - contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) - require.NoError(t, err) - - chainioConfig := clients.BuildAllConfig{ - EthHttpUrl: anvilHttpEndpoint, - EthWsUrl: anvilWsEndpoint, - RegistryCoordinatorAddr: contractAddrs.RegistryCoordinator.String(), - OperatorStateRetrieverAddr: contractAddrs.OperatorStateRetriever.String(), - AvsName: "exampleAvs", - PromMetricsIpPortAddress: ":9090", - } - - clients, err := clients.BuildAll( - chainioConfig, - ecdsaPrivateKey, - logger, - ) - require.NoError(t, err) - return clients, anvilC, anvilHttpEndpoint -} From 53f13fe814ce71080a1357c27e11913cb1b26f2a Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Fri, 17 Jan 2025 15:55:50 -0300 Subject: [PATCH 25/30] Refactor and move some logic --- chainio/clients/elcontracts/reader_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 6753cb93..9d329e2c 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -748,27 +748,26 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { config := elcontracts.Config{ DelegationManagerAddress: contractAddrs.DelegationManager, } - chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) require.NoError(t, err) - operatorAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) - privateKeyHex := testutils.ANVIL_FIRST_PRIVATE_KEY - - chainWriter, err := testclients.NewTestChainWriterFromConfig(anvilHttpEndpoint, privateKeyHex, config) + 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, } - erc20MockStrategyAddr := contractAddrs.Erc20MockStrategy - strategies := []common.Address{erc20MockStrategyAddr} + strategyAddr := contractAddrs.Erc20MockStrategy + strategies := []common.Address{strategyAddr} - err = createOperatorSet(anvilHttpEndpoint, privateKeyHex, operatorAddr, operatorSetId, erc20MockStrategyAddr) + err = createOperatorSet(anvilHttpEndpoint, avsPrivateKeyHex, avsAdrr, operatorSetId, strategyAddr) require.NoError(t, err) keypair, err := bls.NewKeyPairFromString("0x01") @@ -833,7 +832,7 @@ func TestOperatorSetsAndSlashableShares(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(), erc20MockStrategyAddr.Hex()) + require.Equal(t, strats[0].Hex(), strategyAddr.Hex()) }) t.Run("get registered sets", func(t *testing.T) { @@ -846,6 +845,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { opSets, err := chainReader.GetOperatorSetsForOperator(context.Background(), operatorAddr) require.NoError(t, err) require.NotEmpty(t, opSets) + require.Len(t, opSets, 1) }) t.Run("get amount operatorSets for operator", func(t *testing.T) { From aab1903dc68bf7b4da368b09bc22e59018460d85 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Fri, 17 Jan 2025 16:10:38 -0300 Subject: [PATCH 26/30] Change test timeout to 5m --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e36cf383..08b4b02d 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ mocks: ## generates mocks .PHONY: tests tests: ## runs all tests - go test -race ./... -timeout=4m + go test -race ./... -timeout=5m .PHONY: tests-cover tests-cover: ## run all tests with test coverge From 9d32443d5e473179c5f6d1a61c7a4952918736e9 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Mon, 20 Jan 2025 09:17:50 -0300 Subject: [PATCH 27/30] Change const to variable --- chainio/clients/elcontracts/reader_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 9d329e2c..55b31ea6 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -791,14 +791,14 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(1), receipt.Status) - const allocationDelay = 1 - const allocationMagnitude = 100 - const allocationConfigurationDelay = 1200 + allocationDelay := 1 + allocationMagnitude := 100 + allocationConfigurationDelay := 1200 receipt, err = chainWriter.SetAllocationDelay( context.Background(), operatorAddr, - allocationDelay, + uint32(allocationDelay), true, ) require.NoError(t, err) @@ -814,7 +814,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { { OperatorSet: operatorSet, Strategies: strategies, - NewMagnitudes: []uint64{allocationMagnitude}, + NewMagnitudes: []uint64{uint64(allocationMagnitude)}, }, } From 4fbf68691a4bbf739fcff18fae0173b8f5c0a822 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Mon, 20 Jan 2025 09:18:37 -0300 Subject: [PATCH 28/30] Replace literal to geth type --- chainio/clients/elcontracts/reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 55b31ea6..fb98b666 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -825,7 +825,7 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { true, ) require.NoError(t, err) - require.Equal(t, uint64(1), receipt.Status) + require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) t.Run("get operators and operator sets", func(t *testing.T) { t.Run("validate strategies for operatorSet", func(t *testing.T) { From 1e9bf2da3e4223156519fb929168b61bc26854cd Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Mon, 20 Jan 2025 09:20:15 -0300 Subject: [PATCH 29/30] Remove redundant checks --- chainio/clients/elcontracts/reader_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index fb98b666..0604ef79 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -641,7 +641,6 @@ func TestAdminFunctions(t *testing.T) { listPendingAdmins, err := chainReader.ListPendingAdmins(context.Background(), operatorAddr) assert.NoError(t, err) assert.NotEmpty(t, listPendingAdmins) - assert.Len(t, listPendingAdmins, 1) }) t.Run("non-existent admin", func(t *testing.T) { @@ -845,7 +844,6 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { opSets, err := chainReader.GetOperatorSetsForOperator(context.Background(), operatorAddr) require.NoError(t, err) require.NotEmpty(t, opSets) - require.Len(t, opSets, 1) }) t.Run("get amount operatorSets for operator", func(t *testing.T) { @@ -861,7 +859,6 @@ func TestOperatorSetsAndSlashableShares(t *testing.T) { operators, err := chainReader.GetOperatorsForOperatorSet(context.Background(), operatorSet) require.NoError(t, err) require.NotEmpty(t, operators) - require.Len(t, operators, 1) }) t.Run("get amount of operators for operatorsets", func(t *testing.T) { From ca5f8b8fc4abc89bdce7f52659d05e21d32ca5c8 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Mon, 20 Jan 2025 17:45:18 -0300 Subject: [PATCH 30/30] Revert changes in writer.go --- chainio/clients/elcontracts/writer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index a71316af..7486bafe 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -9,6 +9,9 @@ import ( "math/big" + gethcommon "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" @@ -26,8 +29,6 @@ import ( "github.com/Layr-Labs/eigensdk-go/metrics" "github.com/Layr-Labs/eigensdk-go/types" "github.com/Layr-Labs/eigensdk-go/utils" - gethcommon "github.com/ethereum/go-ethereum/common" - gethtypes "github.com/ethereum/go-ethereum/core/types" ) type Reader interface { @@ -563,7 +564,6 @@ func (w *ChainWriter) RegisterForOperatorSets( if err != nil { return nil, utils.WrapError("failed to encode registration params", err) } - tx, err := w.allocationManager.RegisterForOperatorSets( noSendTxOpts, request.OperatorAddress,