mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
lnwire/channel_update: add String method for ChanUpdate[Chan|Msg]Flags
In this commit, we fix the problem where it's annoying to parse a bitfield printed out in decimal by writing a String method for the ChanUpdate[Chan|Msg]Flags bitfield. Co-authored-by: Johan T. Halseth <johanth@gmail.com>
This commit is contained in:
committed by
Johan T. Halseth
parent
0fd6004958
commit
f0ba4b454c
@@ -178,6 +178,50 @@ func randAddrs(r *rand.Rand) ([]net.Addr, error) {
|
||||
return []net.Addr{tcp4Addr, tcp6Addr, v2OnionAddr, v3OnionAddr}, nil
|
||||
}
|
||||
|
||||
// TestChanUpdateChanFlags ensures that converting the ChanUpdateChanFlags and
|
||||
// ChanUpdateMsgFlags bitfields to a string behaves as expected.
|
||||
func TestChanUpdateChanFlags(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
flags uint8
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
flags: 0,
|
||||
expected: "00000000",
|
||||
},
|
||||
{
|
||||
flags: 1,
|
||||
expected: "00000001",
|
||||
},
|
||||
{
|
||||
flags: 3,
|
||||
expected: "00000011",
|
||||
},
|
||||
{
|
||||
flags: 255,
|
||||
expected: "11111111",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
chanFlag := ChanUpdateChanFlags(test.flags)
|
||||
toStr := chanFlag.String()
|
||||
if toStr != test.expected {
|
||||
t.Fatalf("expected %v, got %v",
|
||||
test.expected, toStr)
|
||||
}
|
||||
|
||||
msgFlag := ChanUpdateMsgFlags(test.flags)
|
||||
toStr = msgFlag.String()
|
||||
if toStr != test.expected {
|
||||
t.Fatalf("expected %v, got %v",
|
||||
test.expected, toStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxOutPointIndex(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
Reference in New Issue
Block a user