Skip to content

Commit

Permalink
fix: prevent query syntax error if allowlist is empty (#12912)
Browse files Browse the repository at this point in the history
Co-authored-by: Morgan Kuphal <[email protected]>
  • Loading branch information
agparadiso and KuphJr authored Apr 26, 2024
1 parent 71eed21 commit b1c8d74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit b1c8d74

Please sign in to comment.