lnd.xprv/lnwire/update_fail_htlc_test.go
Olaoluwa Osuntokun 8024fd72f8
lnwire: create distinct type for UpdateFailHTLC failure reason
This commit creates a distint type for the opaque failure reason within
the UpdateFailHTLC message. This new type is needed as this is the only
variable length byte slice within the protocol and therefore requires a
length prefix in order to serialize/deserialize properly.
2017-02-21 01:43:36 -08:00

35 lines
845 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,
}
cancelMsg.Reason = []byte{byte(UnknownDestination)}
// 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)
}
}