2016-09-23 04:51:43 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCancelHTLCEncodeDecode(t *testing.T) {
|
|
|
|
// First create a new HTLCTR message.
|
|
|
|
cancelMsg := &CancelHTLC{
|
|
|
|
ChannelPoint: outpoint1,
|
|
|
|
HTLCKey: 22,
|
2017-01-08 06:24:40 +03:00
|
|
|
Reason: UnknownPaymentHash,
|
2016-09-23 04:51:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next encode the HTLCTR message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := cancelMsg.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode CancelHTLC: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deserialize the encoded HTLCTR message into a new empty struct.
|
|
|
|
cancelMsg2 := &CancelHTLC{}
|
|
|
|
if err := cancelMsg2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode CancelHTLC: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(cancelMsg, cancelMsg2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
cancelMsg, cancelMsg2)
|
|
|
|
}
|
|
|
|
}
|