2015-12-30 14:38:57 +01:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 01:49:48 +02:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2015-12-30 14:38:57 +01:00
|
|
|
"testing"
|
2016-05-23 22:54:34 +02:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcutil"
|
2015-12-30 14:38:57 +01:00
|
|
|
)
|
|
|
|
|
2016-05-31 01:49:48 +02:00
|
|
|
func TestFundingResponseEncodeDecode(t *testing.T) {
|
|
|
|
copy(revocationHash[:], revocationHashBytes)
|
2015-12-31 07:28:14 +01:00
|
|
|
|
2016-01-17 02:14:35 +01:00
|
|
|
// funding response
|
2016-05-31 01:49:48 +02:00
|
|
|
fr := &FundingResponse{
|
2015-12-31 07:28:14 +01:00
|
|
|
ChannelType: uint8(1),
|
|
|
|
ReservationID: uint64(12345678),
|
|
|
|
ResponderFundingAmount: btcutil.Amount(100000000),
|
|
|
|
ResponderReserveAmount: btcutil.Amount(131072),
|
|
|
|
MinFeePerKb: btcutil.Amount(20000),
|
|
|
|
MinDepth: uint32(6),
|
2016-01-17 02:14:35 +01:00
|
|
|
LockTime: uint32(4320), // 30 block-days
|
2015-12-31 07:28:14 +01:00
|
|
|
FeePayer: uint8(1),
|
2016-06-30 20:53:11 +02:00
|
|
|
RevocationHash: revHash,
|
2015-12-31 07:28:14 +01:00
|
|
|
Pubkey: pubKey,
|
|
|
|
CommitSig: commitSig,
|
|
|
|
DeliveryPkScript: deliveryPkScript,
|
|
|
|
ChangePkScript: changePkScript,
|
|
|
|
Inputs: inputs,
|
2015-12-30 14:38:57 +01:00
|
|
|
}
|
|
|
|
|
2016-05-31 01:49:48 +02:00
|
|
|
// Next encode the FR message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := fr.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode HTLCAddRequest: %v", err)
|
|
|
|
}
|
2015-12-30 14:38:57 +01:00
|
|
|
|
2016-05-31 01:49:48 +02:00
|
|
|
// Deserialize the encoded FR message into a new empty struct.
|
|
|
|
fr2 := &FundingResponse{}
|
|
|
|
if err := fr2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode FundingResponse: %v", err)
|
|
|
|
}
|
2015-12-30 14:38:57 +01:00
|
|
|
|
2016-05-31 01:49:48 +02:00
|
|
|
// Assert equality of the two instances.
|
|
|
|
if !reflect.DeepEqual(fr, fr2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
|
|
fr, fr2)
|
|
|
|
}
|
2015-12-30 14:38:57 +01:00
|
|
|
}
|