mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
eth/filters: return invalid params for getlogs query limit
This commit is contained in:
parent
deda47f6a1
commit
f53ced15fb
2 changed files with 27 additions and 4 deletions
|
|
@ -53,6 +53,7 @@ type invalidParamsError struct {
|
|||
|
||||
func (e invalidParamsError) Error() string { return e.err.Error() }
|
||||
func (e invalidParamsError) ErrorCode() int { return -32602 }
|
||||
func (e invalidParamsError) Unwrap() error { return e.err }
|
||||
|
||||
func invalidParamsErr(format string, args ...any) error {
|
||||
return invalidParamsError{fmt.Errorf(format, args...)}
|
||||
|
|
@ -450,11 +451,11 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
|||
}
|
||||
if api.logQueryLimit != 0 {
|
||||
if len(crit.Addresses) > api.logQueryLimit {
|
||||
return nil, errExceedLogQueryLimit
|
||||
return nil, invalidParamsErr("%w", errExceedLogQueryLimit)
|
||||
}
|
||||
for _, topics := range crit.Topics {
|
||||
if len(topics) > api.logQueryLimit {
|
||||
return nil, errExceedLogQueryLimit
|
||||
return nil, invalidParamsErr("%w", errExceedLogQueryLimit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -591,8 +591,19 @@ func TestExceedLogQueryLimit(t *testing.T) {
|
|||
FromBlock: big.NewInt(0),
|
||||
ToBlock: big.NewInt(100),
|
||||
Addresses: addresses,
|
||||
}); err != errExceedLogQueryLimit {
|
||||
}); !errors.Is(err, errExceedLogQueryLimit) {
|
||||
t.Errorf("Expected GetLogs with 6 addresses to return errExceedLogQueryLimit, got: %v", err)
|
||||
} else {
|
||||
var re rpc.Error
|
||||
if !errors.As(err, &re) {
|
||||
t.Fatalf("expected rpc error, got %v", err)
|
||||
}
|
||||
if re.ErrorCode() != -32602 {
|
||||
t.Fatalf("expected error code -32602, got %d", re.ErrorCode())
|
||||
}
|
||||
if re.Error() != "exceed max addresses or topics per search position" {
|
||||
t.Fatalf("expected error message %q, got %q", "exceed max addresses or topics per search position", re.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Test that 5 topics at one position do not result in error
|
||||
|
|
@ -611,8 +622,19 @@ func TestExceedLogQueryLimit(t *testing.T) {
|
|||
ToBlock: big.NewInt(100),
|
||||
Addresses: addresses[:1],
|
||||
Topics: [][]common.Hash{topics},
|
||||
}); err != errExceedLogQueryLimit {
|
||||
}); !errors.Is(err, errExceedLogQueryLimit) {
|
||||
t.Errorf("Expected GetLogs with 6 topics at one position to return errExceedLogQueryLimit, got: %v", err)
|
||||
} else {
|
||||
var re rpc.Error
|
||||
if !errors.As(err, &re) {
|
||||
t.Fatalf("expected rpc error, got %v", err)
|
||||
}
|
||||
if re.ErrorCode() != -32602 {
|
||||
t.Fatalf("expected error code -32602, got %d", re.ErrorCode())
|
||||
}
|
||||
if re.Error() != "exceed max addresses or topics per search position" {
|
||||
t.Fatalf("expected error message %q, got %q", "exceed max addresses or topics per search position", re.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue