2016-11-11 04:09:14 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
func TestPingEncodeDecode(t *testing.T) {
|
|
|
|
ping := &Ping{
|
|
|
|
NumPongBytes: 10,
|
|
|
|
PaddingBytes: bytes.Repeat([]byte("A"), 100),
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
// Next encode the ping message into an empty bytes buffer.
|
2016-11-11 04:09:14 +03:00
|
|
|
var b bytes.Buffer
|
2017-04-17 04:11:39 +03:00
|
|
|
if err := ping.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode ping: %v", err)
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
// Deserialize the encoded ping message into a new empty struct.
|
|
|
|
ping2 := &Ping{}
|
|
|
|
if err := ping2.Decode(&b, 0); err != nil {
|
2016-11-11 04:09:14 +03:00
|
|
|
t.Fatalf("unable to decode ping: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert equality of the two instances.
|
2017-04-17 04:11:39 +03:00
|
|
|
if !reflect.DeepEqual(ping, ping2) {
|
|
|
|
t.Fatalf("encode/decode ping messages don't match %#v vs %#v",
|
|
|
|
ping, ping2)
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
}
|