mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr/loopin: use payment timeout duration helper
This commit is contained in:
parent
3fdd9e2250
commit
bd3882d5b0
2 changed files with 38 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue