lnd.xprv/lnwire/channel_update_announcement_test.go
Olaoluwa Osuntokun 743de45c92
lnwire: rename Expiry to TimeLockDelta within ChannelUpdateAnnouncement
This commit modifies the ChannelUpdateAnnouncement to rename the Expiry
variable instead of TimeLockDelta as that is more descriptive of the
purpose of the attribute itself.
2017-03-05 22:43:57 -06:00

46 lines
1.3 KiB
Go

package lnwire
import (
"bytes"
"reflect"
"testing"
)
func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) {
cua := &ChannelUpdateAnnouncement{
Signature: someSig,
ChannelID: someChannelID,
Timestamp: maxUint32,
Flags: maxUint16,
TimeLockDelta: maxUint16,
HtlcMinimumMstat: maxUint32,
FeeBaseMstat: maxUint32,
FeeProportionalMillionths: maxUint32,
}
// Next encode the CUA message into an empty bytes buffer.
var b bytes.Buffer
if err := cua.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode ChannelUpdateAnnouncement: %v", err)
}
// Ensure the max payload estimate is correct.
serializedLength := uint32(b.Len())
if serializedLength != cua.MaxPayloadLength(0) {
t.Fatalf("payload length estimate is incorrect: expected %v "+
"got %v", serializedLength, cua.MaxPayloadLength(0))
}
// Deserialize the encoded CUA message into a new empty struct.
cua2 := &ChannelUpdateAnnouncement{}
if err := cua2.Decode(&b, 0); err != nil {
t.Fatalf("unable to decode ChannelUpdateAnnouncement: %v", err)
}
// Assert equality of the two instances.
if !reflect.DeepEqual(cua, cua2) {
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
cua, cua2)
}
}