mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
lncli: add testcase for parseTimeLockDelta
Signed-off-by: Eval EXEC <execvy@gmail.com>
This commit is contained in:
parent
cbcbddfe29
commit
e4a6a0f26f
1 changed files with 53 additions and 0 deletions
|
@ -2,6 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -68,3 +71,53 @@ func TestParseChanPoint(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestParseTimeLockDelta tests parseTimeLockDelta with various
|
||||||
|
// valid and invalid input values and verifies the output.
|
||||||
|
func TestParseTimeLockDelta(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
testCases := []struct {
|
||||||
|
timeLockDeltaStr string
|
||||||
|
expectedTimeLockDelta uint16
|
||||||
|
expectErr bool
|
||||||
|
expectedErrContent string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
timeLockDeltaStr: "-1",
|
||||||
|
expectErr: true,
|
||||||
|
expectedErrContent: fmt.Sprintf(
|
||||||
|
"failed to parse time_lock_delta: %d "+
|
||||||
|
"to uint64", -1,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeLockDeltaStr: "0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeLockDeltaStr: "3",
|
||||||
|
expectedTimeLockDelta: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeLockDeltaStr: strconv.FormatUint(
|
||||||
|
uint64(math.MaxUint16), 10,
|
||||||
|
),
|
||||||
|
expectedTimeLockDelta: math.MaxUint16,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeLockDeltaStr: "18446744073709551616",
|
||||||
|
expectErr: true,
|
||||||
|
expectedErrContent: fmt.Sprint(
|
||||||
|
"failed to parse time_lock_delta:" +
|
||||||
|
" 18446744073709551616 to uint64"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
timeLockDelta, err := parseTimeLockDelta(tc.timeLockDeltaStr)
|
||||||
|
require.Equal(t, tc.expectedTimeLockDelta, timeLockDelta)
|
||||||
|
if tc.expectErr {
|
||||||
|
require.ErrorContains(t, err, tc.expectedErrContent)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue