2015-12-28 03:24:16 -08:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-05-15 07:17:44 -07:00
|
|
|
"github.com/roasbeef/btcutil"
|
2015-12-28 03:24:16 -08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-01-16 17:14:35 -08:00
|
|
|
// Need to do this here
|
2015-12-30 22:28:14 -08:00
|
|
|
_ = copy(revocationHash[:], revocationHashBytes)
|
2015-12-28 03:24:16 -08:00
|
|
|
|
2016-01-16 17:14:35 -08:00
|
|
|
// funding request
|
2015-12-28 03:24:16 -08:00
|
|
|
fundingRequest = &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: revocationHash,
|
|
|
|
Pubkey: pubKey,
|
|
|
|
DeliveryPkScript: deliveryPkScript,
|
|
|
|
ChangePkScript: changePkScript,
|
|
|
|
Inputs: inputs,
|
2015-12-28 03:24:16 -08:00
|
|
|
}
|
2015-12-31 01:19:54 -08:00
|
|
|
fundingRequestSerializedString = "0000000000bc614e000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
|
|
|
|
fundingRequestSerializedMessage = "0709110b000000c8000000ec0000000000bc614e000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
|
2015-12-28 03:24:16 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFundingRequestEncodeDecode(t *testing.T) {
|
2016-01-16 17:14:35 -08:00
|
|
|
// All of these types being passed are of the message interface type
|
|
|
|
// Test serialization, runs: message.Encode(b, 0)
|
|
|
|
// Returns bytes
|
|
|
|
// Compares the expected serialized string from the original
|
2015-12-30 22:28:14 -08:00
|
|
|
s := SerializeTest(t, fundingRequest, fundingRequestSerializedString, filename)
|
2015-12-28 03:24:16 -08:00
|
|
|
|
2016-01-16 17:14:35 -08:00
|
|
|
// Test deserialization, runs: message.Decode(s, 0)
|
|
|
|
// Makes sure the deserialized struct is the same as the original
|
2015-12-30 22:28:14 -08:00
|
|
|
newMessage := NewFundingRequest()
|
|
|
|
DeserializeTest(t, s, newMessage, fundingRequest)
|
2015-12-28 03:24:16 -08:00
|
|
|
|
2016-01-16 17:14:35 -08:00
|
|
|
// Test message using Message interface
|
|
|
|
// Serializes into buf: WriteMessage(buf, message, uint32(1), wire.TestNet3)
|
|
|
|
// Deserializes into msg: _, msg, _ , err := ReadMessage(buf, uint32(1), wire.TestNet3)
|
2015-12-30 22:28:14 -08:00
|
|
|
MessageSerializeDeserializeTest(t, fundingRequest, fundingRequestSerializedMessage)
|
2015-12-28 03:24:16 -08:00
|
|
|
}
|