lnd.xprv/lnwire/close_complete_test.go

33 lines
730 B
Go
Raw Normal View History

2015-12-31 13:42:25 +03:00
package lnwire
import (
"bytes"
"reflect"
2015-12-31 13:42:25 +03:00
"testing"
)
func TestCloseCompleteEncodeDecode(t *testing.T) {
cc := &CloseComplete{
ChannelPoint: *outpoint1,
2015-12-31 13:42:25 +03:00
ResponderCloseSig: commitSig,
}
// 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
// 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
// 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
}