multi: add UpdateAccountAliasForTests query

In the upcoming kvdb to SQL migration of the actions store, we need to
simulate in tests that two or more accounts have colliding account
aliases for the first 4 bytes of the alias. In order to allow creation
of such accounts, we need to be able to update the alias of an account
in tests, and this commit adds the a SQL query enabling this
functionality.

Note that the `UpdateAccountAliasForTests` query is only intended for
use in tests and should not be used in production code.
This commit is contained in:
Viktor Torstensson 2025-09-09 15:04:07 +02:00
parent 5d8f03e241
commit 4ccb56a771
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
4 changed files with 32 additions and 0 deletions

View file

@ -49,6 +49,9 @@ type SQLQueries interface {
UpdateAccountBalance(ctx context.Context, arg sqlc.UpdateAccountBalanceParams) (int64, error)
UpdateAccountExpiry(ctx context.Context, arg sqlc.UpdateAccountExpiryParams) (int64, error)
UpdateAccountLastUpdate(ctx context.Context, arg sqlc.UpdateAccountLastUpdateParams) (int64, error)
// UpdateAccountAliasForTests is a query intended only for testing
// purposes, to change the account alias.
UpdateAccountAliasForTests(ctx context.Context, arg sqlc.UpdateAccountAliasForTestsParams) (int64, error)
UpsertAccountPayment(ctx context.Context, arg sqlc.UpsertAccountPaymentParams) error
GetAccountInvoice(ctx context.Context, arg sqlc.GetAccountInvoiceParams) (sqlc.AccountInvoice, error)
}

View file

@ -313,6 +313,26 @@ func (q *Queries) SetAccountIndex(ctx context.Context, arg SetAccountIndexParams
return err
}
const updateAccountAliasForTests = `-- name: UpdateAccountAliasForTests :one
UPDATE accounts
SET alias = $1
WHERE id = $2
RETURNING id
`
type UpdateAccountAliasForTestsParams struct {
Alias int64
ID int64
}
// NOTE: This query is only intended for testing purposes.
func (q *Queries) UpdateAccountAliasForTests(ctx context.Context, arg UpdateAccountAliasForTestsParams) (int64, error) {
row := q.db.QueryRowContext(ctx, updateAccountAliasForTests, arg.Alias, arg.ID)
var id int64
err := row.Scan(&id)
return id, err
}
const updateAccountBalance = `-- name: UpdateAccountBalance :one
UPDATE accounts
SET current_balance_msat = $1

View file

@ -67,6 +67,8 @@ type Querier interface {
SetSessionGroupID(ctx context.Context, arg SetSessionGroupIDParams) error
SetSessionRemotePublicKey(ctx context.Context, arg SetSessionRemotePublicKeyParams) error
SetSessionRevokedAt(ctx context.Context, arg SetSessionRevokedAtParams) error
// NOTE: This query is only intended for testing purposes.
UpdateAccountAliasForTests(ctx context.Context, arg UpdateAccountAliasForTestsParams) (int64, error)
UpdateAccountBalance(ctx context.Context, arg UpdateAccountBalanceParams) (int64, error)
UpdateAccountExpiry(ctx context.Context, arg UpdateAccountExpiryParams) (int64, error)
UpdateAccountLastUpdate(ctx context.Context, arg UpdateAccountLastUpdateParams) (int64, error)

View file

@ -25,6 +25,13 @@ RETURNING id;
INSERT INTO account_invoices (account_id, hash)
VALUES ($1, $2);
-- name: UpdateAccountAliasForTests :one
-- NOTE: This query is only intended for testing purposes.
UPDATE accounts
SET alias = $1
WHERE id = $2
RETURNING id;
-- name: DeleteAccountPayment :exec
DELETE FROM account_payments
WHERE hash = $1