-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add attribute nil verifications in chainReader #448
Changes from 15 commits
e9e320b
169625f
2c08047
d66567c
c7cdca5
2aa773c
6604273
c89bd76
5b8b6ac
983614a
2e013f9
caf388d
2b4f3c8
4f0d591
f4f198a
7f2008a
dec5afb
e48948e
57a4868
20deb64
1c28c33
40e2e49
168fc48
55bf665
f495e8c
306038e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,11 +130,11 @@ func TestChainReader(t *testing.T) { | |
}) | ||
|
||
t.Run("get delegated operator", func(t *testing.T) { | ||
val := big.NewInt(0) | ||
blockNumber := big.NewInt(0) | ||
address, err := read_clients.ElChainReader.GetDelegatedOperator( | ||
ctx, | ||
common.HexToAddress(operator.Address), | ||
val, | ||
blockNumber, | ||
) | ||
|
||
assert.NoError(t, err) | ||
|
@@ -734,3 +734,182 @@ func TestAppointeesFunctions(t *testing.T) { | |
assert.NotEmpty(t, appointeesPermission) | ||
}) | ||
} | ||
|
||
func TestContractErrorCases(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
testConfig := testutils.GetDefaultTestConfig() | ||
anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) | ||
require.NoError(t, err) | ||
|
||
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") | ||
require.NoError(t, err) | ||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
|
||
config := elcontracts.Config{ | ||
DelegationManagerAddress: contractAddrs.DelegationManager, | ||
} | ||
|
||
chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) | ||
require.NoError(t, err) | ||
|
||
strategyAddr := common.HexToAddress("34634374736473673643") | ||
|
||
t.Run("GetStrategyAndUnderlyingToken", func(t *testing.T) { | ||
strategy, undToken, err := chainReader.GetStrategyAndUnderlyingToken(ctx, strategyAddr) | ||
assert.Zero(t, strategy) | ||
assert.Zero(t, undToken) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") | ||
}) | ||
|
||
t.Run("GetStrategyAndUnderlyingERC20Token", func(t *testing.T) { | ||
strategy, methods, undToken, err := chainReader.GetStrategyAndUnderlyingERC20Token(ctx, strategyAddr) | ||
assert.Zero(t, strategy) | ||
assert.Zero(t, methods) | ||
assert.Zero(t, undToken) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in Remove unnecesary asserts |
||
}) | ||
} | ||
|
||
// TestInvalidConfig tests the behavior of the chainReader when the config is invalid (e.g. missing addresses, wrong | ||
// addresses) | ||
func TestInvalidConfig(t *testing.T) { | ||
testConfig := testutils.GetDefaultTestConfig() | ||
anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) | ||
require.NoError(t, err) | ||
|
||
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") | ||
require.NoError(t, err) | ||
|
||
contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) | ||
|
||
operatorAddr := testutils.ANVIL_FIRST_ADDRESS | ||
operator := types.Operator{ | ||
Address: operatorAddr, | ||
} | ||
|
||
config := elcontracts.Config{} | ||
chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) | ||
require.NoError(t, err) | ||
|
||
_ = contractAddrs | ||
_ = operator | ||
_ = chainReader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we going to use these variables? Otherwise we can remove them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
t.Run("try to get a staker shares with invalid config", func(t *testing.T) { | ||
// GetStakerShares needs a correct DelegationManagerAddress | ||
_, _, err := chainReader.GetStakerShares(context.Background(), common.HexToAddress(operator.Address)) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("try to get the delegated operator shares with invalid config", func(t *testing.T) { | ||
// GetDelegatedOperator needs a correct DelegationManagerAddress | ||
_, err := chainReader.GetDelegatedOperator( | ||
context.Background(), | ||
common.HexToAddress(operator.Address), | ||
big.NewInt(0), | ||
) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("try to get the number of operator sets for an operator with invalid config", func(t *testing.T) { | ||
// GetNumOperatorSetsForOperator needs a correct AllocationManagerAddress | ||
_, err := chainReader.GetNumOperatorSetsForOperator(context.Background(), common.HexToAddress(operator.Address)) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("try to get the operator sets for an operator with invalid config", func(t *testing.T) { | ||
// GetOperatorSetsForOperator needs a correct AllocationManagerAddress | ||
_, err := chainReader.GetOperatorSetsForOperator(context.Background(), common.HexToAddress(operator.Address)) | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("try to check if the operator is registered in an operator set with set id 0 and an invalid config", | ||
func(t *testing.T) { | ||
// IsOperatorRegisteredWithOperatorSet with setId 0 needs a correct AVSDirectory | ||
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
operatorSetId := uint32(0) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: testAddr, | ||
Id: operatorSetId, | ||
} | ||
_, err := chainReader.IsOperatorRegisteredWithOperatorSet( | ||
context.Background(), | ||
common.HexToAddress(operator.Address), | ||
operatorSet, | ||
) | ||
require.Error(t, err) | ||
}, | ||
) | ||
|
||
t.Run("try to check if the operator is registered in an operator set with set id 1 and an invalid config", | ||
func(t *testing.T) { | ||
// IsOperatorRegisteredWithOperatorSet with setId 1 needs a correct AllocationManagerAddress | ||
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
operatorSetId := uint32(1) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: testAddr, | ||
Id: operatorSetId, | ||
} | ||
_, err := chainReader.IsOperatorRegisteredWithOperatorSet( | ||
context.Background(), | ||
common.HexToAddress(operator.Address), | ||
operatorSet, | ||
) | ||
require.Error(t, err) | ||
}, | ||
) | ||
|
||
t.Run("try to get the operators for an operator set with set id 1 and an invalid config", | ||
func(t *testing.T) { | ||
// GetOperatorsForOperatorSet needs a correct AllocationManagerAddress | ||
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
operatorSetId := uint32(1) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: testAddr, | ||
Id: operatorSetId, | ||
} | ||
_, err := chainReader.GetOperatorsForOperatorSet( | ||
context.Background(), | ||
operatorSet, | ||
) | ||
require.Error(t, err) | ||
}, | ||
) | ||
|
||
t.Run("try to get the number of operators for an operator set with set id 1 and an invalid config", | ||
func(t *testing.T) { | ||
// GetNumOperatorsForOperatorSet needs a correct AllocationManagerAddress | ||
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
operatorSetId := uint32(1) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: testAddr, | ||
Id: operatorSetId, | ||
} | ||
_, err := chainReader.GetNumOperatorsForOperatorSet( | ||
context.Background(), | ||
operatorSet, | ||
) | ||
require.Error(t, err) | ||
}, | ||
) | ||
|
||
t.Run("try to get the strategies for an operator set with set id 1 and an invalid config", | ||
func(t *testing.T) { | ||
// GetStrategiesForOperatorSet needs a correct AllocationManagerAddress | ||
testAddr := common.HexToAddress(testutils.ANVIL_FIRST_ADDRESS) | ||
operatorSetId := uint32(1) | ||
operatorSet := allocationmanager.OperatorSet{ | ||
Avs: testAddr, | ||
Id: operatorSetId, | ||
} | ||
_, err := chainReader.GetStrategiesForOperatorSet( | ||
context.Background(), | ||
operatorSet, | ||
) | ||
require.Error(t, err) | ||
}, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we know that this function will throw an error, is it necessary to check the
strategy
andundToken
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, done in Remove unnecesary asserts