Skip to content

Commit

Permalink
Merge branch 'dev' into test/add-failing-network-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli authored Jan 29, 2025
2 parents 7a3f515 + 96adf25 commit 2356657
Show file tree
Hide file tree
Showing 21 changed files with 1,147 additions and 494 deletions.
142 changes: 140 additions & 2 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry"
chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/testutils"
Expand All @@ -16,8 +17,23 @@ import (
)

func TestWriterMethods(t *testing.T) {
clients, _ := testclients.BuildTestClients(t)
chainWriter := clients.AvsRegistryChainWriter
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)

operatorPrivateKeyHex := testutils.ANVIL_FIRST_PRIVATE_KEY

config := avsregistry.Config{
RegistryCoordinatorAddress: contractAddrs.RegistryCoordinator,
OperatorStateRetrieverAddress: contractAddrs.OperatorStateRetriever,
}

chainWriter, err := testclients.NewTestAvsRegistryWriterFromConfig(anvilHttpEndpoint, operatorPrivateKeyHex, config)
require.NoError(t, err)

keypair, err := bls.NewKeyPairFromString("0x01")
require.NoError(t, err)
Expand All @@ -28,6 +44,16 @@ func TestWriterMethods(t *testing.T) {

quorumNumbers := types.QuorumNums{0}

t.Run("update socket without being registered", func(t *testing.T) {
receipt, err := chainWriter.UpdateSocket(
context.Background(),
types.Socket("102901920192019201902910291209"),
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("register operator", func(t *testing.T) {
receipt, err := chainWriter.RegisterOperator(
context.Background(),
Expand Down Expand Up @@ -72,6 +98,118 @@ func TestWriterMethods(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, receipt)
})

t.Run("update socket", func(t *testing.T) {
receipt, err := chainWriter.RegisterOperator(
context.Background(),
ecdsaPrivateKey,
keypair,
quorumNumbers,
"",
true,
)
require.NoError(t, err)
require.NotNil(t, receipt)

receipt, err = chainWriter.UpdateSocket(
context.Background(),
types.Socket(""),
true,
)
require.NoError(t, err)
require.NotNil(t, receipt)
})

// Error cases
t.Run("fail register operator cancelling context", func(t *testing.T) {
subCtx, cancelFn := context.WithCancel(context.Background())
cancelFn()
receipt, err := chainWriter.RegisterOperator(
subCtx,
ecdsaPrivateKey,
keypair,
quorumNumbers,
"",
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail update stake of operator subset cancelling context", func(t *testing.T) {
subCtx, cancelFn := context.WithCancel(context.Background())
cancelFn()
receipt, err := chainWriter.UpdateStakesOfOperatorSubsetForAllQuorums(
subCtx,
[]gethcommon.Address{addr},
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail update stake of entire operator set cancelling context", func(t *testing.T) {
subCtx, cancelFn := context.WithCancel(context.Background())
cancelFn()
receipt, err := chainWriter.UpdateStakesOfEntireOperatorSetForQuorums(
subCtx,
[][]gethcommon.Address{{addr}},
quorumNumbers,
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail update stake of entire operator set because of quorum length", func(t *testing.T) {
// Fails because operators per quorum length is distinct from quorum numbers
receipt, err := chainWriter.UpdateStakesOfEntireOperatorSetForQuorums(
context.Background(),
[][]gethcommon.Address{{addr, addr}},
quorumNumbers,
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail deregister operator cancelling context", func(t *testing.T) {
subCtx, cancelFn := context.WithCancel(context.Background())
cancelFn()
receipt, err := chainWriter.DeregisterOperator(
subCtx,
quorumNumbers,
chainioutils.ConvertToBN254G1Point(keypair.PubKey),
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail deregister operator because of operator not registered", func(t *testing.T) {
quorumNumbers := types.QuorumNums{}
receipt, err := chainWriter.DeregisterOperator(
context.Background(),
quorumNumbers,
chainioutils.ConvertToBN254G1Point(keypair.PubKey),
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("fail update socket cancelling context", func(t *testing.T) {
subCtx, cancelFn := context.WithCancel(context.Background())

cancelFn()
receipt, err := chainWriter.UpdateSocket(
subCtx,
types.Socket(""),
true,
)
assert.Error(t, err)
assert.Nil(t, receipt)
})
}

// Compliance test for BLS signature
Expand Down
188 changes: 187 additions & 1 deletion chainio/clients/eigenpod/bindings/IEigenPodManager.go

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func (r *ChainReader) GetStakerShares(
ctx context.Context,
stakerAddress gethcommon.Address,
) ([]gethcommon.Address, []*big.Int, error) {
if r.delegationManager == nil {
return nil, nil, errors.New("DelegationManager contract not provided")
}
return r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress)
}

Expand All @@ -117,6 +120,9 @@ func (r *ChainReader) GetDelegatedOperator(
stakerAddress gethcommon.Address,
blockNumber *big.Int,
) (gethcommon.Address, error) {
if r.delegationManager == nil {
return gethcommon.Address{}, errors.New("DelegationManager contract not provided")
}
return r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress)
}

Expand Down Expand Up @@ -433,6 +439,9 @@ 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
Expand All @@ -446,6 +455,9 @@ func (r *ChainReader) GetOperatorSetsForOperator(
ctx context.Context,
operatorAddress gethcommon.Address,
) ([]allocationmanager.OperatorSet, error) {
if r.allocationManager == nil {
return nil, errors.New("AllocationManager contract not provided")
}
// TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to
// paginate?
return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress)
Expand All @@ -459,6 +471,10 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet(
) (bool, error) {
if operatorSet.Id == 0 {
// this is an M2 AVS
if r.avsDirectory == nil {
return false, errors.New("AVSDirectory contract not provided")
}

status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress)
// This call should not fail since it's a getter
if err != nil {
Expand All @@ -467,6 +483,9 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet(

return status == 1, nil
} else {
if r.allocationManager == nil {
return false, errors.New("AllocationManager contract not provided")
}
registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress)
// This call should not fail since it's a getter
if err != nil {
Expand All @@ -491,6 +510,10 @@ func (r *ChainReader) GetOperatorsForOperatorSet(
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
if r.allocationManager == nil {
return nil, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet)
}
}
Expand All @@ -503,6 +526,10 @@ func (r *ChainReader) GetNumOperatorsForOperatorSet(
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
if r.allocationManager == nil {
return nil, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet)
}
}
Expand All @@ -516,6 +543,10 @@ func (r *ChainReader) GetStrategiesForOperatorSet(
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
if r.allocationManager == nil {
return nil, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet)
}
}
Expand Down
Loading

0 comments on commit 2356657

Please sign in to comment.