staticaddr/loopin: use payment timeout duration helper

This commit is contained in:
Slyghtning 2026-07-02 10:47:06 +02:00
parent 3fdd9e2250
commit bd3882d5b0
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 38 additions and 2 deletions

View file

@ -470,9 +470,9 @@ func (l *StaticAddressLoopIn) TotalDepositAmount() btcutil.Amount {
// initiation time of the swap. If more than the swap's configured payment
// timeout has passed, the remaining time will be negative.
func (l *StaticAddressLoopIn) RemainingPaymentTimeSeconds() int64 {
elapsedSinceInitiation := time.Since(l.InitiationTime).Seconds()
deadline := l.InitiationTime.Add(l.PaymentTimeoutDuration())
return l.paymentTimeoutSeconds() - int64(elapsedSinceInitiation)
return int64(time.Until(deadline).Seconds())
}
// PaymentTimeoutDuration returns the configured payment timeout duration,

View file

@ -147,6 +147,42 @@ func TestCreateHtlcSweepTxSweepValue(t *testing.T) {
"the HTLC output")
}
// TestPaymentTimeoutDuration verifies that zero timeout values fall back to the
// default payment timeout duration.
func TestPaymentTimeoutDuration(t *testing.T) {
t.Parallel()
tests := []struct {
name string
paymentTimeoutSeconds uint32
expected time.Duration
}{
{
name: "default",
expected: time.Duration(DefaultPaymentTimeoutSeconds) * time.Second,
},
{
name: "configured",
paymentTimeoutSeconds: 42,
expected: 42 * time.Second,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
loopIn := &StaticAddressLoopIn{
PaymentTimeoutSeconds: test.paymentTimeoutSeconds,
}
require.Equal(
t, test.expected, loopIn.PaymentTimeoutDuration(),
)
})
}
}
// newStaticAddress creates a StaticAddress for testing.
func newStaticAddress(clientKey, serverKey *btcec.PublicKey,
csvExpiry int64) (*script.StaticAddress, error) {