2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 02:49:48 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2016-01-05 19:19:22 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-02-16 15:04:58 +03:00
|
|
|
func TestCommitSigEncodeDecode(t *testing.T) {
|
|
|
|
commitSignature := &CommitSig{
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID: ChannelID(revHash),
|
|
|
|
CommitSig: commitSig,
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Next encode the CS message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := commitSignature.Encode(&b, 0); err != nil {
|
2017-02-16 15:04:58 +03:00
|
|
|
t.Fatalf("unable to encode CommitSig: %v", err)
|
2016-05-31 02:49:48 +03:00
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Deserialize the encoded EG message into a new empty struct.
|
2017-02-16 15:04:58 +03:00
|
|
|
commitSignature2 := &CommitSig{}
|
2016-05-31 02:49:48 +03:00
|
|
|
if err := commitSignature2.Decode(&b, 0); err != nil {
|
2017-02-16 15:04:58 +03:00
|
|
|
t.Fatalf("unable to decode CommitSig: %v", err)
|
2016-05-31 02:49:48 +03:00
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(commitSignature, commitSignature2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
commitSignature, commitSignature2)
|
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|