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"
|
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
func TestHTLCSettleRequestEncodeDecode(t *testing.T) {
|
2016-06-30 21:53:11 +03:00
|
|
|
redemptionProofs := make([][32]byte, 1)
|
|
|
|
redemptionProofs[0] = revHash
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
// First create a new HTLCSR message.
|
2016-06-21 07:55:07 +03:00
|
|
|
settleReq := NewHTLCSettleRequest(outpoint1, HTLCKey(23), redemptionProofs)
|
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 {
|
|
|
|
t.Fatalf("unable to encode HTLCSettleRequest: %v", err)
|
|
|
|
}
|
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.
|
|
|
|
settleReq2 := &HTLCSettleRequest{}
|
|
|
|
if err := settleReq2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode HTLCSettleRequest: %v", err)
|
|
|
|
}
|
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
|
|
|
}
|