2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 02:49:48 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2016-01-05 19:19:22 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-02-16 15:34:09 +03:00
|
|
|
func TestUpdateFufillHTLCEncodeDecode(t *testing.T) {
|
2016-05-31 02:49:48 +03:00
|
|
|
// First create a new HTLCSR message.
|
2017-02-16 15:34:09 +03:00
|
|
|
settleReq := NewUpdateFufillHTLC(*outpoint1, 23, revHash)
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Next encode the HTLCSR message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := settleReq.Encode(&b, 0); err != nil {
|
2017-02-16 15:34:09 +03:00
|
|
|
t.Fatalf("unable to encode UpdateFufillHTLC: %v", err)
|
2016-05-31 02:49:48 +03:00
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Deserialize the encoded SFOP message into a new empty struct.
|
2017-02-16 15:34:09 +03:00
|
|
|
settleReq2 := &UpdateFufillHTLC{}
|
2016-05-31 02:49:48 +03:00
|
|
|
if err := settleReq2.Decode(&b, 0); err != nil {
|
2017-02-16 15:34:09 +03:00
|
|
|
t.Fatalf("unable to decode UpdateFufillHTLC: %v", err)
|
2016-05-31 02:49:48 +03:00
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(settleReq, settleReq2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
settleReq, settleReq2)
|
|
|
|
}
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|