2016-09-23 04:51:43 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
func TestUpdateFailHTLC(t *testing.T) {
|
|
|
|
// First create a new UFH message.
|
|
|
|
cancelMsg := &UpdateFailHTLC{
|
|
|
|
ChannelPoint: *outpoint1,
|
|
|
|
ID: 22,
|
2016-09-23 04:51:43 +03:00
|
|
|
}
|
2017-02-16 15:25:36 +03:00
|
|
|
copy(cancelMsg.Reason[:], bytes.Repeat([]byte{21}, 20))
|
2016-09-23 04:51:43 +03:00
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// Next encode the UFH message into an empty bytes buffer.
|
2016-09-23 04:51:43 +03:00
|
|
|
var b bytes.Buffer
|
|
|
|
if err := cancelMsg.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode CancelHTLC: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// Deserialize the encoded UFH message into a new empty struct.
|
|
|
|
cancelMsg2 := &UpdateFailHTLC{}
|
2016-09-23 04:51:43 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|