2015-12-31 13:42:25 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 02:49:48 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2015-12-31 13:42:25 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
func TestCloseCompleteEncodeDecode(t *testing.T) {
|
|
|
|
cc := &CloseComplete{
|
2017-02-16 15:34:44 +03:00
|
|
|
ChannelPoint: *outpoint1,
|
2015-12-31 13:42:25 +03:00
|
|
|
ResponderCloseSig: commitSig,
|
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Next encode the CC message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := cc.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode CloseComplete: %v", err)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Deserialize the encoded CC message into a new empty struct.
|
|
|
|
cc2 := &CloseComplete{}
|
|
|
|
if err := cc2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode CloseComplete: %v", err)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(cc, cc2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
cc, cc2)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
}
|