• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lnwire/warning.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "io"
7

8
        "pgregory.net/rapid"
9
)
10

11
// WarningData is a set of bytes associated with a particular sent warning. A
12
// receiving node SHOULD only print out data verbatim if the string is composed
13
// solely of printable ASCII characters. For reference, the printable character
14
// set includes byte values 32 through 127 inclusive.
15
type WarningData []byte
16

17
// Warning is used to express non-critical errors in the protocol, providing
18
// a "soft" way for nodes to communicate failures.
19
type Warning struct {
20
        // ChanID references the active channel in which the warning occurred
21
        // within. If the ChanID is all zeros, then this warning applies to the
22
        // entire established connection.
23
        ChanID ChannelID
24

25
        // Data is the attached warning data that describes the exact failure
26
        // which caused the warning message to be sent.
27
        Data WarningData
28
}
29

30
// A compile time check to ensure Warning implements the lnwire.Message
31
// interface.
32
var _ Message = (*Warning)(nil)
33

34
// A compile time check to ensure Warning implements the lnwire.SizeableMessage
35
// interface.
36
var _ SizeableMessage = (*Warning)(nil)
37

38
// A compile time check to ensure Warning implements the lnwire.TestMessage
39
// interface.
40
var _ TestMessage = (*Warning)(nil)
41

42
// NewWarning creates a new Warning message.
43
func NewWarning() *Warning {
×
44
        return &Warning{}
×
45
}
×
46

47
// Warning returns the string representation to Warning.
UNCOV
48
func (c *Warning) Warning() string {
×
UNCOV
49
        errMsg := "non-ascii data"
×
UNCOV
50
        if isASCII(c.Data) {
×
UNCOV
51
                errMsg = string(c.Data)
×
UNCOV
52
        }
×
53

UNCOV
54
        return fmt.Sprintf("chan_id=%v, err=%v", c.ChanID, errMsg)
×
55
}
56

57
// Decode deserializes a serialized Warning message stored in the passed
58
// io.Reader observing the specified protocol version.
59
//
60
// This is part of the lnwire.Message interface.
UNCOV
61
func (c *Warning) Decode(r io.Reader, _ uint32) error {
×
UNCOV
62
        return ReadElements(r,
×
UNCOV
63
                &c.ChanID,
×
UNCOV
64
                &c.Data,
×
UNCOV
65
        )
×
UNCOV
66
}
×
67

68
// Encode serializes the target Warning into the passed io.Writer observing the
69
// protocol version specified.
70
//
71
// This is part of the lnwire.Message interface.
UNCOV
72
func (c *Warning) Encode(w *bytes.Buffer, _ uint32) error {
×
UNCOV
73
        if err := WriteBytes(w, c.ChanID[:]); err != nil {
×
74
                return err
×
75
        }
×
76

UNCOV
77
        return WriteWarningData(w, c.Data)
×
78
}
79

80
// MsgType returns the integer uniquely identifying an Warning message on the
81
// wire.
82
//
83
// This is part of the lnwire.Message interface.
UNCOV
84
func (c *Warning) MsgType() MessageType {
×
UNCOV
85
        return MsgWarning
×
UNCOV
86
}
×
87

88
// SerializedSize returns the serialized size of the message in bytes.
89
//
90
// This is part of the lnwire.SizeableMessage interface.
NEW
91
func (c *Warning) SerializedSize() (uint32, error) {
×
NEW
92
        return MessageSerializedSize(c)
×
NEW
93
}
×
94

95
// RandTestMessage populates the message with random data suitable for testing.
96
// It uses the rapid testing framework to generate random values.
97
//
98
// This is part of the TestMessage interface.
NEW
99
func (c *Warning) RandTestMessage(t *rapid.T) Message {
×
NEW
100
        msg := &Warning{
×
NEW
101
                ChanID: RandChannelID(t),
×
NEW
102
        }
×
NEW
103

×
NEW
104
        useASCII := rapid.Bool().Draw(t, "useASCII")
×
NEW
105
        if useASCII {
×
NEW
106
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
NEW
107
                data := make([]byte, length)
×
NEW
108
                for i := 0; i < length; i++ {
×
NEW
109
                        data[i] = byte(
×
NEW
110
                                rapid.IntRange(32, 126).Draw(
×
NEW
111
                                        t, fmt.Sprintf("warningDataByte-%d", i),
×
NEW
112
                                ),
×
NEW
113
                        )
×
NEW
114
                }
×
NEW
115
                msg.Data = data
×
NEW
116
        } else {
×
NEW
117
                length := rapid.IntRange(1, 100).Draw(t, "warningDataLength")
×
NEW
118
                msg.Data = rapid.SliceOfN(rapid.Byte(), length, length).Draw(
×
NEW
119
                        t, "warningData",
×
NEW
120
                )
×
NEW
121
        }
×
122

NEW
123
        return msg
×
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc