2015-12-30 16:38:57 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/btcsuite/btcutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-12-31 09:28:14 +03:00
|
|
|
var (
|
2016-01-17 04:14:35 +03:00
|
|
|
// Need to do this here
|
2015-12-31 09:28:14 +03:00
|
|
|
_ = copy(revocationHash[:], revocationHashBytes)
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// funding response
|
2015-12-31 09:28:14 +03:00
|
|
|
fundingResponse = &FundingResponse{
|
|
|
|
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),
|
|
|
|
RevocationHash: revocationHash,
|
|
|
|
Pubkey: pubKey,
|
|
|
|
CommitSig: commitSig,
|
|
|
|
DeliveryPkScript: deliveryPkScript,
|
|
|
|
ChangePkScript: changePkScript,
|
|
|
|
Inputs: inputs,
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|
2015-12-31 09:28:14 +03:00
|
|
|
fundingResponseSerializedString = "0000000000bc614e010000000005f5e1004132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e2000000006000010e0011976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
|
|
|
|
fundingResponseSerializedMessage = "0709110b000000d2000001230000000000bc614e010000000005f5e1004132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e2000000006000010e0011976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
|
|
|
|
)
|
2015-12-30 16:38:57 +03:00
|
|
|
|
2015-12-31 09:28:14 +03:00
|
|
|
func TestFundingResponseEncodeDecode(t *testing.T) {
|
2016-01-17 04:14:35 +03: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-31 09:28:14 +03:00
|
|
|
s := SerializeTest(t, fundingResponse, fundingResponseSerializedString, filename)
|
2015-12-30 16:38:57 +03:00
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Test deserialization, runs: message.Decode(s, 0)
|
|
|
|
// Makes sure the deserialized struct is the same as the original
|
2015-12-31 09:28:14 +03:00
|
|
|
newMessage := NewFundingResponse()
|
|
|
|
DeserializeTest(t, s, newMessage, fundingResponse)
|
2015-12-30 16:38:57 +03:00
|
|
|
|
2016-01-17 04:14:35 +03: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-31 09:28:14 +03:00
|
|
|
MessageSerializeDeserializeTest(t, fundingResponse, fundingResponseSerializedMessage)
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|