2016-12-07 18:46:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) {
|
|
|
|
cua := &ChannelUpdateAnnouncement{
|
|
|
|
Signature: someSig,
|
2017-04-17 01:22:20 +03:00
|
|
|
ShortChannelID: someShortChannelID,
|
2016-12-07 18:46:22 +03:00
|
|
|
Timestamp: maxUint32,
|
|
|
|
Flags: maxUint16,
|
2017-03-06 07:43:34 +03:00
|
|
|
TimeLockDelta: maxUint16,
|
2017-03-09 01:20:00 +03:00
|
|
|
HtlcMinimumMsat: maxUint32,
|
|
|
|
FeeBaseMsat: maxUint32,
|
2016-12-07 18:46:22 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:49:52 +03:00
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
|
2016-12-07 18:46:22 +03:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|