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"
|
2016-05-23 23:54:34 +03:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcutil"
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
func TestCommitSignatureEncodeDecode(t *testing.T) {
|
|
|
|
copy(revocationHash[:], revocationHashBytes)
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
commitSignature := &CommitSignature{
|
2016-06-21 07:55:07 +03:00
|
|
|
ChannelPoint: outpoint1,
|
|
|
|
Fee: btcutil.Amount(10000),
|
|
|
|
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 {
|
|
|
|
t.Fatalf("unable to encode CommitSignature: %v", err)
|
|
|
|
}
|
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.
|
|
|
|
commitSignature2 := &CommitSignature{}
|
|
|
|
if err := commitSignature2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode CommitSignature: %v", err)
|
|
|
|
}
|
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
|
|
|
}
|