2016-11-11 04:09:14 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
func TestPongEncodeDecode(t *testing.T) {
|
|
|
|
pong := &Pong{
|
|
|
|
PongBytes: bytes.Repeat([]byte("A"), 100),
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
// Next encode the pong 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 := pong.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode pong: %v", err)
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
// Deserialize the encoded pong message into a new empty struct.
|
|
|
|
pong2 := &Pong{}
|
|
|
|
if err := pong2.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(pong, pong2) {
|
|
|
|
t.Fatalf("encode/decode pong messages don't match %#v vs %#v",
|
|
|
|
pong, pong2)
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
}
|