2015-12-30 16:38:57 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-31 02:49:48 +03:00
|
|
|
"bytes"
|
|
|
|
"reflect"
|
2015-12-30 16:38:57 +03:00
|
|
|
"testing"
|
2016-05-23 23:54:34 +03:00
|
|
|
|
|
|
|
"github.com/roasbeef/btcutil"
|
2015-12-30 16:38:57 +03:00
|
|
|
)
|
|
|
|
|
2016-05-31 02:49:48 +03:00
|
|
|
func TestFundingResponseEncodeDecode(t *testing.T) {
|
|
|
|
copy(revocationHash[:], revocationHashBytes)
|
2015-12-31 09:28:14 +03:00
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// funding response
|
2016-05-31 02:49:48 +03:00
|
|
|
fr := &FundingResponse{
|
2015-12-31 09:28:14 +03: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 04:14:35 +03:00
|
|
|
LockTime: uint32(4320), // 30 block-days
|
2015-12-31 09:28:14 +03:00
|
|
|
FeePayer: uint8(1),
|
2016-06-30 21:53:11 +03:00
|
|
|
RevocationHash: revHash,
|
2015-12-31 09:28:14 +03:00
|
|
|
Pubkey: pubKey,
|
|
|
|
CommitSig: commitSig,
|
|
|
|
DeliveryPkScript: deliveryPkScript,
|
|
|
|
ChangePkScript: changePkScript,
|
|
|
|
Inputs: inputs,
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 02:49:48 +03: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 16:38:57 +03:00
|
|
|
|
2016-05-31 02:49:48 +03: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 16:38:57 +03:00
|
|
|
|
2016-05-31 02:49:48 +03: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 16:38:57 +03:00
|
|
|
}
|