Files
lnd.xprv/lnwire/funding_request_test.go
T

48 lines
1.3 KiB
Go
Raw Normal View History

2015-12-28 03:24:16 -08:00
package lnwire
import (
"bytes"
"reflect"
2015-12-28 03:24:16 -08:00
"testing"
"github.com/roasbeef/btcutil"
2015-12-28 03:24:16 -08:00
)
func TestFundingRequestEncodeDecode(t *testing.T) {
2016-01-16 17:14:35 -08:00
// funding request
fr := &FundingRequest{
2015-12-31 01:19:54 -08:00
ReservationID: uint64(12345678),
2015-12-30 22:28:14 -08:00
ChannelType: uint8(0),
RequesterFundingAmount: btcutil.Amount(100000000),
RequesterReserveAmount: btcutil.Amount(131072),
MinFeePerKb: btcutil.Amount(20000),
MinTotalFundingAmount: btcutil.Amount(150000000),
2016-01-16 17:14:35 -08:00
LockTime: uint32(4320), // 30 block-days
2015-12-30 22:28:14 -08:00
FeePayer: uint8(0),
PaymentAmount: btcutil.Amount(1234567),
MinDepth: uint32(6),
RevocationHash: revHash,
2015-12-30 22:28:14 -08:00
Pubkey: pubKey,
DeliveryPkScript: deliveryPkScript,
ChangePkScript: changePkScript,
Inputs: inputs,
2015-12-28 03:24:16 -08: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 FundingRequest: %v", err)
}
2015-12-28 03:24:16 -08:00
// Deserialize the encoded FR message into a new empty struct.
fr2 := &FundingRequest{}
if err := fr2.Decode(&b, 0); err != nil {
t.Fatalf("unable to decode FundingRequest: %v", err)
}
2015-12-28 03:24:16 -08: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-28 03:24:16 -08:00
}