2023-05-21 14:24:31 +00:00
|
|
|
package multicast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ed25519"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMulticastAdvertisementRoundTrip(t *testing.T) {
|
|
|
|
pk, sk, err := ed25519.GenerateKey(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
orig := multicastAdvertisement{
|
2023-10-11 18:28:28 +00:00
|
|
|
MajorVersion: 1,
|
|
|
|
MinorVersion: 2,
|
|
|
|
PublicKey: pk,
|
|
|
|
Port: 3,
|
|
|
|
Hash: sk, // any bytes will do
|
2023-05-21 14:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ob, err := orig.MarshalBinary()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var new multicastAdvertisement
|
|
|
|
if err := new.UnmarshalBinary(ob); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(orig, new) {
|
|
|
|
t.Logf("original: %+v", orig)
|
|
|
|
t.Logf("new: %+v", new)
|
|
|
|
t.Fatalf("differences found after round-trip")
|
|
|
|
}
|
|
|
|
}
|