loop/staticaddr/deposit/manager_height_test.go
Slyghtning 1abe617991
staticaddr/deposit: track unconfirmed deposits
Retain static-address deposits as soon as lnd reports the UTXO, even
when the output is still unconfirmed. Store the first confirmation
height once the output confirms.

Derive confirmation heights from the current wallet view because lnd
reports confirmation counts instead of first-confirmation heights.
2026-07-12 09:14:31 +02:00

39 lines
1 KiB
Go

package deposit
import (
"testing"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/stretchr/testify/require"
)
// TestConfirmationHeightForUtxo verifies confirmation heights are derived from
// the current block height and wallet confirmation count.
func TestConfirmationHeightForUtxo(t *testing.T) {
t.Run("unconfirmed", func(t *testing.T) {
height, err := confirmationHeightForUtxo(0, &lnwallet.Utxo{})
require.NoError(t, err)
require.Zero(t, height)
})
t.Run("confirmed", func(t *testing.T) {
height, err := confirmationHeightForUtxo(101, &lnwallet.Utxo{
OutPoint: wire.OutPoint{
Hash: chainhash.Hash{1},
Index: 2,
},
Confirmations: 6,
})
require.NoError(t, err)
require.EqualValues(t, 96, height)
})
t.Run("invalid current height", func(t *testing.T) {
_, err := confirmationHeightForUtxo(2, &lnwallet.Utxo{
Confirmations: 6,
})
require.ErrorContains(t, err, "invalid confirmation height")
})
}