2015-12-31 13:42:25 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-06-21 07:55:07 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2015-12-31 13:42:25 +03:00
|
|
|
"testing"
|
2016-05-23 23:54:34 +03:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcutil"
|
2015-12-31 13:42:25 +03:00
|
|
|
)
|
|
|
|
|
2016-06-21 07:55:07 +03:00
|
|
|
func TestCloseRequestEncodeDecode(t *testing.T) {
|
|
|
|
cr := &CloseRequest{
|
2017-04-17 04:11:39 +03:00
|
|
|
ChanID: ChannelID(revHash),
|
2015-12-31 13:42:25 +03:00
|
|
|
RequesterCloseSig: commitSig,
|
2016-06-21 07:55:07 +03:00
|
|
|
Fee: btcutil.Amount(10000),
|
2015-12-31 13:42:25 +03:00
|
|
|
}
|
|
|
|
|
2016-06-21 07:55:07 +03:00
|
|
|
// Next encode the CR message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := cr.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode CloseRequest: %v", err)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
|
2016-06-21 07:55:07 +03:00
|
|
|
// Deserialize the encoded CR message into a new empty struct.
|
|
|
|
cr2 := &CloseRequest{}
|
|
|
|
if err := cr2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode CloseRequest: %v", err)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
|
2016-06-21 07:55:07 +03:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(cr, cr2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
cr, cr2)
|
|
|
|
}
|
2015-12-31 13:42:25 +03:00
|
|
|
}
|