2016-01-05 19:53:42 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 02:49:48 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2016-01-05 19:53:42 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
func TestErrorGenericEncodeDecode(t *testing.T) {
|
|
|
|
eg := &ErrorGeneric{
|
2016-06-21 07:55:07 +03:00
|
|
|
ChannelPoint: outpoint1,
|
|
|
|
ErrorID: 99,
|
|
|
|
Problem: "Hello world!",
|
2016-10-15 16:19:11 +03:00
|
|
|
PendingChannelID: 1,
|
2016-01-05 19:53:42 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Next encode the EG message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := eg.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode ErrorGeneric: %v", err)
|
|
|
|
}
|
2016-01-05 19:53:42 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Deserialize the encoded EG message into a new empty struct.
|
|
|
|
eg2 := &ErrorGeneric{}
|
|
|
|
if err := eg2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode ErrorGeneric: %v", err)
|
|
|
|
}
|
2016-01-05 19:53:42 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(eg, eg2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
eg, eg2)
|
|
|
|
}
|
2016-01-05 19:53:42 +03:00
|
|
|
}
|