6842c0ba8c
In this commit, we convert the delivery address in the open and accept channel methods to be a TLV type. This works as an "empty" delivery address is encoded using a two zero bytes (uint16 length zero), and a tlv type of 0 is encoded in the same manner (byte for type, byte for zero length). This change allows us to easily extend these messages in the future, in a uniform manner. When decoding the message we snip the bytes from the read TLV data. Similarly, when encoding we concatenate the TLV record for the shutdown script with the rest of the TLV data.
38 lines
771 B
Go
38 lines
771 B
Go
package lnwire
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
// TestDeliveryAddressEncodeDecode tests that we're able to properly
|
|
// encode and decode delivery addresses within TLV streams.
|
|
func TestDeliveryAddressEncodeDecode(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
addr := DeliveryAddress(
|
|
bytes.Repeat([]byte("a"), deliveryAddressMaxSize),
|
|
)
|
|
|
|
var extraData ExtraOpaqueData
|
|
err := extraData.PackRecords(addr.NewRecord())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var addr2 DeliveryAddress
|
|
tlvs, err := extraData.ExtractRecords(addr2.NewRecord())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, ok := tlvs[DeliveryAddrType]; !ok {
|
|
t.Fatalf("DeliveryAddrType not found in records")
|
|
}
|
|
|
|
if !bytes.Equal(addr, addr2) {
|
|
t.Fatalf("addr mismatch: expected %x, got %x", addr[:],
|
|
addr2[:])
|
|
}
|
|
}
|