31 lines
812 B
Go
31 lines
812 B
Go
package lnwire
|
|
|
|
import (
|
|
"bytes"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestUpdateFufillHTLCEncodeDecode(t *testing.T) {
|
|
// First create a new HTLCSR message.
|
|
settleReq := NewUpdateFufillHTLC(ChannelID(revHash), 23, revHash)
|
|
|
|
// Next encode the HTLCSR message into an empty bytes buffer.
|
|
var b bytes.Buffer
|
|
if err := settleReq.Encode(&b, 0); err != nil {
|
|
t.Fatalf("unable to encode UpdateFufillHTLC: %v", err)
|
|
}
|
|
|
|
// Deserialize the encoded SFOP message into a new empty struct.
|
|
settleReq2 := &UpdateFufillHTLC{}
|
|
if err := settleReq2.Decode(&b, 0); err != nil {
|
|
t.Fatalf("unable to decode UpdateFufillHTLC: %v", err)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|