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

[FUN] prevent query syntax error if allowlist is empty #12912

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions core/services/gateway/handlers/functions/allowlist/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (o *orm) GetAllowedSenders(ctx context.Context, offset, limit uint) ([]comm
}

func (o *orm) CreateAllowedSenders(ctx context.Context, allowedSenders []common.Address) error {
if len(allowedSenders) == 0 {
o.lggr.Debugf("empty allowed senders list: %v for routerContractAddress: %s. skipping...", allowedSenders, o.routerContractAddress)
return nil
}

var valuesPlaceholder []string
for i := 1; i <= len(allowedSenders)*2; i += 2 {
valuesPlaceholder = append(valuesPlaceholder, fmt.Sprintf("($%d, $%d)", i, i+1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func TestORM_CreateAllowedSenders(t *testing.T) {
require.Equal(t, expected[0], results[0])
require.Equal(t, expected[1], results[1])
})

// this scenario can happen if the allowlist is empty but we call CreateAllowedSenders
t.Run("OK-empty_list", func(t *testing.T) {
ctx := testutils.Context(t)
orm, err := setupORM(t)
require.NoError(t, err)
err = orm.CreateAllowedSenders(ctx, []common.Address{})
require.NoError(t, err)
})
}

func TestORM_DeleteAllowedSenders(t *testing.T) {
Expand Down
Loading