lnd.xprv/lnwire/htlc_cancel_test.go
Olaoluwa Osuntokun d079c88702
lnwire: add cancellation reason to htlc cancel messages
This commit adds a new field to the CancelHTLC message which describes
the event that led to an HTLC being cancelled up stream.

A new enum has been added which describers the “why” concerning the
cancellation of the HTLC. Currently the encoding and back propagation
of the errors aren’t properly implemented as defined within the spec.
As a result the current error types provide to privacy as the error are
in plain-site rather doing being properly encrypted.
2017-01-07 21:20:54 -08:00

35 lines
833 B
Go

package lnwire
import (
"bytes"
"reflect"
"testing"
)
func TestCancelHTLCEncodeDecode(t *testing.T) {
// First create a new HTLCTR message.
cancelMsg := &CancelHTLC{
ChannelPoint: outpoint1,
HTLCKey: 22,
Reason: UpstreamTimeout,
}
// 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)
}
}