lnd.xprv/lnwire/close_request_test.go

36 lines
800 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"
"github.com/roasbeef/btcutil"
2015-12-31 13:42:25 +03:00
)
func TestCloseRequestEncodeDecode(t *testing.T) {
cr := &CloseRequest{
ChannelPoint: outpoint1,
2015-12-31 13:42:25 +03:00
RequesterCloseSig: commitSig,
Fee: btcutil.Amount(10000),
2015-12-31 13:42:25 +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
// 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
// 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
}