lnwire: revamp previous encode/decode tests to passing state

This commit is contained in:
Olaoluwa Osuntokun committed 2016-05-30 20:52:25 -07:00
1 parent 83b11c5efe
commit 3b6e456371
15 files changed
+269 -266

No files matched your search

+24 -22
View File
@@ -14,33 +14,14 @@ type ErrorGeneric struct {
// within.
ChannelID uint64
// TODO(roasbeef): uint16 for problem type?
// ErrorID uint16
// ErrorID quickly defines the nature of the error according to error
// type.
ErrorID uint16
// Problem is a human-readable string further elaborating upon the
// nature of the exact error. The maxmium allowed length of this
// message is 8192 bytes.
Problem string
// TODO(roasbeef): add SerializeSize?
}
// Decode deserializes a serialized ErrorGeneric message stored in the
// passed io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// Problem
err := readElements(r,
&c.ChannelID,
&c.Problem,
)
if err != nil {
return err
}
return nil
}
// NewErrorGeneric creates a new ErrorGeneric message.
@@ -52,6 +33,25 @@ func NewErrorGeneric() *ErrorGeneric {
// interface.
var _ Message = (*ErrorGeneric)(nil)
// Decode deserializes a serialized ErrorGeneric message stored in the
// passed io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// Problem
err := readElements(r,
&c.ChannelID,
&c.ErrorID,
&c.Problem,
)
if err != nil {
return err
}
return nil
}
// Encode serializes the target ErrorGeneric into the passed io.Writer
// observing the protocol version specified.
//
@@ -59,6 +59,7 @@ var _ Message = (*ErrorGeneric)(nil)
func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.ErrorID,
c.Problem,
)
if err != nil {
@@ -104,6 +105,7 @@ func (c *ErrorGeneric) Validate() error {
func (c *ErrorGeneric) String() string {
return fmt.Sprintf("\n--- Begin ErrorGeneric ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
fmt.Sprintf("ErrorID:\t%d\n", c.ErrorID) +
fmt.Sprintf("Problem:\t%s\n", c.Problem) +
fmt.Sprintf("--- End ErrorGeneric ---\n")
}