f1357e96b3
This commit morphs the prior CancelHTLC into the new UpdateFailHTLC message and also gets rid of the obsolete HLTCAddReject message while we’re at it. The primary change from the CancelHTLC message to the UpdateFailHTLC message is that the CancelReason is now simply called Reason and that it’s now an opaque encrypted set of bytes. With this update the failure messages are now more flexible (they can even carry new ChannelUpdate’s) and also don’t reveal the exact cause of failure to intermediate nodes.
35 lines
849 B
Go
35 lines
849 B
Go
package lnwire
|
|
|
|
import (
|
|
"bytes"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestUpdateFailHTLC(t *testing.T) {
|
|
// First create a new UFH message.
|
|
cancelMsg := &UpdateFailHTLC{
|
|
ChannelPoint: *outpoint1,
|
|
ID: 22,
|
|
}
|
|
copy(cancelMsg.Reason[:], bytes.Repeat([]byte{21}, 20))
|
|
|
|
// Next encode the UFH 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 UFH message into a new empty struct.
|
|
cancelMsg2 := &UpdateFailHTLC{}
|
|
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)
|
|
}
|
|
}
|