loop/staticaddr/deposit/sql_store_test.go
Boris Nagaev d554b42ef6
multi: migrate to btcd v2 modules
Update LND, Aperture, and Taproot Assets to revisions using the
btcd v2 modules, and update lndclient to v0.21.0-3. Migrate Loop
chain, transaction, and address types to their corresponding v2
packages.

The lndclient release includes the migration from:
https://github.com/lightninglabs/lndclient/pull/280

Taproot Assets is temporarily replaced with its btcd v2 revision
because the v0.8 release branch has not adopted the new modules.

This raises the minimum Go version to 1.26 and changes exported
address types.
2026-08-12 23:39:26 +00:00

86 lines
2 KiB
Go

package deposit
import (
"database/sql"
"testing"
"github.com/btcsuite/btcd/wire/v2"
"github.com/jackc/pgx/v5"
"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/loopdb/sqlc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
)
func TestToDeposit(t *testing.T) {
depositID, err := GetRandomDepositID()
require.NoError(t, err)
swapHash, err := lntypes.MakeHash(dummyHashBytes())
require.NoError(t, err)
tx := wire.NewMsgTx(2)
txHash := tx.TxHash()
tests := []struct {
name string
row sqlc.Deposit
lastUpdate sqlc.DepositUpdate
expectErr bool
}{
{
name: "fully valid data",
row: sqlc.Deposit{
DepositID: depositID[:],
TxHash: txHash[:],
Amount: 100000000,
ConfirmationHeight: 123456,
SwapHash: swapHash[:],
},
lastUpdate: sqlc.DepositUpdate{
UpdateState: "completed",
},
expectErr: false,
},
{
name: "fully valid data",
row: sqlc.Deposit{
DepositID: depositID[:],
TxHash: txHash[:],
Amount: 100000000,
ConfirmationHeight: 123456,
},
lastUpdate: sqlc.DepositUpdate{
UpdateState: "completed",
},
expectErr: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result, err := ToDeposit(test.row, test.lastUpdate)
if test.expectErr {
require.Error(t, err)
require.Nil(t, result)
} else {
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, fsm.StateType(test.lastUpdate.UpdateState), result.state)
}
})
}
}
func dummyHashBytes() []byte {
return []byte{0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23}
}
// TestErrNoRows ensures that pgx.ErrNoRows is a wrapped sql.ErrNoRows, so we
// don't have to check against both of them.
func TestErrNoRows(t *testing.T) {
require.ErrorIs(t, pgx.ErrNoRows, sql.ErrNoRows)
}