lncli: add test for parseChanPoint
This commit is contained in:
1 parent
807bc0628c
commit
3821bd2202
1 file changed
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestParseChanPoint tests parseChanPoint with various
|
||||||
|
// valid and invalid input values and verifies the output.
|
||||||
|
func TestParseChanPoint(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
channelPoinStr string
|
||||||
|
channelPointIsNil bool
|
||||||
|
outputIndex uint32
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"24581424081379576b4a7580ace91db10925d996a2a8d45c8034" +
|
||||||
|
"3a5a467dc0bc:0",
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
nil,
|
||||||
|
}, {
|
||||||
|
"24581424081379576b4a7580ace91db10925d996a2a8d45c8034" +
|
||||||
|
"3a5a467dc0bc:4",
|
||||||
|
false,
|
||||||
|
4,
|
||||||
|
nil,
|
||||||
|
}, {
|
||||||
|
":",
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
errBadChanPoint,
|
||||||
|
}, {
|
||||||
|
":0",
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
errBadChanPoint,
|
||||||
|
}, {
|
||||||
|
"24581424081379576b4a7580ace91db10925d996a2a8d45c8034" +
|
||||||
|
"3a5a467dc0bc:",
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
errBadChanPoint,
|
||||||
|
}, {
|
||||||
|
"24581424081379576b4a7580ace91db10925d996a2a8d45c8034" +
|
||||||
|
"3a5a467dc0bc:string",
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
errors.New("unable to decode output index: strconv." +
|
||||||
|
"ParseInt: parsing \"string\": invalid syntax"),
|
||||||
|
}, {
|
||||||
|
"not_hex:0",
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
errors.New("unable to parse hex string: encoding/hex:" +
|
||||||
|
" invalid byte: U+006E 'n'"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
cp, err := parseChanPoint(tc.channelPoinStr)
|
||||||
|
require.Equal(t, tc.err, err)
|
||||||
|
require.Equal(t, tc.channelPointIsNil, cp == nil)
|
||||||
|
if !tc.channelPointIsNil {
|
||||||
|
require.Equal(t, tc.outputIndex, cp.OutputIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user