Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add attribute nil verifications in chainReader #448

Merged
merged 26 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e9e320b
Add error returning in contract tests cases
maximopalopoli Jan 17, 2025
169625f
Add base structure of invalid config tests
maximopalopoli Jan 17, 2025
2c08047
Add test case and check in GetStakerShares
maximopalopoli Jan 17, 2025
d66567c
Add if verification and test case with GetDelegatedOperator
maximopalopoli Jan 17, 2025
c7cdca5
Improve variable name in test
maximopalopoli Jan 17, 2025
2aa773c
Fix make fmt check
maximopalopoli Jan 17, 2025
6604273
Add verification and test for GetNumOperatorSetsForOperator
maximopalopoli Jan 17, 2025
c89bd76
Add verification and test case for GetOperatorSetsForOperator
maximopalopoli Jan 17, 2025
5b8b6ac
Add test cases and verifications for IsOperatorRegisteredWithOperatorSet
maximopalopoli Jan 17, 2025
983614a
Add verification and test case for GetOperatorsForOperatorSet
maximopalopoli Jan 17, 2025
2e013f9
Add validation and test case for GetNumOperatorsForOperatorSet
maximopalopoli Jan 17, 2025
caf388d
Add validation and test case for GetStrategiesForOperatorSet
maximopalopoli Jan 17, 2025
2b4f3c8
Fix terminology in a comment
maximopalopoli Jan 17, 2025
4f0d591
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 17, 2025
f4f198a
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 20, 2025
7f2008a
Remove unused variables in TestInvalidConfig
maximopalopoli Jan 20, 2025
dec5afb
Add comment clarifying literal number
maximopalopoli Jan 20, 2025
e48948e
Remove unnecesary asserts
maximopalopoli Jan 20, 2025
57a4868
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 20, 2025
20deb64
test: `chainReader` shares and operatorSets functions (#437)
damiramirez Jan 20, 2025
1c28c33
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 20, 2025
40e2e49
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 21, 2025
168fc48
Merge branch 'dev' into add-attribute-null-verifications
maximopalopoli Jan 21, 2025
55bf665
unify TestInvalidConfig variants
maximopalopoli Jan 21, 2025
f495e8c
Increase timeout window
maximopalopoli Jan 21, 2025
306038e
Revert timeout window increase
maximopalopoli Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading